Skip to content

Commit

Permalink
feat: implement serialization for FraudCheckRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Nov 30, 2023
1 parent 747bfb9 commit c927b87
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "phone",
"phone": "447009000000",
"insights": [
"fraud_score"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "phone",
"phone": "447009000000",
"insights": [
"sim_swap"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Vonage.Common;
using Vonage.Common.Test;
using Vonage.Common.Test.Extensions;
using Vonage.NumberInsightV2.FraudCheck;
using Xunit;

Expand All @@ -18,6 +19,31 @@ public class SerializationTest
public void ShouldDeserialize200() => throw new NotImplementedException();

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

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

[Fact]
public void ShouldSerializeWithSimSwap() => FraudCheckRequest.Build()
.WithPhone("447009000000")
.WithSimSwap()
.Create()
.GetStringContent()
.Should()
.BeSuccess(this.helper.GetRequestJson());
}
}
6 changes: 6 additions & 0 deletions Vonage.Test.Unit/Vonage.Test.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,12 @@
<None Update="NumberInsightsV2\FraudCheck\Data\ShouldSerializeWithFraudScoreAndSimSwap-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="NumberInsightsV2\FraudCheck\Data\ShouldSerializeWithFraudScore-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="NumberInsightsV2\FraudCheck\Data\ShouldSerializeWithSimSwap-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
Expand Down
18 changes: 15 additions & 3 deletions Vonage/NumberInsightV2/FraudCheck/FraudCheckRequest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Text.Json.Serialization;
using Vonage.Common;
using Vonage.Common.Client;
using Vonage.Common.Serialization;

namespace Vonage.NumberInsightV2.FraudCheck;

Expand All @@ -12,17 +14,21 @@ namespace Vonage.NumberInsightV2.FraudCheck;
/// <summary>
/// The insight(s) you need, at least one of: fraud_score and sim_swap.
/// </summary>
[JsonPropertyOrder(2)]
public IEnumerable<string> Insights { get; internal init; }

/// <summary>
/// A single phone number that you need insight about in the E.164 format. Don't use a leading + or 00 when entering a
/// phone number, start with the country code, e.g. 447700900000.
/// </summary>
[JsonPropertyOrder(1)]
[JsonConverter(typeof(PhoneNumberJsonConverter))]
public PhoneNumber Phone { get; internal init; }

/// <summary>
/// Accepted value is “phone” when a phone number is provided.
/// </summary>
[JsonPropertyOrder(0)]
public string Type => "phone";

/// <summary>
Expand All @@ -32,8 +38,14 @@ namespace Vonage.NumberInsightV2.FraudCheck;
public static IBuilderForPhone Build() => new FraudCheckRequestBuilder();

/// <inheritdoc />
public HttpRequestMessage BuildRequestMessage() => throw new NotImplementedException();
public HttpRequestMessage BuildRequestMessage() => VonageRequestBuilder
.Initialize(HttpMethod.Post, this.GetEndpointPath())
.WithContent(this.GetRequestContent())
.Build();

/// <inheritdoc />
public string GetEndpointPath() => throw new NotImplementedException();
public string GetEndpointPath() => "/v2/ni";

private StringContent GetRequestContent() => new(JsonSerializer.BuildWithSnakeCase().SerializeObject(this),
Encoding.UTF8, "application/json");
}

0 comments on commit c927b87

Please sign in to comment.