diff --git a/apps/web/src/app/billing/individual/upgrade/premium-org-upgrade-payment/services/premium-org-upgrade.service.spec.ts b/apps/web/src/app/billing/individual/upgrade/premium-org-upgrade-payment/services/premium-org-upgrade.service.spec.ts index 8b0b2c712bb..ff6e337af7b 100644 --- a/apps/web/src/app/billing/individual/upgrade/premium-org-upgrade-payment/services/premium-org-upgrade.service.spec.ts +++ b/apps/web/src/app/billing/individual/upgrade/premium-org-upgrade-payment/services/premium-org-upgrade.service.spec.ts @@ -150,6 +150,18 @@ describe("PremiumOrgUpgradeService", () => { ).rejects.toThrow("Key generation failed"); }); + it("should throw an error if encrypted string is undefined", async () => { + keyService.makeOrgKey.mockResolvedValue([{ encryptedString: undefined }, "decrypted-key"]); + await expect( + service.upgradeToOrganization( + mockAccount, + "Test Organization", + mockPlanDetails, + mockBillingAddress, + ), + ).rejects.toThrow("Failed to generate encrypted organization key"); + }); + it("should propagate error if upgrade API call fails", async () => { accountBillingClient.upgradePremiumToOrganization.mockRejectedValue( new Error("API call failed"), diff --git a/apps/web/src/app/billing/individual/upgrade/premium-org-upgrade-payment/services/premium-org-upgrade.service.ts b/apps/web/src/app/billing/individual/upgrade/premium-org-upgrade-payment/services/premium-org-upgrade.service.ts index 9e7d7488b72..d14a09d4fd1 100644 --- a/apps/web/src/app/billing/individual/upgrade/premium-org-upgrade-payment/services/premium-org-upgrade.service.ts +++ b/apps/web/src/app/billing/individual/upgrade/premium-org-upgrade-payment/services/premium-org-upgrade.service.ts @@ -83,6 +83,10 @@ export class PremiumOrgUpgradeService { const tier: ProductTierType = this.ProductTierTypeFromSubscriptionTierId(planDetails.tier); const [encryptedKey] = await this.keyService.makeOrgKey(account.id); + if (!encryptedKey.encryptedString) { + throw new Error("Failed to generate encrypted organization key"); + } + await this.accountBillingClient.upgradePremiumToOrganization( organizationName, encryptedKey.encryptedString,