mirror of
https://github.com/bitwarden/browser
synced 2026-02-11 05:53:42 +00:00
fix(billing): Ensure encrypted org key is present during upgrade
This commit is contained in:
@@ -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"),
|
||||
|
||||
@@ -83,6 +83,10 @@ export class PremiumOrgUpgradeService {
|
||||
const tier: ProductTierType = this.ProductTierTypeFromSubscriptionTierId(planDetails.tier);
|
||||
const [encryptedKey] = await this.keyService.makeOrgKey<OrgKey>(account.id);
|
||||
|
||||
if (!encryptedKey.encryptedString) {
|
||||
throw new Error("Failed to generate encrypted organization key");
|
||||
}
|
||||
|
||||
await this.accountBillingClient.upgradePremiumToOrganization(
|
||||
organizationName,
|
||||
encryptedKey.encryptedString,
|
||||
|
||||
Reference in New Issue
Block a user