-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPayoutsApiTests.cs
More file actions
142 lines (126 loc) · 5.24 KB
/
PayoutsApiTests.cs
File metadata and controls
142 lines (126 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using OneOf;
using TrueLayer.Auth;
using TrueLayer.Common;
using TrueLayer.Payments;
using TrueLayer.Payouts;
using TrueLayer.Payouts.Model;
using TrueLayer.Tests.Mocks;
using Xunit;
using AccountIdentifier = TrueLayer.Payouts.Model.AccountIdentifier;
using Beneficiary = TrueLayer.Payouts.Model.Beneficiary;
namespace TrueLayer.Tests.Payouts
{
using PayoutBeneficiary = OneOf<Beneficiary.PaymentSource, Beneficiary.ExternalAccount, Beneficiary.BusinessAccount>;
public class PayoutsApiTests
{
private readonly ApiClientMock _apiClientMock;
private readonly AuthApiMock _authApiMock;
private readonly PayoutsApi _sut;
public PayoutsApiTests()
{
TrueLayerOptions trueLayerOptions = new()
{
Payments = new PaymentsOptions
{
SigningKey = new SigningKey
{
KeyId = "key-id",
PrivateKey = "private-key",
},
Uri = new Uri("http://test.payouts.test"),
},
};
_apiClientMock = new ApiClientMock();
_authApiMock = new AuthApiMock();
_sut = new PayoutsApi(_apiClientMock, _authApiMock, trueLayerOptions);
}
[Theory]
[MemberData(nameof(TestData))]
public async Task Generic_Successful_PayoutSource_Request(CreatePayoutRequest createPayoutRequest)
{
// Arrange
var payoutResponseData = new CreatePayoutResponse("some-id");
_apiClientMock.SetPostAsync(new ApiResponse<CreatePayoutResponse>(payoutResponseData, HttpStatusCode.OK, "trace-id"));
var authData = new GetAuthTokenResponse("access-token", 1000, "Bearer", "");
_authApiMock.SetGetAuthToken(new ApiResponse<GetAuthTokenResponse>(authData, HttpStatusCode.OK, "trace-id"));
// Act
var response = await _sut.CreatePayout(createPayoutRequest, "idempotency-key", CancellationToken.None);
// Assert
response.Should().NotBeNull();
response.IsSuccessful.Should().BeTrue();
response.StatusCode.Should().Be(HttpStatusCode.OK);
response.TraceId.Should().Be("trace-id");
response.Data.Should().NotBeNull();
response.Data!.Id.Should().Be("some-id");
}
[Theory]
[MemberData(nameof(TestData))]
public async Task CreatePayout_Returns_Empty_Response_With_Http_Status_Code_On_Auth_Failure(CreatePayoutRequest createPayoutRequest)
{
// Arrange
_authApiMock.SetGetAuthToken(new ApiResponse<GetAuthTokenResponse>(HttpStatusCode.BadRequest, "trace-id"));
// Act
var actual = await _sut.CreatePayout(createPayoutRequest, "idempotency-key", CancellationToken.None);
//Assert
actual.Should().NotBeNull();
actual.IsSuccessful.Should().BeFalse();
actual.StatusCode.Should().Be(HttpStatusCode.BadRequest);
actual.TraceId.Should().Be("trace-id");
}
[Fact]
public async Task GetPayout_Returns_Empty_Response_With_Http_Status_Code_On_Auth_Failure()
{
// Arrange
_authApiMock.SetGetAuthToken(new ApiResponse<GetAuthTokenResponse>(HttpStatusCode.BadRequest, "trace-id"));
// Act
var actual = await _sut.GetPayout("payout-id", CancellationToken.None);
//Assert
actual.Should().NotBeNull();
actual.IsSuccessful.Should().BeFalse();
actual.StatusCode.Should().Be(HttpStatusCode.BadRequest);
actual.TraceId.Should().Be("trace-id");
}
private static CreatePayoutRequest CreatePayoutRequest(PayoutBeneficiary beneficiary) =>
new(
"merchant-account-id",
100,
Currencies.GBP,
beneficiary,
metadata: new() { { "a", "b" } },
schemeSelection: new SchemeSelection.InstantPreferred());
public static IEnumerable<object[]> TestData =>
new List<object[]>
{
new object[]
{
CreatePayoutRequest(new Beneficiary.ExternalAccount(
"Ms. Lucky",
"truelayer-dotnet",
new AccountIdentifier.Iban("GB33BUKB20201555555555"),
dateOfBirth: new DateTime(1970, 12, 31),
address: new Address("London", "England", "EC1R 4RB", "GB", "1 Hardwick St")
))
},
new object[]
{
CreatePayoutRequest(new Beneficiary.PaymentSource(
"payment-source-id",
"user-id",
"truelayer-dotnet"
))
},
new object[]
{
CreatePayoutRequest(new Beneficiary.BusinessAccount(
"truelayer-dotnet"
))
},
};
}
}