-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: proactive connect - lists (#395)
* Creating file structure * Implement GetLists * Add missing response * Implement CreateListRequestBuilder * Implement CreateList * Implement serialization test for CreateList * Reuse same struct for a list response * Implement GetList * Implement DeleteList * Implement ClearListRequest * Implement ReplaceItemsRequest * Implement UpdateListRequest * Remove wrong property * Exposes ProactiveConnectClient
- Loading branch information
Showing
67 changed files
with
3,206 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Vonage.Common; | ||
|
||
/// <summary> | ||
/// Represents a set of HAL Links. | ||
/// </summary> | ||
public struct HalLinks | ||
{ | ||
/// <summary> | ||
/// Represents the navigation link to the first element. | ||
/// </summary> | ||
public HalLink First { get; set; } | ||
|
||
/// <summary> | ||
/// Represents the navigation link to the last element. | ||
/// </summary> | ||
public HalLink Last { get; set; } | ||
|
||
/// <summary> | ||
/// Represents the navigation link to the next element. | ||
/// </summary> | ||
public HalLink Next { get; set; } | ||
|
||
/// <summary> | ||
/// Represents the navigation link to the previous element. | ||
/// </summary> | ||
[JsonPropertyName("prev")] | ||
public HalLink Previous { get; set; } | ||
|
||
/// <summary> | ||
/// Represents the navigation link to the current element. | ||
/// </summary> | ||
public HalLink Self { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// Represents a link to another page. | ||
/// </summary> | ||
/// <param name="Href">Hyperlink reference.</param> | ||
public record HalLink(Uri Href); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,8 +129,4 @@ | |
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Video\Sessions\Common\"/> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Vonage.Test.Unit/ProactiveConnect/Lists/ClearList/RequestTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using Vonage.Common.Failures; | ||
using Vonage.Common.Test.Extensions; | ||
using Vonage.ProactiveConnect.Lists.ClearList; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Unit.ProactiveConnect.Lists.ClearList | ||
{ | ||
public class RequestTest | ||
{ | ||
[Fact] | ||
public void GetEndpointPath_ShouldReturnApiEndpoint() => | ||
ClearListRequest.Parse(new Guid("de51fd37-551c-45f1-8eaf-0fcd75c0bbc8")) | ||
.Map(request => request.GetEndpointPath()) | ||
.Should() | ||
.BeSuccess("/v.01/bulk/lists/de51fd37-551c-45f1-8eaf-0fcd75c0bbc8/clear"); | ||
|
||
[Fact] | ||
public void Parse_ShouldReturnFailure_GivenIdIsEmpty() => | ||
ClearListRequest.Parse(Guid.Empty) | ||
.Should() | ||
.BeFailure(ResultFailure.FromErrorMessage("Id cannot be empty.")); | ||
|
||
[Fact] | ||
public void Parse_ShouldReturnSuccess() => | ||
ClearListRequest.Parse(new Guid("de51fd37-551c-45f1-8eaf-0fcd75c0bbc8")) | ||
.Map(request => request.Id) | ||
.Should() | ||
.BeSuccess(new Guid("de51fd37-551c-45f1-8eaf-0fcd75c0bbc8")); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
Vonage.Test.Unit/ProactiveConnect/Lists/ClearList/UseCaseTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using AutoFixture; | ||
using AutoFixture.Kernel; | ||
using FsCheck; | ||
using FsCheck.Xunit; | ||
using Vonage.Common.Client; | ||
using Vonage.Common.Monads; | ||
using Vonage.Common.Test; | ||
using Vonage.ProactiveConnect; | ||
using Vonage.ProactiveConnect.Lists.ClearList; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Unit.ProactiveConnect.Lists.ClearList | ||
{ | ||
public class UseCaseTest : BaseUseCase | ||
{ | ||
private Func<VonageHttpClientConfiguration, Task<Result<Common.Monads.Unit>>> Operation => | ||
configuration => new ProactiveConnectClient(configuration).ClearListAsync(this.request); | ||
|
||
private readonly Result<ClearListRequest> request; | ||
|
||
public UseCaseTest() => this.request = BuildRequest(this.helper.Fixture); | ||
|
||
[Property] | ||
public Property ShouldReturnFailure_GivenApiErrorCannotBeParsed() => | ||
this.helper.VerifyReturnsFailureGivenErrorCannotBeParsed(this.BuildExpectedRequest(), this.Operation); | ||
|
||
[Property] | ||
public Property ShouldReturnFailure_GivenApiResponseIsError() => | ||
this.helper.VerifyReturnsFailureGivenApiResponseIsError(this.BuildExpectedRequest(), this.Operation); | ||
|
||
[Fact] | ||
public async Task ShouldReturnFailure_GivenRequestIsFailure() => | ||
await this.helper | ||
.VerifyReturnsFailureGivenRequestIsFailure<ClearListRequest, Common.Monads.Unit>( | ||
(configuration, failureRequest) => | ||
new ProactiveConnectClient(configuration).ClearListAsync(failureRequest)); | ||
|
||
[Fact] | ||
public async Task ShouldReturnFailure_GivenTokenGenerationFailed() => | ||
await this.helper.VerifyReturnsFailureGivenTokenGenerationFails(this.Operation); | ||
|
||
[Fact] | ||
public async Task ShouldReturnSuccess_GivenApiResponseIsSuccess() => | ||
await this.helper.VerifyReturnsExpectedValueGivenApiResponseIsSuccess(this.BuildExpectedRequest(), | ||
this.Operation); | ||
|
||
private ExpectedRequest BuildExpectedRequest() => | ||
new ExpectedRequest | ||
{ | ||
Method = HttpMethod.Post, | ||
RequestUri = new Uri(UseCaseHelper.GetPathFromRequest(this.request), UriKind.Relative), | ||
}; | ||
|
||
private static Result<ClearListRequest> BuildRequest(ISpecimenBuilder fixture) => | ||
ClearListRequest.Parse(fixture.Create<Guid>()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
Vonage.Test.Unit/ProactiveConnect/Lists/CreateList/Data/ShouldDeserialize200-response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "my name", | ||
"description": "my description", | ||
"tags": [ | ||
"vip", | ||
"sport" | ||
], | ||
"attributes": [ | ||
{ | ||
"name": "phone_number", | ||
"alias": "phone", | ||
"key": false | ||
} | ||
], | ||
"datasource": { | ||
"type": "salesforce", | ||
"integration_id": "salesforce_credentials", | ||
"soql": "some sql" | ||
}, | ||
"id": "29192c4a-4058-49da-86c2-3e349d1065b7", | ||
"created_at": "2022-06-19T17:59:28.085Z", | ||
"updated_at": "2022-06-19T17:59:28.085Z", | ||
"sync_status": { | ||
"value": "configured", | ||
"details": "Not found", | ||
"metadata_modified": false, | ||
"data_modified": true, | ||
"dirty": true | ||
}, | ||
"items_count": 500 | ||
} |
5 changes: 5 additions & 0 deletions
5
...it/ProactiveConnect/Lists/CreateList/Data/ShouldSerializeWithMandatoryValues-request.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "my name", | ||
"tags": [], | ||
"attributes": [] | ||
} |
18 changes: 18 additions & 0 deletions
18
...t/ProactiveConnect/Lists/CreateList/Data/ShouldSerializeWithManualDataSource-request.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "my name", | ||
"description": "my description", | ||
"tags": [ | ||
"vip", | ||
"sport" | ||
], | ||
"attributes": [ | ||
{ | ||
"name": "phone_number", | ||
"alias": "phone", | ||
"key": false | ||
} | ||
], | ||
"datasource": { | ||
"type": "manual" | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...oactiveConnect/Lists/CreateList/Data/ShouldSerializeWithSalesforceDataSource-request.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "my name", | ||
"description": "my description", | ||
"tags": [ | ||
"vip", | ||
"sport" | ||
], | ||
"attributes": [ | ||
{ | ||
"name": "phone_number", | ||
"alias": "phone", | ||
"key": false | ||
} | ||
], | ||
"datasource": { | ||
"type": "salesforce", | ||
"integration_id": "123456789", | ||
"soql": "some sql" | ||
} | ||
} |
Oops, something went wrong.