Skip to content

Commit

Permalink
#367: Add unit test to verify serialization and deserialization of Re…
Browse files Browse the repository at this point in the history
…verseRouting property
  • Loading branch information
Viincenttt committed Jul 6, 2024
1 parent af7f437 commit b524cb3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/Mollie.Tests.Unit/Client/RefundClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,49 @@ public async Task CreateRefundAsync_NoPaymentIdIsGiven_ArgumentExceptionIsThrown
exception.Message.Should().Be("Required URL argument 'paymentId' is null or empty");
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task CreateRefundAsync_WithReverseRouting_ResponseIsDeserializedInExpectedFormat(bool reverseRouting) {
// Given: We create a refund with a routing destination
const string paymentId = "tr_7UhSN1zuXS";
var refundRequest = new RefundRequest {
Amount = new Amount(Currency.EUR, 100m),
ReverseRouting = reverseRouting
};
string expectedStringValue = reverseRouting.ToString().ToLowerInvariant();
string expectedRoutingInformation = $"\"reverseRouting\": {expectedStringValue}";
string expectedJsonResponse = @$"{{
""resource"": ""refund"",
""id"": ""re_4qqhO89gsT"",
""description"": """",
""amount"": {{
""currency"": ""EUR"",
""value"": ""100.00""
}},
""reverseRouting"": ""{expectedStringValue}"",
""status"": ""pending"",
""metadata"": null,
""paymentId"": ""{paymentId}"",
""createdAt"": ""2023-03-14T17:09:02.0Z""
}}";
var mockHttp = CreateMockHttpMessageHandler(
HttpMethod.Post,
$"{BaseMollieClient.ApiEndPoint}payments/{paymentId}/refunds",
expectedJsonResponse,
expectedRoutingInformation);
HttpClient httpClient = mockHttp.ToHttpClient();
RefundClient refundClient = new("api-key", httpClient);

// When: We create the refund
RefundResponse refundResponse = await refundClient.CreatePaymentRefundAsync(paymentId, refundRequest);

// Then
mockHttp.VerifyNoOutstandingExpectation();
refundResponse.ReverseRouting.Should().Be(reverseRouting);
refundResponse.RoutingReversals.Should().BeNull();
}

[Fact]
public async Task CreateRefundAsync_WithRoutingInformation_ResponseIsDeserializedInExpectedFormat() {
// Given: We create a refund with a routing destination
Expand Down Expand Up @@ -144,6 +187,7 @@ public async Task CreateRefundAsync_WithRoutingInformation_ResponseIsDeserialize
// Then
mockHttp.VerifyNoOutstandingExpectation();
refundResponse.RoutingReversals.Should().BeEquivalentTo(refundRequest.RoutingReversals);
refundResponse.ReverseRouting.Should().BeNull();
}

[Theory]
Expand Down

0 comments on commit b524cb3

Please sign in to comment.