Skip to content

Commit

Permalink
refactor: E2E tests for FraudCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Nov 30, 2023
1 parent 56ebfb1 commit 9a27e8f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 34 deletions.
48 changes: 34 additions & 14 deletions Vonage.Test.Unit/NumberInsightsV2/FraudCheck/E2ETest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Net;
using System.Threading.Tasks;
using Vonage.Common;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.Extensions;
using Vonage.NumberInsightV2.FraudCheck;
Expand All @@ -13,41 +14,60 @@ namespace Vonage.Test.Unit.NumberInsightsV2.FraudCheck
[Trait("Category", "E2E")]
public class E2ETest
{
private const string ApiUrl = "Vonage.Url.Api";

private readonly SerializationTestHelper serialization =
new SerializationTestHelper(typeof(E2ETest).Namespace, JsonSerializer.BuildWithSnakeCase());

private readonly TestingContext helperWithBasicCredentials =
TestingContext.WithBasicCredentials("Vonage.Url.Api");
[Fact]
public async Task PerformFraudCheck_WithFraudScore_UsingBasicCredentials() =>
await this.PerformFraudCheckWithFraudScore(TestingContext.WithBasicCredentials(ApiUrl));

private readonly TestingContext helperWithBearerCredentials =
TestingContext.WithBearerCredentials("Vonage.Url.Api");
[Fact]
public async Task PerformFraudCheck_WithFraudScore_UsingBearerCredentials() =>
await this.PerformFraudCheckWithFraudScore(TestingContext.WithBearerCredentials(ApiUrl));

[Fact]
public async Task PerformFraudCheck_WithFraudScoreAndSimSwap_UsingBasicCredentials() =>
await this.PerformFraudCheckWithFraudScoreAndSimSwap(this.helperWithBasicCredentials);
await this.PerformFraudCheckWithFraudScoreAndSimSwap(TestingContext.WithBasicCredentials(ApiUrl));

[Fact]
public async Task PerformFraudCheck_WithFraudScoreAndSimSwap_UsingBearerCredentials() =>
await this.PerformFraudCheckWithFraudScoreAndSimSwap(this.helperWithBearerCredentials);
await this.PerformFraudCheckWithFraudScoreAndSimSwap(TestingContext.WithBearerCredentials(ApiUrl));

[Fact]
public async Task PerformFraudCheck_WithSimSwap_UsingBasicCredentials() =>
await this.PerformFraudCheckWithSimSwap(TestingContext.WithBasicCredentials(ApiUrl));

private async Task PerformFraudCheckWithFraudScoreAndSimSwap(TestingContext helper)
[Fact]
public async Task PerformFraudCheck_WithSimSwap_UsingBearerCredentials() =>
await this.PerformFraudCheckWithSimSwap(TestingContext.WithBearerCredentials(ApiUrl));

private async Task PerformFraudCheck(TestingContext helper, string body, Result<FraudCheckRequest> request)
{
helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath("/v2/ni")
.WithHeader("Authorization", helper.ExpectedAuthorizationHeaderValue)
.WithBody(this.serialization.GetRequestJson(nameof(SerializationTest
.ShouldSerializeWithFraudScoreAndSimSwap)))
.WithBody(body)
.UsingPost())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)
.WithBody(this.serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200))));
await helper.VonageClient.NumberInsightV2Client
.PerformFraudCheckAsync(FraudCheckRequest.Build()
.WithPhone("447009000000")
.WithFraudScore()
.WithSimSwap()
.Create())
.PerformFraudCheckAsync(request)
.Should()
.BeSuccessAsync(SerializationTest.GetExpectedFraudCheckResponse());
}

private Task PerformFraudCheckWithFraudScore(TestingContext helper) =>
this.PerformFraudCheck(helper, this.serialization.GetRequestJson(nameof(SerializationTest
.ShouldSerializeWithFraudScore)), SerializationTest.BuildRequestWithFraudScore());

private Task PerformFraudCheckWithFraudScoreAndSimSwap(TestingContext helper) =>
this.PerformFraudCheck(helper, this.serialization.GetRequestJson(nameof(SerializationTest
.ShouldSerializeWithFraudScoreAndSimSwap)), SerializationTest.BuildRequestWithFraudScoreAndSimSwap());

private Task PerformFraudCheckWithSimSwap(TestingContext helper) =>
this.PerformFraudCheck(helper, this.serialization.GetRequestJson(nameof(SerializationTest
.ShouldSerializeWithSimSwap)), SerializationTest.BuildRequestWithSimSwap());
}
}
50 changes: 30 additions & 20 deletions Vonage.Test.Unit/NumberInsightsV2/FraudCheck/SerializationTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Vonage.Common;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.Extensions;
using Vonage.NumberInsightV2.FraudCheck;
Expand All @@ -13,45 +14,54 @@ public class SerializationTest
typeof(SerializationTest).Namespace,
JsonSerializer.BuildWithSnakeCase());

public static FraudCheckResponse GetExpectedFraudCheckResponse() => new FraudCheckResponse(
new Guid("6cb4c489-0fc8-4c40-8c3d-95e7e74f9450"),
"phone",
new PhoneData("16197363066", "Orange France", "MOBILE"),
new FraudScore("54", "flag", "medium", "completed"),
new SimSwap("failed", true, "Mobile Network Operator Not Supported"));

[Fact]
public void ShouldDeserialize200() => this.helper.Serializer
.DeserializeObject<FraudCheckResponse>(this.helper.GetResponseJson())
.Should()
.BeSuccess(GetExpectedFraudCheckResponse());

[Fact]
public void ShouldSerializeWithFraudScore() => FraudCheckRequest.Build()
.WithPhone("447009000000")
.WithFraudScore()
.Create()
public void ShouldSerializeWithFraudScore() => BuildRequestWithFraudScore()
.GetStringContent()
.Should()
.BeSuccess(this.helper.GetRequestJson());

[Fact]
public void ShouldSerializeWithFraudScoreAndSimSwap() => FraudCheckRequest.Build()
.WithPhone("447009000000")
.WithFraudScore()
.WithSimSwap()
.Create()
public void ShouldSerializeWithFraudScoreAndSimSwap() => BuildRequestWithFraudScoreAndSimSwap()
.GetStringContent()
.Should()
.BeSuccess(this.helper.GetRequestJson());

[Fact]
public void ShouldSerializeWithSimSwap() => FraudCheckRequest.Build()
.WithPhone("447009000000")
.WithSimSwap()
.Create()
public void ShouldSerializeWithSimSwap() => BuildRequestWithSimSwap()
.GetStringContent()
.Should()
.BeSuccess(this.helper.GetRequestJson());

internal static Result<FraudCheckRequest> BuildRequestWithFraudScoreAndSimSwap() =>
FraudCheckRequest.Build()
.WithPhone("447009000000")
.WithFraudScore()
.WithSimSwap()
.Create();

internal static Result<FraudCheckRequest> BuildRequestWithSimSwap() =>
FraudCheckRequest.Build()
.WithPhone("447009000000")
.WithSimSwap()
.Create();

internal static FraudCheckResponse GetExpectedFraudCheckResponse() => new FraudCheckResponse(
new Guid("6cb4c489-0fc8-4c40-8c3d-95e7e74f9450"),
"phone",
new PhoneData("16197363066", "Orange France", "MOBILE"),
new FraudScore("54", "flag", "medium", "completed"),
new SimSwap("failed", true, "Mobile Network Operator Not Supported"));

internal static Result<FraudCheckRequest> BuildRequestWithFraudScore() =>
FraudCheckRequest.Build()
.WithPhone("447009000000")
.WithFraudScore()
.Create();
}
}

0 comments on commit 9a27e8f

Please sign in to comment.