-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPayoutTests.cs
More file actions
87 lines (73 loc) · 3.28 KB
/
PayoutTests.cs
File metadata and controls
87 lines (73 loc) · 3.28 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
using System;
using System.Net;
using System.Threading.Tasks;
using FluentAssertions;
using TrueLayer.Common;
using TrueLayer.Payouts.Model;
using Xunit;
using static TrueLayer.Payouts.Model.GetPayoutsResponse;
namespace TrueLayer.AcceptanceTests
{
public class PayoutTests : IClassFixture<ApiTestFixture>
{
private readonly ApiTestFixture _fixture;
public PayoutTests(ApiTestFixture fixture)
{
_fixture = fixture;
}
[Fact]
public async Task Can_create_payout()
{
CreatePayoutRequest payoutRequest = CreatePayoutRequest();
var response = await _fixture.TlClients[0].Payouts.CreatePayout(payoutRequest);
response.StatusCode.Should().Be(HttpStatusCode.Accepted);
response.Data.Should().NotBeNull();
response.Data!.Id.Should().NotBeNullOrWhiteSpace();
}
[Fact]
public async Task Can_get_payout()
{
CreatePayoutRequest payoutRequest = CreatePayoutRequest();
var response = await _fixture.TlClients[0].Payouts.CreatePayout(
payoutRequest, idempotencyKey: Guid.NewGuid().ToString());
response.StatusCode.Should().Be(HttpStatusCode.Accepted);
response.Data.Should().NotBeNull();
response.Data!.Id.Should().NotBeNullOrWhiteSpace();
var getPayoutResponse = await _fixture.TlClients[0].Payouts.GetPayout(response.Data.Id);
getPayoutResponse.StatusCode.Should().Be(HttpStatusCode.OK);
getPayoutResponse.Data.Value.Should().NotBeNull();
PayoutDetails? details = getPayoutResponse.Data.Value as PayoutDetails;
details.Should().NotBeNull();
details!.Id.Should().Be(response.Data.Id);
details.Currency.Should().Be(payoutRequest.Currency);
details.Beneficiary.AsT1.Should().NotBeNull();
details.Status.Should().BeOneOf("pending", "authorized", "executed", "failed");
details.CreatedAt.Should().NotBe(DateTime.MinValue);
details.CreatedAt.Should().NotBe(DateTime.MaxValue);
details.Metadata.Should().BeEquivalentTo(payoutRequest.Metadata);
}
[Fact]
public async Task GetPayout_Url_As_PayoutId_Should_Throw_Exception()
{
var client = _fixture.TlClients[0];
const string payoutId = "https://test.com";
var result = await Assert.ThrowsAsync<ArgumentException>(() =>
client.Payouts.GetPayout(payoutId));
result.Message.Should().Be("Value is malformed (Parameter 'id')");
}
private CreatePayoutRequest CreatePayoutRequest()
=> new(
_fixture.ClientMerchantAccounts[0].GbpMerchantAccountId,
100,
Currencies.GBP,
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")),
metadata: new() { { "a", "b" } },
schemeSelection: new SchemeSelection.InstantOnly()
);
}
}