Skip to content

Commit

Permalink
refactor: [breaking] remove sync methods from VerifyClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Mar 14, 2024
1 parent d3d7627 commit 36fb4f0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 354 deletions.
252 changes: 5 additions & 247 deletions Vonage.Test/VerifyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class VerifyTest : TestBase
[Theory]
[InlineData(true, true)]
[InlineData(false, false)]
public void Psd2Verification(bool passCreds, bool kitchenSink)
public async Task Psd2VerificationAsync(bool passCreds, bool kitchenSink)
{
var expectedResponse = @"{
""request_id"": ""abcdef0123456789abcdef0123456789"",
Expand Down Expand Up @@ -44,104 +44,11 @@ public void Psd2Verification(bool passCreds, bool kitchenSink)
VerifyResponse response;
if (passCreds)
{
response = client.VerifyClient.VerifyRequestWithPSD2(request, creds);
response = await client.VerifyClient.VerifyRequestWithPSD2Async(request, creds);
}
else
{
response = client.VerifyClient.VerifyRequestWithPSD2(request);
}

Assert.Equal("abcdef0123456789abcdef0123456789", response.RequestId);
Assert.Equal("0", response.Status);
}

[Theory]
[InlineData(true, true)]
[InlineData(false, false)]
public void Psd2VerificationAsync(bool passCreds, bool kitchenSink)
{
var expectedResponse = @"{
""request_id"": ""abcdef0123456789abcdef0123456789"",
""status"": ""0""
}";
var expectedUri = $"{this.ApiUrl}/verify/psd2/json";
string expectedRequestContent;
var request = new Psd2Request {Number = "447700900000", Payee = "Acme Inc", Amount = 4.8};
if (kitchenSink)
{
expectedRequestContent =
$"payee={WebUtility.UrlEncode("Acme Inc")}&amount=4.8&workflow_id=1&number=447700900000&country=GB&code_length=4&lg=en-us&pin_expiry=240&next_event_wait=60&api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
request.Country = "GB";
request.CodeLength = 4;
request.Lg = "en-us";
request.PinExpiry = 240;
request.NextEventWait = 60;
request.WorkflowId = Psd2Request.Workflow.SMS_TTS_TTS;
}
else
{
expectedRequestContent =
$"payee={WebUtility.UrlEncode("Acme Inc")}&amount=4.8&number=447700900000&api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
}

this.Setup(expectedUri, expectedResponse, expectedRequestContent);
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
VerifyResponse response;
if (passCreds)
{
response = client.VerifyClient.VerifyRequestWithPSD2(request, creds);
}
else
{
response = client.VerifyClient.VerifyRequestWithPSD2(request);
}

Assert.Equal("abcdef0123456789abcdef0123456789", response.RequestId);
Assert.Equal("0", response.Status);
}

[Theory]
[InlineData(true, true)]
[InlineData(false, false)]
public void RequestVerification(bool passCreds, bool kitchenSink)
{
var expectedResponse = @"{
""request_id"": ""abcdef0123456789abcdef0123456789"",
""status"": ""0""
}";
var expectedUri = $"{this.ApiUrl}/verify/json";
string expectedRequestContent;
var request = new VerifyRequest {Number = "447700900000", Brand = "Acme Inc"};
if (kitchenSink)
{
expectedRequestContent =
$"brand={WebUtility.UrlEncode("Acme Inc")}&sender_id=ACME&workflow_id=1&number=447700900000&country=GB&code_length=4&lg=en-us&pin_expiry=240&next_event_wait=60&api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
request.Country = "GB";
request.SenderId = "ACME";
request.CodeLength = 4;
request.Lg = "en-us";
request.PinExpiry = 240;
request.NextEventWait = 60;
request.WorkflowId = VerifyRequest.Workflow.SMS_TTS_TTS;
}
else
{
expectedRequestContent =
$"brand={WebUtility.UrlEncode("Acme Inc")}&number=447700900000&api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
}

this.Setup(expectedUri, expectedResponse, expectedRequestContent);
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
VerifyResponse response;
if (passCreds)
{
response = client.VerifyClient.VerifyRequest(request, creds);
}
else
{
response = client.VerifyClient.VerifyRequest(request);
response = await client.VerifyClient.VerifyRequestWithPSD2Async(request);
}

Assert.Equal("abcdef0123456789abcdef0123456789", response.RequestId);
Expand Down Expand Up @@ -195,55 +102,6 @@ public async Task RequestVerificationAsync(bool passCreds, bool kitchenSink)
Assert.Equal("0", response.Status);
}

[Theory]
[InlineData(true, true)]
[InlineData(false, false)]
public void TestCheckVerification(bool passCreds, bool kitchenSink)
{
var expectedResponse = @"{
""request_id"": ""abcdef0123456789abcdef0123456789"",
""event_id"": ""0A00000012345678"",
""status"": ""0"",
""price"": ""0.10000000"",
""currency"": ""EUR"",
""estimated_price_messages_sent"": ""0.03330000""
}";
var expectedUri = $"{this.ApiUrl}/verify/check/json";
string expectedRequestContent;
var request = new VerifyCheckRequest {Code = "1234", RequestId = "abcdef0123456789abcdef0123456789"};
if (kitchenSink)
{
expectedRequestContent =
$"request_id=abcdef0123456789abcdef0123456789&code=1234&ip_address={WebUtility.UrlEncode("123.0.0.255")}&api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
request.IpAddress = "123.0.0.255";
}
else
{
expectedRequestContent =
$"request_id=abcdef0123456789abcdef0123456789&code=1234&api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
}

this.Setup(expectedUri, expectedResponse, expectedRequestContent);
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
VerifyCheckResponse response;
if (passCreds)
{
response = client.VerifyClient.VerifyCheck(request, creds);
}
else
{
response = client.VerifyClient.VerifyCheck(request);
}

Assert.Equal("0.10000000", response.Price);
Assert.Equal("0.03330000", response.EstimatedPriceMessagesSent);
Assert.Equal("EUR", response.Currency);
Assert.Equal("0A00000012345678", response.EventId);
Assert.Equal("abcdef0123456789abcdef0123456789", response.RequestId);
Assert.Equal("0", response.Status);
}

[Theory]
[InlineData(true, true)]
[InlineData(false, false)]
Expand Down Expand Up @@ -293,36 +151,6 @@ public async Task TestCheckVerificationAsync(bool passCreds, bool kitchenSink)
Assert.Equal("0", response.Status);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void TestControlVerify(bool passCreds)
{
var expectedResponse = @"{
""status"": ""0"",
""command"": ""cancel""
}";
var expectedUri = $"{this.ApiUrl}/verify/control/json";
var requestContent =
$"request_id=abcdef0123456789abcdef0123456789&cmd=cancel&api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
this.Setup(expectedUri, expectedResponse, requestContent);
var request = new VerifyControlRequest {Cmd = "cancel", RequestId = "abcdef0123456789abcdef0123456789"};
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
VerifyControlResponse response;
if (passCreds)
{
response = client.VerifyClient.VerifyControl(request, creds);
}
else
{
response = client.VerifyClient.VerifyControl(request, creds);
}

Assert.Equal("0", response.Status);
Assert.Equal("cancel", response.Command);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down Expand Up @@ -354,7 +182,7 @@ public async Task TestControlVerifyAsync(bool passCreds)
}

[Fact]
public void TestControlVerifyInvalidCredentials()
public async Task TestControlVerifyInvalidCredentials()
{
var expectedResponse = @"{
""status"": ""4"",
Expand All @@ -369,7 +197,7 @@ public void TestControlVerifyInvalidCredentials()
var client = this.BuildVonageClient(creds);
try
{
client.VerifyClient.VerifyControl(request, creds);
await client.VerifyClient.VerifyControlAsync(request, creds);
Assert.True(false, "Automatically failing because exception wasn't thrown");
}
catch (VonageVerifyResponseException ex)
Expand All @@ -379,76 +207,6 @@ public void TestControlVerifyInvalidCredentials()
}
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void TestVerifySearch(bool passCreds)
{
var expectedResponse = @"{
""request_id"": ""abcdef0123456789abcdef0123456789"",
""account_id"": ""abcdef01"",
""status"": ""IN PROGRESS"",
""number"": ""447700900000"",
""price"": ""0.10000000"",
""currency"": ""EUR"",
""sender_id"": ""mySenderId"",
""date_submitted"": ""2020-01-01 12:00:00"",
""date_finalized"": ""2020-01-01 12:00:00"",
""first_event_date"": ""2020-01-01 12:00:00"",
""last_event_date"": ""2020-01-01 12:00:00"",
""checks"": [
{
""date_received"": ""2020-01-01 12:00:00"",
""code"": ""987654"",
""status"": ""abc123"",
""ip_address"": ""123.0.0.255""
}
],
""events"": [
{
""type"": ""abc123"",
""id"": ""abc123""
}
],
""estimated_price_messages_sent"": ""0.03330000""
}";
var expectedUri =
$"{this.ApiUrl}/verify/search/json?request_id=abcdef0123456789abcdef0123456789&api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
this.Setup(expectedUri, expectedResponse);
var request = new VerifySearchRequest {RequestId = "abcdef0123456789abcdef0123456789"};
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
VerifySearchResponse response;
if (passCreds)
{
response = client.VerifyClient.VerifySearch(request, creds);
}
else
{
response = client.VerifyClient.VerifySearch(request);
}

var req = response;
Assert.Equal("abcdef0123456789abcdef0123456789", req.RequestId);
Assert.Equal("abcdef01", req.AccountId);
Assert.Equal("IN PROGRESS", req.Status);
Assert.Equal("447700900000", req.Number);
Assert.Equal("0.10000000", req.Price);
Assert.Equal("EUR", req.Currency);
Assert.Equal("mySenderId", req.SenderId);
Assert.Equal("2020-01-01 12:00:00", req.DateSubmitted);
Assert.Equal("2020-01-01 12:00:00", req.DateFinalized);
Assert.Equal("2020-01-01 12:00:00", req.FirstEventDate);
Assert.Equal("2020-01-01 12:00:00", req.LastEventDate);
Assert.Equal("2020-01-01 12:00:00", req.Checks[0].DateReceived);
Assert.Equal("987654", req.Checks[0].Code);
Assert.Equal("abc123", req.Checks[0].Status);
Assert.Equal("123.0.0.255", req.Checks[0].IpAddress);
Assert.Equal("abc123", req.Events[0].Type);
Assert.Equal("abc123", req.Events[0].Id);
Assert.Equal("0.03330000", req.EstimatedPriceMessagesSent);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down
43 changes: 0 additions & 43 deletions Vonage/Verify/IVerifyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,47 +47,4 @@ public interface IVerifyClient
/// <param name="creds"></param>
/// <returns></returns>
Task<VerifyResponse> VerifyRequestWithPSD2Async(Psd2Request request, Credentials creds = null);

/// <summary>
/// Use Verify request to generate and send a PIN to your user
/// </summary>
/// <param name="request"></param>
/// <param name="creds"></param>
/// <returns></returns>
VerifyResponse VerifyRequest(VerifyRequest request, Credentials creds = null);

/// <summary>
/// Use Verify check to confirm that the PIN you received from your user matches the one sent by Vonage in your Verify request
/// </summary>
/// <param name="request"></param>
/// <param name="creds"></param>
/// <returns></returns>
VerifyCheckResponse VerifyCheck(VerifyCheckRequest request, Credentials creds = null);

/// <summary>
/// Use Verify search to check the status of past or current verification requests
/// </summary>
/// <param name="request"></param>
/// <param name="creds"></param>
/// <returns></returns>
VerifySearchResponse VerifySearch(VerifySearchRequest request, Credentials creds = null);

/// <summary>
/// Control the progress of your Verify requests. To cancel an existing Verify request, or to trigger the next verification event
/// </summary>
/// <param name="request"></param>
/// <param name="creds"></param>
/// <returns></returns>
VerifyControlResponse VerifyControl(VerifyControlRequest request, Credentials creds = null);

/// <summary>
/// Use Verify request to generate and send a PIN to your user to authorize a payment:
/// 1. Create a request to send a verification code to your user.
/// 2. Check the status field in the response to ensure that your request was successful (zero is success).
/// 3. Use the request_id field in the response for the Verify check.
/// </summary>
/// <param name="request"></param>
/// <param name="creds"></param>
/// <returns></returns>
VerifyResponse VerifyRequestWithPSD2(Psd2Request request, Credentials creds = null);
}
Loading

0 comments on commit 36fb4f0

Please sign in to comment.