Skip to content

Commit

Permalink
Fix for subscription integration test and add support for CustomerId …
Browse files Browse the repository at this point in the history
…property in SubscriptionResponse
  • Loading branch information
Viincenttt committed Sep 29, 2024
1 parent 721b12a commit a632e6e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public record SubscriptionResponse {
/// </summary>
public string? WebhookUrl { get; set; }

/// <summary>
/// The customer this subscription belongs to.
/// </summary>
public required string CustomerId { get; init; }

/// <summary>
/// The optional metadata you provided upon subscription creation. Metadata can for example be used to link a plan to a
/// subscription.
Expand Down
24 changes: 18 additions & 6 deletions tests/Mollie.Tests.Integration/Api/SubscriptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,15 @@ public async Task CanCancelSubscription() {
[DefaultRetryFact]
public async Task CanUpdateSubscription() {
// Given
string customerId = await GetFirstCustomerWithValidMandate();
ListResponse<SubscriptionResponse> subscriptions = await _subscriptionClient.GetSubscriptionListAsync(customerId);
var activeSubscription = await GetActiveSubscription();

// When
SubscriptionResponse subscriptionToUpdate = subscriptions.Items
.FirstOrDefault(s => s.Status != SubscriptionStatus.Canceled);
if (subscriptionToUpdate != null) {
if (activeSubscription != null) {
var customerId = activeSubscription.CustomerId;
SubscriptionUpdateRequest request = new SubscriptionUpdateRequest() {
Description = $"Updated subscription {Guid.NewGuid()}"
};
SubscriptionResponse response = await _subscriptionClient.UpdateSubscriptionAsync(customerId, subscriptionToUpdate.Id, request);
SubscriptionResponse response = await _subscriptionClient.UpdateSubscriptionAsync(customerId, activeSubscription.Id, request);

// Then
response.Description.Should().Be(request.Description);
Expand Down Expand Up @@ -163,6 +161,20 @@ private async Task<string> GetFirstCustomerWithValidMandate() {
return null;
}

private async Task<SubscriptionResponse?> GetActiveSubscription() {

Check warning on line 164 in tests/Mollie.Tests.Integration/Api/SubscriptionTests.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 164 in tests/Mollie.Tests.Integration/Api/SubscriptionTests.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
ListResponse<CustomerResponse> customers = await _customerClient.GetCustomerListAsync();

foreach (CustomerResponse customer in customers.Items.OrderByDescending(x => x.CreatedAt)) {
ListResponse<SubscriptionResponse> subscriptions = await _subscriptionClient.GetSubscriptionListAsync(customer.Id);
var activeSubscription = subscriptions.Items.FirstOrDefault(x => x.Status == SubscriptionStatus.Active);
if (activeSubscription != null) {
return activeSubscription;
}
}

return null;
}

public void Dispose()
{
_subscriptionClient?.Dispose();
Expand Down

0 comments on commit a632e6e

Please sign in to comment.