|
| 1 | +using System; |
| 2 | +using FluentAssertions; |
| 3 | +using TrueLayer.Payments; |
| 4 | +using TrueLayer.Payments.Model; |
| 5 | +using Xunit; |
| 6 | + |
| 7 | +namespace TrueLayer.Tests.Payments; |
| 8 | + |
| 9 | +public class HppLinkBuilderTests |
| 10 | +{ |
| 11 | + [Fact] |
| 12 | + public void Build_Payment_Sandbox_ReturnsCorrectUri() |
| 13 | + { |
| 14 | + var paymentId = new Guid().ToString(); |
| 15 | + const string token = "eyJhbGciOiJSUzUxMiIsImtpZCI6IlBDNHJFVHZycGZTV1dqYW91R2dIbmJHNTBBR184SFBHXzBuU0"; |
| 16 | + var sut = new HppLinkBuilder(null, true); |
| 17 | + |
| 18 | + var result = sut.Build(paymentId, token, new Uri("https://return.client.com/"), ResourceType.Payment); |
| 19 | + |
| 20 | + result.Should().Be($"https://payment.truelayer-sandbox.com/payments#payment_id={paymentId}&resource_token={token}&return_uri=https://return.client.com/"); |
| 21 | + } |
| 22 | + |
| 23 | + [Fact] |
| 24 | + public void Build_Payment_Production_ReturnsCorrectUri() |
| 25 | + { |
| 26 | + var paymentId = new Guid().ToString(); |
| 27 | + const string token = "eyJhbGciOiJSUzUxMiIsImtpZCI6IlBDNHJFVHZycGZTV1dqYW91R2dIbmJHNTBBR184SFBHXzBuU0"; |
| 28 | + var sut = new HppLinkBuilder(null, false); |
| 29 | + |
| 30 | + var result = sut.Build(paymentId, token, new Uri("https://return.client.com/"), ResourceType.Payment); |
| 31 | + |
| 32 | + result.Should().Be($"https://payment.truelayer.com/payments#payment_id={paymentId}&resource_token={token}&return_uri=https://return.client.com/"); |
| 33 | + } |
| 34 | + |
| 35 | + [Fact] |
| 36 | + public void Build_CustomUri_ReturnsCorrectUri() |
| 37 | + { |
| 38 | + var uri = new Uri("https://api.custom.com/"); |
| 39 | + var paymentId = new Guid().ToString(); |
| 40 | + const string token = "eyJhbGciOiJSUzUxMiIsImtpZCI6IlBDNHJFVHZycGZTV1dqYW91R2dIbmJHNTBBR184SFBHXzBuU0"; |
| 41 | + var sut = new HppLinkBuilder(uri, false); |
| 42 | + |
| 43 | + var result = sut.Build(paymentId, token, new Uri("https://return.client.com/"), ResourceType.Payment); |
| 44 | + |
| 45 | + result.Should().Be($"https://api.custom.com/payments#payment_id={paymentId}&resource_token={token}&return_uri=https://return.client.com/"); |
| 46 | + } |
| 47 | + |
| 48 | + [Fact] |
| 49 | + public void Build_Payment_Sandbox_MaxWait_Signup_ReturnsCorrectUri() |
| 50 | + { |
| 51 | + var paymentId = new Guid().ToString(); |
| 52 | + const string token = "eyJhbGciOiJSUzUxMiIsImtpZCI6IlBDNHJFVHZycGZTV1dqYW91R2dIbmJHNTBBR184SFBHXzBuU0"; |
| 53 | + var sut = new HppLinkBuilder(null, true); |
| 54 | + |
| 55 | + var result = sut.Build(paymentId, token, new Uri("https://return.client.com/"), ResourceType.Payment, 60, true); |
| 56 | + |
| 57 | + result.Should().Be($"https://payment.truelayer-sandbox.com/payments#payment_id={paymentId}&resource_token={token}&return_uri=https://return.client.com/&max_wait_seconds=60&signup=true"); |
| 58 | + } |
| 59 | + |
| 60 | + [Fact] |
| 61 | + public void Build_Mandate_Sandbox_ReturnsCorrectUri() |
| 62 | + { |
| 63 | + var mandateId = new Guid().ToString(); |
| 64 | + const string token = "eyJhbGciOiJSUzUxMiIsImtpZCI6IlBDNHJFVHZycGZTV1dqYW91R2dIbmJHNTBBR184SFBHXzBuU0"; |
| 65 | + var sut = new HppLinkBuilder(null, true); |
| 66 | + |
| 67 | + var result = sut.Build(mandateId, token, new Uri("https://return.client.com/"), ResourceType.Mandate); |
| 68 | + |
| 69 | + result.Should().Be($"https://payment.truelayer-sandbox.com/mandates#mandate_id={mandateId}&resource_token={token}&return_uri=https://return.client.com/"); |
| 70 | + } |
| 71 | + |
| 72 | + [Fact] |
| 73 | + public void Build_Mandate_Production_ReturnsCorrectUri() |
| 74 | + { |
| 75 | + var mandateId = new Guid().ToString(); |
| 76 | + const string token = "eyJhbGciOiJSUzUxMiIsImtpZCI6IlBDNHJFVHZycGZTV1dqYW91R2dIbmJHNTBBR184SFBHXzBuU0"; |
| 77 | + var sut = new HppLinkBuilder(null, false); |
| 78 | + |
| 79 | + var result = sut.Build(mandateId, token, new Uri("https://return.client.com/"), ResourceType.Mandate); |
| 80 | + |
| 81 | + result.Should().Be($"https://payment.truelayer.com/mandates#mandate_id={mandateId}&resource_token={token}&return_uri=https://return.client.com/"); |
| 82 | + } |
| 83 | +} |
0 commit comments