-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement GetTemplateFragments for VerifyV2
- Loading branch information
Showing
12 changed files
with
524 additions
and
6 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
Vonage.Test/VerifyV2/GetTemplateFragments/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,40 @@ | ||
{ | ||
"page_size": 1, | ||
"page": 2, | ||
"total_pages": 10, | ||
"total_items": 25, | ||
"_embedded": { | ||
"template_fragments": [ | ||
{ | ||
"template_fragment_id": "c70f446e-997a-4313-a081-60a02a31dc19", | ||
"channel": "sms", | ||
"locale": "en-us", | ||
"text": "Text content of the template. May contain 4 reserved variables: `${code}`, `${brand}`, `${time-limit}` and `${time-limit-unit}`", | ||
"date_updated": "2023-08-30T15:20:15.178Z", | ||
"date_created": "2021-08-30T20:12:15.178Z", | ||
"_links": { | ||
"self": { | ||
"href": "https://api.nexmo.com/v2/verify/templates/8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9/template_fragments/c70f446e-997a-4313-a081-60a02a31dc19" | ||
}, | ||
"template": { | ||
"href": "https://api.nexmo.com/v2/verify/templates/8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"_links": { | ||
"self": { | ||
"href": "https://api.nexmo.com/v2/verify/templates/c70f446e-997a-4313-a081-60a02a31dc19/template_fragments?page=2" | ||
}, | ||
"next": { | ||
"href": "https://api.nexmo.com/v2/verify/templates/c70f446e-997a-4313-a081-60a02a31dc19/template_fragments?page=3" | ||
}, | ||
"prev": { | ||
"href": "https://api.nexmo.com/v2/verify/templates/c70f446e-997a-4313-a081-60a02a31dc19/template_fragments?page=1" | ||
}, | ||
"last": { | ||
"href": "https://api.nexmo.com/v2/verify/templates/c70f446e-997a-4313-a081-60a02a31dc19/template_fragments?page=5" | ||
} | ||
} | ||
} |
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,99 @@ | ||
#region | ||
using System; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Vonage.Test.Common.Extensions; | ||
using Vonage.VerifyV2.GetTemplateFragments; | ||
using WireMock.ResponseBuilders; | ||
using Xunit; | ||
#endregion | ||
|
||
namespace Vonage.Test.VerifyV2.GetTemplateFragments; | ||
|
||
[Trait("Category", "E2E")] | ||
public class E2ETest : E2EBase | ||
{ | ||
public E2ETest() : base(typeof(E2ETest).Namespace) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task GetTemplateFragmentsEmpty() | ||
{ | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/v2/verify/templates/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb/template_fragments") | ||
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) | ||
.UsingGet()) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(HttpStatusCode.OK) | ||
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); | ||
await this.Helper.VonageClient.VerifyV2Client | ||
.GetTemplateFragmentsAsync(GetTemplateFragmentsRequest | ||
.Build() | ||
.WithTemplateId(RequestBuilderTest.ValidTemplateId) | ||
.Create()) | ||
.Should() | ||
.BeSuccessAsync(SerializationTest.VerifyExpectedResponse); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTemplatesEmptyFromResponse() | ||
{ | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/v2/verify/templates/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb/template_fragments") | ||
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) | ||
.UsingGet()) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(HttpStatusCode.OK) | ||
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); | ||
await this.Helper.VonageClient.VerifyV2Client | ||
.GetTemplateFragmentsAsync( | ||
new GetTemplateFragmentsHalLink(new Uri( | ||
"https://api.nexmo.com/v2/verify/templates/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb/template_fragments")) | ||
.BuildRequest()) | ||
.Should() | ||
.BeSuccessAsync(SerializationTest.VerifyExpectedResponse); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTemplatesFromResponse() | ||
{ | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/v2/verify/templates/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb/template_fragments") | ||
.WithParam("page_size", "15") | ||
.WithParam("page", "50") | ||
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) | ||
.UsingGet()) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(HttpStatusCode.OK) | ||
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); | ||
await this.Helper.VonageClient.VerifyV2Client | ||
.GetTemplateFragmentsAsync( | ||
new GetTemplateFragmentsHalLink(new Uri( | ||
"https://api.nexmo.com/v2/verify/templates/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb/template_fragments?page_size=15&page=50")) | ||
.BuildRequest()) | ||
.Should() | ||
.BeSuccessAsync(SerializationTest.VerifyExpectedResponse); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTemplates() | ||
{ | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/v2/verify/templates/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb/template_fragments") | ||
.WithParam("page_size", "15") | ||
.WithParam("page", "50") | ||
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) | ||
.UsingGet()) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(HttpStatusCode.OK) | ||
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); | ||
await this.Helper.VonageClient.VerifyV2Client | ||
.GetTemplateFragmentsAsync(GetTemplateFragmentsRequest | ||
.Build() | ||
.WithTemplateId(RequestBuilderTest.ValidTemplateId) | ||
.WithPageSize(15).WithPage(50).Create()) | ||
.Should() | ||
.BeSuccessAsync(SerializationTest.VerifyExpectedResponse); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
Vonage.Test/VerifyV2/GetTemplateFragments/RequestBuilderTest.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,76 @@ | ||
#region | ||
using System; | ||
using Vonage.Common.Monads; | ||
using Vonage.Test.Common.Extensions; | ||
using Vonage.VerifyV2.GetTemplateFragments; | ||
using Xunit; | ||
#endregion | ||
|
||
namespace Vonage.Test.VerifyV2.GetTemplateFragments; | ||
|
||
[Trait("Category", "Request")] | ||
public class RequestBuilderTest | ||
{ | ||
internal static readonly Guid ValidTemplateId = new Guid("68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb"); | ||
|
||
[Fact] | ||
public void Parse_ShouldReturnFailure_GivenRequestIsEmpty() => | ||
GetTemplateFragmentsRequest | ||
.Build() | ||
.WithTemplateId(Guid.Empty) | ||
.Create() | ||
.Should() | ||
.BeParsingFailure("TemplateId cannot be empty."); | ||
|
||
[Fact] | ||
public void Build_ShouldHaveNoDefaultPageSize() => | ||
GetTemplateFragmentsRequest | ||
.Build() | ||
.WithTemplateId(ValidTemplateId) | ||
.Create() | ||
.Map(request => request.PageSize) | ||
.Should() | ||
.BeSuccess(Maybe<int>.None); | ||
|
||
[Fact] | ||
public void Build_ShouldHaveNoDefaultPage() => | ||
GetTemplateFragmentsRequest | ||
.Build() | ||
.WithTemplateId(ValidTemplateId) | ||
.Create() | ||
.Map(request => request.Page) | ||
.Should() | ||
.BeSuccess(Maybe<int>.None); | ||
|
||
[Fact] | ||
public void Build_ShouldSetTemplateId() => | ||
GetTemplateFragmentsRequest | ||
.Build() | ||
.WithTemplateId(ValidTemplateId) | ||
.Create() | ||
.Map(request => request.TemplateId) | ||
.Should() | ||
.BeSuccess(ValidTemplateId); | ||
|
||
[Fact] | ||
public void Build_ShouldSetPageSize() => | ||
GetTemplateFragmentsRequest | ||
.Build() | ||
.WithTemplateId(ValidTemplateId) | ||
.WithPageSize(50) | ||
.Create() | ||
.Map(request => request.PageSize) | ||
.Should() | ||
.BeSuccess(50); | ||
|
||
[Fact] | ||
public void Build_ShouldSetPage() => | ||
GetTemplateFragmentsRequest | ||
.Build() | ||
.WithTemplateId(ValidTemplateId) | ||
.WithPage(50) | ||
.Create() | ||
.Map(request => request.Page) | ||
.Should() | ||
.BeSuccess(50); | ||
} |
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,33 @@ | ||
#region | ||
using Vonage.Test.Common.Extensions; | ||
using Vonage.VerifyV2.GetTemplateFragments; | ||
using Xunit; | ||
#endregion | ||
|
||
namespace Vonage.Test.VerifyV2.GetTemplateFragments; | ||
|
||
[Trait("Category", "Request")] | ||
public class RequestTest | ||
{ | ||
[Theory] | ||
[InlineData(null, null, "/v2/verify/templates/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb/template_fragments")] | ||
[InlineData(30, null, "/v2/verify/templates/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb/template_fragments?page_size=30")] | ||
[InlineData(null, 50, "/v2/verify/templates/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb/template_fragments?page=50")] | ||
[InlineData(30, 50, | ||
"/v2/verify/templates/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb/template_fragments?page_size=30&page=50")] | ||
public void GetEndpointPath_ShouldReturnApiEndpoint(int? pageSize, int? page, string expectedEndpoint) | ||
{ | ||
var builder = GetTemplateFragmentsRequest.Build().WithTemplateId(RequestBuilderTest.ValidTemplateId); | ||
if (pageSize.HasValue) | ||
{ | ||
builder = builder.WithPageSize(pageSize.Value); | ||
} | ||
|
||
if (page.HasValue) | ||
{ | ||
builder = builder.WithPage(page.Value); | ||
} | ||
|
||
builder.Create().Map(request => request.GetEndpointPath()).Should().BeSuccess(expectedEndpoint); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
Vonage.Test/VerifyV2/GetTemplateFragments/SerializationTest.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,59 @@ | ||
#region | ||
using System; | ||
using FluentAssertions; | ||
using Vonage.Serialization; | ||
using Vonage.Test.Common; | ||
using Vonage.Test.Common.Extensions; | ||
using Vonage.VerifyV2; | ||
using Vonage.VerifyV2.GetTemplateFragments; | ||
using Vonage.VerifyV2.StartVerification; | ||
using Xunit; | ||
#endregion | ||
|
||
namespace Vonage.Test.VerifyV2.GetTemplateFragments; | ||
|
||
[Trait("Category", "Serialization")] | ||
public class SerializationTest | ||
{ | ||
private readonly SerializationTestHelper helper = new SerializationTestHelper( | ||
typeof(SerializationTest).Namespace, | ||
JsonSerializerBuilder.BuildWithSnakeCase()); | ||
|
||
[Fact] | ||
public void ShouldDeserialize200() => | ||
this.helper.Serializer | ||
.DeserializeObject<GetTemplateFragmentsResponse>(this.helper.GetResponseJson()) | ||
.Should() | ||
.BeSuccess(VerifyExpectedResponse); | ||
|
||
internal static void VerifyExpectedResponse(GetTemplateFragmentsResponse response) | ||
{ | ||
response.PageSize.Should().Be(1); | ||
response.Page.Should().Be(2); | ||
response.TotalPages.Should().Be(10); | ||
response.TotalItems.Should().Be(25); | ||
response.Links.Self.Href.Should() | ||
.Be(new Uri( | ||
"https://api.nexmo.com/v2/verify/templates/c70f446e-997a-4313-a081-60a02a31dc19/template_fragments?page=2")); | ||
response.Links.Next.Href.Should() | ||
.Be(new Uri( | ||
"https://api.nexmo.com/v2/verify/templates/c70f446e-997a-4313-a081-60a02a31dc19/template_fragments?page=3")); | ||
response.Links.Previous.Href.Should() | ||
.Be(new Uri( | ||
"https://api.nexmo.com/v2/verify/templates/c70f446e-997a-4313-a081-60a02a31dc19/template_fragments?page=1")); | ||
response.Links.Last.Href.Should() | ||
.Be(new Uri( | ||
"https://api.nexmo.com/v2/verify/templates/c70f446e-997a-4313-a081-60a02a31dc19/template_fragments?page=5")); | ||
response.Embedded.Fragments.Should().HaveCount(1); | ||
response.Embedded.Fragments.Should().BeEquivalentTo(new[] | ||
{ | ||
new TemplateFragment( | ||
new Guid("c70f446e-997a-4313-a081-60a02a31dc19"), | ||
VerificationChannel.Sms, | ||
Locale.EnUs, | ||
"Text content of the template. May contain 4 reserved variables: `${code}`, `${brand}`, `${time-limit}` and `${time-limit-unit}`", | ||
DateTimeOffset.Parse("2021-08-30T20:12:15.178Z"), | ||
DateTimeOffset.Parse("2023-08-30T15:20:15.178Z")), | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.