-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
472 additions
and
24 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
17 changes: 17 additions & 0 deletions
17
Vonage.Test/SimSwap/Authenticate/AuthenticateResponseTest.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,17 @@ | ||
using System.Net.Http.Headers; | ||
using FluentAssertions; | ||
using Vonage.SimSwap.Authenticate; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.SimSwap.Authenticate; | ||
|
||
[Trait("Category", "Request")] | ||
public class AuthenticateResponseTest | ||
{ | ||
[Fact] | ||
public void BuildAuthenticationHeader_ShouldReturnBearerAuth() => | ||
new AuthenticateResponse("123456789") | ||
.BuildAuthenticationHeader() | ||
.Should() | ||
.Be(new AuthenticationHeaderValue("Bearer", "123456789")); | ||
} |
5 changes: 5 additions & 0 deletions
5
Vonage.Test/SimSwap/Check/Data/ShouldDeserializeAccessToken-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,5 @@ | ||
{ | ||
"access_token": "ABCDEFG", | ||
"token_type": "Bearer", | ||
"expires_in": 3600 | ||
} |
5 changes: 5 additions & 0 deletions
5
Vonage.Test/SimSwap/Check/Data/ShouldDeserializeAuthorize-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,5 @@ | ||
{ | ||
"auth_req_id": "123456789", | ||
"expires_in": "120", | ||
"interval": "2" | ||
} |
3 changes: 3 additions & 0 deletions
3
Vonage.Test/SimSwap/Check/Data/ShouldDeserializeCheck-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,3 @@ | ||
{ | ||
"swapped": true | ||
} |
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,4 @@ | ||
{ | ||
"phoneNumber": "346661113334", | ||
"maxAge": 240 | ||
} |
4 changes: 4 additions & 0 deletions
4
Vonage.Test/SimSwap/Check/Data/ShouldSerializeWithPeriod-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,4 @@ | ||
{ | ||
"phoneNumber": "346661113334", | ||
"maxAge": 15 | ||
} |
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,68 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Vonage.SimSwap.Check; | ||
using Vonage.Test.Common.Extensions; | ||
using WireMock.ResponseBuilders; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.SimSwap.Check; | ||
|
||
[Trait("Category", "E2E")] | ||
public class E2ETest : E2EBase | ||
{ | ||
public E2ETest() : base(typeof(E2ETest).Namespace) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task CheckAsync() | ||
{ | ||
this.SetupAuthorization(); | ||
this.SetupToken(); | ||
this.SetupSimSwap(nameof(SerializationTest.ShouldSerialize)); | ||
await this.Helper.VonageClient.SimSwapClient | ||
.CheckAsync(CheckRequest.Build().WithPhoneNumber("346661113334").Create()) | ||
.Should() | ||
.BeSuccessAsync(true); | ||
} | ||
|
||
[Fact] | ||
public async Task CheckAsyncWithPeriod() | ||
{ | ||
this.SetupAuthorization(); | ||
this.SetupToken(); | ||
this.SetupSimSwap(nameof(SerializationTest.ShouldSerializeWithPeriod)); | ||
await this.Helper.VonageClient.SimSwapClient | ||
.CheckAsync(CheckRequest.Build().WithPhoneNumber("346661113334").WithPeriod(15).Create()) | ||
.Should() | ||
.BeSuccessAsync(true); | ||
} | ||
|
||
private void SetupSimSwap(string expectedOutput) => | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/camara/sim-swap/v040/check") | ||
.WithHeader("Authorization", "Bearer ABCDEFG") | ||
.WithBody(this.Serialization.GetRequestJson(expectedOutput)) | ||
.UsingPost()) | ||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) | ||
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserializeCheck)))); | ||
|
||
private void SetupToken() => | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/oauth2/token") | ||
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) | ||
.WithBody("auth_req_id=123456789&grant_type=urn:openid:params:grant-type:ciba") | ||
.UsingPost()) | ||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) | ||
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserializeAccessToken)))); | ||
|
||
private void SetupAuthorization() => | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/oauth2/bc-authorize") | ||
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) | ||
.WithBody( | ||
"login_hint=tel:%2B346661113334&scope=openid+dpv%3AFraudPreventionAndDetection%23check-sim-swap") | ||
.UsingPost()) | ||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) | ||
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserializeAuthorize)))); | ||
} |
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,102 @@ | ||
using Vonage.Common.Failures; | ||
using Vonage.SimSwap.Check; | ||
using Vonage.Test.Common.Extensions; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.SimSwap.Check; | ||
|
||
[Trait("Category", "Request")] | ||
public class RequestBuilderTest | ||
{ | ||
[Theory] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
[InlineData(null)] | ||
public void Build_ShouldReturnFailure_GivenNumberIsNullOrWhitespace(string value) => | ||
CheckRequest.Build() | ||
.WithPhoneNumber(value) | ||
.Create() | ||
.Should() | ||
.BeFailure(ResultFailure.FromErrorMessage("Number cannot be null or whitespace.")); | ||
|
||
[Fact] | ||
public void Build_ShouldReturnFailure_GivenNumberContainsNonDigits() => | ||
CheckRequest.Build() | ||
.WithPhoneNumber("1234567abc123") | ||
.Create() | ||
.Should() | ||
.BeFailure(ResultFailure.FromErrorMessage("Number can only contain digits.")); | ||
|
||
[Fact] | ||
public void Build_ShouldReturnFailure_GivenNumberLengthIsHigherThan7() => | ||
CheckRequest.Build() | ||
.WithPhoneNumber("123456") | ||
.Create() | ||
.Should() | ||
.BeFailure(ResultFailure.FromErrorMessage("Number length cannot be lower than 7.")); | ||
|
||
[Fact] | ||
public void Build_ShouldReturnFailure_GivenNumberLengthIsLowerThan15() => | ||
CheckRequest.Build() | ||
.WithPhoneNumber("1234567890123456") | ||
.Create() | ||
.Should() | ||
.BeFailure(ResultFailure.FromErrorMessage("Number length cannot be higher than 15.")); | ||
|
||
[Theory] | ||
[InlineData("1234567", "1234567")] | ||
[InlineData("123456789012345", "123456789012345")] | ||
[InlineData("+1234567890", "1234567890")] | ||
[InlineData("+123456789012345", "123456789012345")] | ||
[InlineData("+++1234567890", "1234567890")] | ||
public void Build_ShouldSetPhoneNumber_GivenNumberIsValid(string value, string expected) => | ||
CheckRequest.Build() | ||
.WithPhoneNumber(value) | ||
.Create() | ||
.Map(number => number.PhoneNumber.Number) | ||
.Should() | ||
.BeSuccess(expected); | ||
|
||
[Theory] | ||
[InlineData(1)] | ||
[InlineData(2400)] | ||
public void Build_ShouldSetPeriod(int value) => | ||
CheckRequest.Build() | ||
.WithPhoneNumber("1234567") | ||
.WithPeriod(value) | ||
.Create() | ||
.Map(number => number.Period) | ||
.Should() | ||
.BeSuccess(value); | ||
|
||
[Fact] | ||
public void Build_ShouldSetPeriodToDefault_GivenPeriodIsNotSet() => | ||
CheckRequest.Build() | ||
.WithPhoneNumber("1234567") | ||
.Create() | ||
.Map(number => number.Period) | ||
.Should() | ||
.BeSuccess(240); | ||
|
||
[Theory] | ||
[InlineData(0)] | ||
[InlineData(-1)] | ||
public void Build_ShouldReturnFailure_GivenPeriodIsLowerThan15(int incorrectValue) => | ||
CheckRequest.Build() | ||
.WithPhoneNumber("1234567") | ||
.WithPeriod(incorrectValue) | ||
.Create() | ||
.Should() | ||
.BeParsingFailure("Period cannot be lower than 1."); | ||
|
||
[Theory] | ||
[InlineData(2401)] | ||
[InlineData(2402)] | ||
public void Build_ShouldReturnFailure_GivenPeriodIsHigherThan2400(int incorrectValue) => | ||
CheckRequest.Build() | ||
.WithPhoneNumber("1234567") | ||
.WithPeriod(incorrectValue) | ||
.Create() | ||
.Should() | ||
.BeParsingFailure("Period cannot be higher than 2400."); | ||
} |
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 @@ | ||
using Vonage.SimSwap.Check; | ||
using Vonage.Test.Common.Extensions; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.SimSwap.Check; | ||
|
||
[Trait("Category", "Request")] | ||
public class RequestTest | ||
{ | ||
[Fact] | ||
public void GetEndpointPath_ShouldReturnApiEndpoint() => | ||
CheckRequest.Build() | ||
.WithPhoneNumber("123456789") | ||
.Create() | ||
.Map(request => request.GetEndpointPath()) | ||
.Should() | ||
.BeSuccess("camara/sim-swap/v040/check"); | ||
} |
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 @@ | ||
using Vonage.Serialization; | ||
using Vonage.SimSwap.Authenticate; | ||
using Vonage.SimSwap.Check; | ||
using Vonage.Test.Common; | ||
using Vonage.Test.Common.Extensions; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.SimSwap.Check; | ||
|
||
[Trait("Category", "Serialization")] | ||
public class SerializationTest | ||
{ | ||
private readonly SerializationTestHelper helper = new SerializationTestHelper( | ||
typeof(SerializationTest).Namespace, | ||
JsonSerializerBuilder.BuildWithSnakeCase()); | ||
|
||
[Fact] | ||
public void ShouldDeserializeAuthorize() => this.helper.Serializer | ||
.DeserializeObject<AuthorizeResponse>(this.helper.GetResponseJson()) | ||
.Should() | ||
.BeSuccess(GetExpectedAuthorizeResponse()); | ||
|
||
[Fact] | ||
public void ShouldDeserializeAccessToken() => this.helper.Serializer | ||
.DeserializeObject<GetTokenResponse>(this.helper.GetResponseJson()) | ||
.Should() | ||
.BeSuccess(GetExpectedTokenResponse()); | ||
|
||
[Fact] | ||
public void ShouldDeserializeCheck() => this.helper.Serializer | ||
.DeserializeObject<CheckResponse>(this.helper.GetResponseJson()) | ||
.Should() | ||
.BeSuccess(GetExpectedResponse()); | ||
|
||
[Fact] | ||
public void ShouldSerialize() => | ||
CheckRequest.Build() | ||
.WithPhoneNumber("346661113334") | ||
.Create() | ||
.GetStringContent() | ||
.Should() | ||
.BeSuccess(this.helper.GetRequestJson()); | ||
|
||
[Fact] | ||
public void ShouldSerializeWithPeriod() => | ||
CheckRequest.Build() | ||
.WithPhoneNumber("346661113334") | ||
.WithPeriod(15) | ||
.Create() | ||
.GetStringContent() | ||
.Should() | ||
.BeSuccess(this.helper.GetRequestJson()); | ||
|
||
private static AuthorizeResponse GetExpectedAuthorizeResponse() => new AuthorizeResponse("123456789", "120", "2"); | ||
|
||
private static GetTokenResponse GetExpectedTokenResponse() => new GetTokenResponse("ABCDEFG", "Bearer", 3600); | ||
|
||
private static CheckResponse GetExpectedResponse() => new CheckResponse(true); | ||
} |
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.