-
Notifications
You must be signed in to change notification settings - Fork 12
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
1 parent
a0fb393
commit 9d2ffb5
Showing
11 changed files
with
301 additions
and
255 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
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,28 @@ | ||
using System.Net.Http; | ||
using System.Net.Http.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace TrueLayer.AcceptanceTests.Clients; | ||
|
||
public class ApiClient | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public ApiClient(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
public async Task<HttpResponseMessage> SubmitPaymentsProviderReturnAsync(string query, string fragment) | ||
{ | ||
var requestBody = new SubmitProviderReturnParametersRequest { Query = query, Fragment = fragment }; | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Post, "/spa/payments-provider-return") | ||
{ | ||
Content = JsonContent.Create(requestBody) | ||
}; | ||
var response = await _httpClient.SendAsync(request); | ||
return response; | ||
} | ||
} | ||
|
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,62 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Net.Mime; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
|
||
namespace TrueLayer.AcceptanceTests.Clients; | ||
|
||
public class MockBankClient | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public MockBankClient(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
public async Task<Uri> AuthorisePaymentAsync( | ||
Uri authUri, | ||
MockBankPaymentAction paymentAction, | ||
int settlementDelayInSeconds = 0) | ||
{ | ||
var mockPaymentId = authUri.Segments.Last(); | ||
var token = authUri.Fragment[7..]; | ||
|
||
var requestBody = $@"{{ ""action"": ""{paymentAction}"", ""settlement_delay_in_seconds"": {settlementDelayInSeconds} }}"; | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Post, $"api/single-immediate-payments/{mockPaymentId}/action") | ||
{ | ||
Headers = { { "Authorization", $"Bearer {token}" } }, | ||
Content = new StringContent(requestBody, Encoding.UTF8, MediaTypeNames.Application.Json), | ||
}; | ||
var response = await _httpClient.SendAsync(request); | ||
var responseBody = await response.Content.ReadAsStringAsync(); | ||
response.StatusCode.Should().Be(HttpStatusCode.Accepted, "submit mock payment response should be 202"); | ||
return new Uri(responseBody); | ||
} | ||
|
||
public async Task<Uri> AuthoriseMandateAsync( | ||
Uri authUri, | ||
MockBankMandateAction mandateAction, | ||
int settlementDelayInSeconds = 0) | ||
{ | ||
var mockMandateId = authUri.Segments.Last(); | ||
var token = authUri.Fragment[7..]; | ||
|
||
var requestBody = $@"{{ ""action"": ""{mandateAction}"", ""settlement_delay_in_seconds"": {settlementDelayInSeconds} }}"; | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Post, $"/api/vrp-consents/{mockMandateId}/action") | ||
{ | ||
Headers = { { "Authorization", $"Bearer {token}" } }, | ||
Content = new StringContent(requestBody, Encoding.UTF8, MediaTypeNames.Application.Json), | ||
}; | ||
var response = await _httpClient.SendAsync(request); | ||
var responseBody = await response.Content.ReadAsStringAsync(); | ||
response.StatusCode.Should().Be(HttpStatusCode.Accepted, "submit mock mandate response should be 202"); | ||
return new Uri(responseBody); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/TrueLayer.AcceptanceTests/Clients/MockBankPaymentAction.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 @@ | ||
namespace TrueLayer.AcceptanceTests.Clients; | ||
|
||
public enum MockBankPaymentAction | ||
{ | ||
Cancel, | ||
RejectAuthorisation, | ||
Execute, | ||
RejectExecution, | ||
} | ||
|
||
public enum MockBankMandateAction | ||
{ | ||
Authorise, | ||
RejectAuthorisation, | ||
Revoke, | ||
Cancel, | ||
} |
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
9 changes: 9 additions & 0 deletions
9
test/TrueLayer.AcceptanceTests/Clients/SubmitProviderReturnParametersRequest.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,9 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace TrueLayer.AcceptanceTests.Clients; | ||
|
||
public class SubmitProviderReturnParametersRequest | ||
{ | ||
[JsonPropertyName("query")] public string? Query { get; set; } | ||
[JsonPropertyName("fragment")] public string? Fragment { get; set; } | ||
} |
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,119 @@ | ||
using System.Collections.Generic; | ||
using OneOf; | ||
using TrueLayer.Mandates.Model; | ||
using TrueLayer.Payments.Model; | ||
|
||
namespace TrueLayer.AcceptanceTests | ||
{ | ||
using AccountIdentifierUnion = OneOf< | ||
AccountIdentifier.SortCodeAccountNumber, | ||
AccountIdentifier.Iban, | ||
AccountIdentifier.Bban, | ||
AccountIdentifier.Nrb>; | ||
using MandateUnion = OneOf<Mandate.VRPCommercialMandate, Mandate.VRPSweepingMandate>; | ||
using ProviderUnion = OneOf<Payments.Model.Provider.UserSelected, Mandates.Model.Provider.Preselected>; | ||
|
||
public static class MandateTestCases | ||
{ | ||
private static AccountIdentifier.SortCodeAccountNumber accountIdentifier = new("140662", "10003957"); | ||
private const string CommercialProviderId = "mock-payments-gb-redirect"; | ||
private const string ProviderId = "mock-payments-gb-redirect"; | ||
public static CreateMandateRequest CreateTestMandateRequest( | ||
MandateUnion mandate, | ||
string currency = Currencies.GBP) | ||
=> new( | ||
mandate, | ||
currency, | ||
new Constraints( | ||
MaximumIndividualAmount: 1000, | ||
new PeriodicLimits(Month: new Limit(2000, PeriodAlignment.Calendar))), | ||
new PaymentUserRequest( | ||
id: "f9b48c9d-176b-46dd-b2da-fe1a2b77350c", | ||
name: "Remi Terr", | ||
email: "[email protected]", | ||
phone: "+44777777777"), | ||
Metadata: new Dictionary<string, string> { { "a_custom_key", "a-custom-value" } }); | ||
|
||
public static CreatePaymentRequest CreateTestMandatePaymentRequest( | ||
CreateMandateRequest mandateRequest, | ||
string mandateId, | ||
bool setRelatedProducts = true) | ||
=> new( | ||
mandateRequest.Constraints.MaximumIndividualAmount, | ||
mandateRequest.Currency, | ||
new PaymentMethod.Mandate(mandateId, "reference", null), | ||
mandateRequest.User, | ||
setRelatedProducts ? new RelatedProducts(new SignupPlus()) : null); | ||
|
||
public static CreateMandateRequest CreateTestMandateRequests() | ||
=> CreateTestMandateRequest(MandateUnion.FromT1(new Mandate.VRPSweepingMandate( | ||
"sweeping", | ||
ProviderUnion.FromT1(new Mandates.Model.Provider.Preselected("preselected", ProviderId)), | ||
new Mandates.Model.Beneficiary.ExternalAccount( | ||
"external_account", | ||
"Bob NET SDK", | ||
AccountIdentifierUnion.FromT0(accountIdentifier))))); | ||
|
||
public static IEnumerable<object[]> CreateTestSweepingPreselectedMandateRequests() | ||
{ | ||
yield return | ||
[ | ||
CreateTestMandateRequest(MandateUnion.FromT1(new Mandate.VRPSweepingMandate( | ||
"sweeping", | ||
ProviderUnion.FromT1(new Mandates.Model.Provider.Preselected("preselected", ProviderId)), | ||
new Mandates.Model.Beneficiary.ExternalAccount( | ||
"external_account", | ||
"Bob NET SDK", | ||
AccountIdentifierUnion.FromT0(accountIdentifier))))) | ||
]; | ||
} | ||
|
||
public static IEnumerable<object[]> CreateTestCommercialPreselectedMandateRequests() | ||
{ | ||
yield return | ||
[ | ||
CreateTestMandateRequest(MandateUnion.FromT0(new Mandate.VRPCommercialMandate( | ||
"commercial", | ||
ProviderUnion.FromT1(new Mandates.Model.Provider.Preselected("preselected", CommercialProviderId)), | ||
new Mandates.Model.Beneficiary.ExternalAccount( | ||
"external_account", | ||
"My Bank Account", | ||
AccountIdentifierUnion.FromT0(accountIdentifier))))) | ||
]; | ||
} | ||
|
||
public static IEnumerable<object[]> CreateTestSweepingUserSelectedMandateRequests() | ||
{ | ||
yield return | ||
[ | ||
CreateTestMandateRequest(MandateUnion.FromT1(new Mandate.VRPSweepingMandate( | ||
"sweeping", | ||
ProviderUnion.FromT0(new Payments.Model.Provider.UserSelected | ||
{ | ||
Filter = new ProviderFilter { Countries = ["GB"], ReleaseChannel = "alpha" }, | ||
}), | ||
new Mandates.Model.Beneficiary.ExternalAccount( | ||
"external_account", | ||
"My Bank Account", | ||
AccountIdentifierUnion.FromT0(accountIdentifier))))) | ||
]; | ||
} | ||
|
||
public static IEnumerable<object[]> CreateTestCommercialUserSelectedMandateRequests() | ||
{ | ||
yield return | ||
[ | ||
CreateTestMandateRequest(MandateUnion.FromT0(new Mandate.VRPCommercialMandate( | ||
"commercial", | ||
ProviderUnion.FromT0(new Payments.Model.Provider.UserSelected | ||
{ | ||
Filter = new ProviderFilter { Countries = ["GB"], ReleaseChannel = "alpha" }, | ||
}), | ||
new Mandates.Model.Beneficiary.ExternalAccount( | ||
"external_account", | ||
"My Bank Account", | ||
AccountIdentifierUnion.FromT0(accountIdentifier))))) | ||
]; | ||
} | ||
} | ||
} |
Oops, something went wrong.