From b1776240ea226039b517f8684cbc2cbbf61ea8b3 Mon Sep 17 00:00:00 2001 From: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com> Date: Wed, 13 Nov 2024 13:19:16 +0100 Subject: [PATCH] Pm 14861 vault items fail to load (#5031) * Resolve vault items fail to load * Add hasSubscription to metadata * Remove unused property * Fix the failing unit test --- .../Responses/OrganizationMetadataResponse.cs | 6 ++++-- src/Core/Billing/Models/OrganizationMetadata.cs | 3 ++- .../Implementations/OrganizationBillingService.cs | 15 +++++++++++---- .../OrganizationBillingControllerTests.cs | 3 ++- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs b/src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs index 960cd53ea..86cbdb92c 100644 --- a/src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs +++ b/src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs @@ -6,12 +6,14 @@ public record OrganizationMetadataResponse( bool IsEligibleForSelfHost, bool IsManaged, bool IsOnSecretsManagerStandalone, - bool IsSubscriptionUnpaid) + bool IsSubscriptionUnpaid, + bool HasSubscription) { public static OrganizationMetadataResponse From(OrganizationMetadata metadata) => new( metadata.IsEligibleForSelfHost, metadata.IsManaged, metadata.IsOnSecretsManagerStandalone, - metadata.IsSubscriptionUnpaid); + metadata.IsSubscriptionUnpaid, + metadata.HasSubscription); } diff --git a/src/Core/Billing/Models/OrganizationMetadata.cs b/src/Core/Billing/Models/OrganizationMetadata.cs index 138fb6aef..5bdb450dc 100644 --- a/src/Core/Billing/Models/OrganizationMetadata.cs +++ b/src/Core/Billing/Models/OrganizationMetadata.cs @@ -4,4 +4,5 @@ public record OrganizationMetadata( bool IsEligibleForSelfHost, bool IsManaged, bool IsOnSecretsManagerStandalone, - bool IsSubscriptionUnpaid); + bool IsSubscriptionUnpaid, + bool HasSubscription); diff --git a/src/Core/Billing/Services/Implementations/OrganizationBillingService.cs b/src/Core/Billing/Services/Implementations/OrganizationBillingService.cs index bdcf0fbf6..eadc58962 100644 --- a/src/Core/Billing/Services/Implementations/OrganizationBillingService.cs +++ b/src/Core/Billing/Services/Implementations/OrganizationBillingService.cs @@ -62,18 +62,25 @@ public class OrganizationBillingService( return null; } + var isEligibleForSelfHost = IsEligibleForSelfHost(organization); + var isManaged = organization.Status == OrganizationStatusType.Managed; + + if (string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId)) + { + return new OrganizationMetadata(isEligibleForSelfHost, isManaged, false, + false, false); + } + var customer = await subscriberService.GetCustomer(organization, new CustomerGetOptions { Expand = ["discount.coupon.applies_to"] }); var subscription = await subscriberService.GetSubscription(organization); - - var isEligibleForSelfHost = IsEligibleForSelfHost(organization); - var isManaged = organization.Status == OrganizationStatusType.Managed; var isOnSecretsManagerStandalone = IsOnSecretsManagerStandalone(organization, customer, subscription); var isSubscriptionUnpaid = IsSubscriptionUnpaid(subscription); + var hasSubscription = true; return new OrganizationMetadata(isEligibleForSelfHost, isManaged, isOnSecretsManagerStandalone, - isSubscriptionUnpaid); + isSubscriptionUnpaid, hasSubscription); } public async Task UpdatePaymentMethod( diff --git a/test/Api.Test/Billing/Controllers/OrganizationBillingControllerTests.cs b/test/Api.Test/Billing/Controllers/OrganizationBillingControllerTests.cs index 51e374fd5..703475fc5 100644 --- a/test/Api.Test/Billing/Controllers/OrganizationBillingControllerTests.cs +++ b/test/Api.Test/Billing/Controllers/OrganizationBillingControllerTests.cs @@ -52,7 +52,7 @@ public class OrganizationBillingControllerTests { sutProvider.GetDependency().OrganizationUser(organizationId).Returns(true); sutProvider.GetDependency().GetMetadata(organizationId) - .Returns(new OrganizationMetadata(true, true, true, true)); + .Returns(new OrganizationMetadata(true, true, true, true, true)); var result = await sutProvider.Sut.GetMetadataAsync(organizationId); @@ -64,6 +64,7 @@ public class OrganizationBillingControllerTests Assert.True(response.IsManaged); Assert.True(response.IsOnSecretsManagerStandalone); Assert.True(response.IsSubscriptionUnpaid); + Assert.True(response.HasSubscription); } [Theory, BitAutoData]