Skip to content

Commit

Permalink
Add unit tests for EnableGiftCardIssuerAsync method
Browse files Browse the repository at this point in the history
  • Loading branch information
Viincenttt committed Dec 21, 2023
1 parent ae6fbaa commit e6695f5
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/Mollie.Tests.Unit/Client/ProfileClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,44 @@ public async Task DeleteProfileAsync_WithMissingProfileIdParameter_ThrowsArgumen
exception.Message.Should().Be($"Required URL argument 'profileId' is null or empty");
}

[Fact]
public async Task EnableGiftCardIssuerAsync_ForCurrentProfile_ResponseIsDeserializedInExpectedFormat()
{
// Arrange
const string issuer = "festivalcadeau";
var mockHttp = new MockHttpMessageHandler();
mockHttp.Expect(HttpMethod.Post,$"{BaseMollieClient.ApiEndPoint}profiles/me/methods/giftcard/issuers/{issuer}")
.With(request => request.Headers.Contains("Idempotency-Key"))
.Respond("application/json", defaultEnableGiftcardIssuerResponse);
HttpClient httpClient = mockHttp.ToHttpClient();
using var profileClient = new ProfileClient("abcde", httpClient);

// Act
var result = await profileClient.EnableGiftCardIssuerAsync(issuer);

// Assert
mockHttp.VerifyNoOutstandingRequest();
result.Resource.Should().Be("issuer");
result.Id.Should().Be(issuer);
result.Description.Should().Be("FestivalCadeau Giftcard");
result.Status.Should().Be("pending-issuer");
}

[Fact]
public async Task EnableGiftCardIssuerAsync_ForCurrentProfileWithMissingIssuerParameter_ThrowsArgumentException()
{
// Arrange
var mockHttp = new MockHttpMessageHandler();
HttpClient httpClient = mockHttp.ToHttpClient();
using var profileClient = new ProfileClient("abcde", httpClient);

// Act
var exception = await Assert.ThrowsAsync<ArgumentException>(() => profileClient.EnableGiftCardIssuerAsync(string.Empty));

// Assert
exception.Message.Should().Be($"Required URL argument 'issuer' is null or empty");
}

private void AssertDefaultProfileResponse(ProfileResponse result)
{
result.Resource.Should().Be("profile");
Expand All @@ -244,6 +282,23 @@ private void AssertDefaultProfileResponse(ProfileResponse result)
result.Status.Should().Be(ProfileStatus.Unverified);
}

private const string defaultEnableGiftcardIssuerResponse = @"{
""resource"": ""issuer"",
""id"": ""festivalcadeau"",
""description"": ""FestivalCadeau Giftcard"",
""status"": ""pending-issuer"",
""_links"": {
""self"": {
""href"": ""https://api.mollie.com/v2/issuers/festivalcadeau"",
""type"": ""application/hal+json""
},
""documentation"": {
""href"": ""https://docs.mollie.com/reference/v2/profiles-api/enable-giftcard-issuer"",
""type"": ""text/html""
}
}
}";

private const string defaultPaymentMethodResponse = @"{
""resource"": ""method"",
""id"": ""ideal"",
Expand Down

0 comments on commit e6695f5

Please sign in to comment.