-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[DNM] Replace Hard-Coded Storage amount #17393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sbrown-livefront
wants to merge
22
commits into
main
Choose a base branch
from
billing/pm-27600/replace-hard-coded-pricing-data
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+331
โ23
Draft
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
640e3c8
feat(billing): add provided as a required property to premium response
sbrown-livefront 630a3c1
fix(billing): replace hard coded storage variables with retrieved plan
sbrown-livefront c21f28a
tests(billing): add tests to pricing-summary service
sbrown-livefront 93dc312
feat(billing): add optional property.
sbrown-livefront 05dde04
Merge branch 'main' into billing/pm-27600/replace-hard-coded-pricing-โฆ
sbrown-livefront 0e6b5bf
Merge branch 'main' into billing/pm-27600/replace-hard-coded-pricing-โฆ
sbrown-livefront 1ea8144
fix(billing): update storage logic
sbrown-livefront 1a71cb4
Merge branch 'main' into billing/pm-27600/replace-hard-coded-pricing-โฆ
sbrown-livefront 507525b
fix(billing): remove optional check
sbrown-livefront ee2b2ef
fix(billing): remove optionality
sbrown-livefront 380d8ef
fix(billing): remove optionality
sbrown-livefront 02dbda2
fix(billing): refactored storage calculation logic
sbrown-livefront 9937eef
feat(billing): add provided amounts to subscription-pricing-service
sbrown-livefront 629d107
fix(billing): update cloud premium component
sbrown-livefront 2afc885
fix(billing): update desktop premium component
sbrown-livefront f45d803
fix(billing): update org plans component
sbrown-livefront c72b8e4
Merge branch 'main' into billing/pm-27600/replace-hard-coded-pricing-โฆ
sbrown-livefront dfcd18c
Merge branch 'main' into billing/pm-27600/replace-hard-coded-pricing-โฆ
sbrown-livefront 125f30d
fix(billing) update stories and tests
sbrown-livefront 2353da4
fix(billing): update messages
sbrown-livefront 26b15ed
fix(billing): replace storage sizes
sbrown-livefront aae8c9c
Merge branch 'main' into billing/pm-27600/replace-hard-coded-pricing-โฆ
sbrown-livefront File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
232 changes: 232 additions & 0 deletions
232
apps/web/src/app/billing/services/pricing-summary.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; | ||
| import { PlanInterval, ProductTierType } from "@bitwarden/common/billing/enums"; | ||
| import { | ||
| BillingCustomerDiscount, | ||
| OrganizationSubscriptionResponse, | ||
| } from "@bitwarden/common/billing/models/response/organization-subscription.response"; | ||
| import { | ||
| PasswordManagerPlanFeaturesResponse, | ||
| PlanResponse, | ||
| SecretsManagerPlanFeaturesResponse, | ||
| } from "@bitwarden/common/billing/models/response/plan.response"; | ||
|
|
||
| import { PricingSummaryData } from "../shared/pricing-summary/pricing-summary.component"; | ||
|
|
||
| import { PricingSummaryService } from "./pricing-summary.service"; | ||
|
|
||
| describe("PricingSummaryService", () => { | ||
| let service: PricingSummaryService; | ||
|
|
||
| beforeEach(() => { | ||
| service = new PricingSummaryService(); | ||
| }); | ||
|
|
||
| describe("getPricingSummaryData", () => { | ||
| let mockPlan: PlanResponse; | ||
| let mockSub: OrganizationSubscriptionResponse; | ||
| let mockOrganization: Organization; | ||
|
|
||
| beforeEach(() => { | ||
| // Create mock plan with password manager features | ||
| mockPlan = { | ||
| productTier: ProductTierType.Teams, | ||
| PasswordManager: { | ||
| basePrice: 0, | ||
| seatPrice: 48, | ||
| baseSeats: 0, | ||
| hasAdditionalSeatsOption: true, | ||
| hasPremiumAccessOption: false, | ||
| premiumAccessOptionPrice: 0, | ||
| hasAdditionalStorageOption: true, | ||
| additionalStoragePricePerGb: 6, | ||
| baseStorageGb: 1, | ||
| } as PasswordManagerPlanFeaturesResponse, | ||
| SecretsManager: { | ||
| basePrice: 0, | ||
| seatPrice: 72, | ||
| baseSeats: 3, | ||
| hasAdditionalSeatsOption: true, | ||
| hasAdditionalServiceAccountOption: true, | ||
| additionalPricePerServiceAccount: 6, | ||
| baseServiceAccount: 50, | ||
| } as SecretsManagerPlanFeaturesResponse, | ||
| } as PlanResponse; | ||
|
|
||
| // Create mock subscription | ||
| mockSub = { | ||
| seats: 5, | ||
| smSeats: 5, | ||
| smServiceAccounts: 5, | ||
| maxStorageGb: 2, | ||
| customerDiscount: null, | ||
| } as OrganizationSubscriptionResponse; | ||
|
|
||
| // Create mock organization | ||
| mockOrganization = { | ||
| useSecretsManager: false, | ||
| } as Organization; | ||
| }); | ||
|
|
||
| it("should calculate pricing data correctly for password manager only", async () => { | ||
| const result = await service.getPricingSummaryData( | ||
| mockPlan, | ||
| mockSub, | ||
| mockOrganization, | ||
| PlanInterval.Monthly, | ||
| false, | ||
| 50, // estimatedTax | ||
| ); | ||
|
|
||
| expect(result).toEqual<PricingSummaryData>({ | ||
| selectedPlanInterval: "month", | ||
| passwordManagerSeats: 5, | ||
| passwordManagerSeatTotal: 240, // 48 * 5 | ||
| secretsManagerSeatTotal: 360, // 72 * 5 | ||
| additionalStorageTotal: 6, // 6 * (2 - 1) | ||
| additionalStoragePriceMonthly: 6, | ||
| additionalServiceAccountTotal: 0, // No additional service accounts (50 base vs 5 used) | ||
| totalAppliedDiscount: 0, | ||
| secretsManagerSubtotal: 360, // 0 + 360 + 0 | ||
| passwordManagerSubtotal: 246, // 0 + 240 + 6 | ||
| total: 296, // 246 + 50 (tax) - organization doesn't use secrets manager | ||
| organization: mockOrganization, | ||
| sub: mockSub, | ||
| selectedPlan: mockPlan, | ||
| selectedInterval: PlanInterval.Monthly, | ||
| discountPercentageFromSub: 0, | ||
| discountPercentage: 20, | ||
| acceptingSponsorship: false, | ||
| additionalServiceAccount: 0, // 50 - 5 = 45, which is > 0, so return 0 | ||
| storageGb: 1, | ||
| isSecretsManagerTrial: false, | ||
| estimatedTax: 50, | ||
| }); | ||
| }); | ||
|
|
||
| it("should calculate pricing data correctly with secrets manager enabled", async () => { | ||
| mockOrganization.useSecretsManager = true; | ||
|
|
||
| const result = await service.getPricingSummaryData( | ||
| mockPlan, | ||
| mockSub, | ||
| mockOrganization, | ||
| PlanInterval.Monthly, | ||
| false, | ||
| 50, | ||
| ); | ||
|
|
||
| expect(result.total).toBe(656); // passwordManagerSubtotal (246) + secretsManagerSubtotal (360) + tax (50) | ||
| }); | ||
|
|
||
| it("should handle secrets manager trial", async () => { | ||
| const result = await service.getPricingSummaryData( | ||
| mockPlan, | ||
| mockSub, | ||
| mockOrganization, | ||
| PlanInterval.Monthly, | ||
| true, // isSecretsManagerTrial | ||
| 50, | ||
| ); | ||
|
|
||
| expect(result.passwordManagerSeatTotal).toBe(0); // Should be 0 during trial | ||
| expect(result.discountPercentageFromSub).toBe(0); // Should be 0 during trial | ||
| }); | ||
|
|
||
| it("should handle premium access option", async () => { | ||
| mockPlan.PasswordManager.hasPremiumAccessOption = true; | ||
| mockPlan.PasswordManager.premiumAccessOptionPrice = 25; | ||
|
|
||
| const result = await service.getPricingSummaryData( | ||
| mockPlan, | ||
| mockSub, | ||
| mockOrganization, | ||
| PlanInterval.Monthly, | ||
| false, | ||
| 50, | ||
| ); | ||
|
|
||
| expect(result.passwordManagerSubtotal).toBe(271); // 0 + 240 + 6 + 25 | ||
| }); | ||
|
|
||
| it("should handle customer discount", async () => { | ||
| mockSub.customerDiscount = { | ||
| id: "discount1", | ||
| active: true, | ||
| percentOff: 10, | ||
| appliesTo: ["subscription"], | ||
| } as BillingCustomerDiscount; | ||
|
|
||
| const result = await service.getPricingSummaryData( | ||
| mockPlan, | ||
| mockSub, | ||
| mockOrganization, | ||
| PlanInterval.Monthly, | ||
| false, | ||
| 50, | ||
| ); | ||
|
|
||
| expect(result.discountPercentageFromSub).toBe(10); | ||
| }); | ||
|
|
||
| it("should handle zero storage calculation", async () => { | ||
| mockSub.maxStorageGb = 1; // Same as base storage | ||
|
|
||
| const result = await service.getPricingSummaryData( | ||
| mockPlan, | ||
| mockSub, | ||
| mockOrganization, | ||
| PlanInterval.Monthly, | ||
| false, | ||
| 50, | ||
| ); | ||
|
|
||
| expect(result.additionalStorageTotal).toBe(0); | ||
| expect(result.storageGb).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getAdditionalServiceAccount", () => { | ||
| let mockPlan: PlanResponse; | ||
| let mockSub: OrganizationSubscriptionResponse; | ||
|
|
||
| beforeEach(() => { | ||
| mockPlan = { | ||
| SecretsManager: { | ||
| baseServiceAccount: 50, | ||
| } as SecretsManagerPlanFeaturesResponse, | ||
| } as PlanResponse; | ||
|
|
||
| mockSub = { | ||
| smServiceAccounts: 55, | ||
| } as OrganizationSubscriptionResponse; | ||
| }); | ||
|
|
||
| it("should return additional service accounts when used exceeds base", () => { | ||
| const result = service.getAdditionalServiceAccount(mockPlan, mockSub); | ||
| expect(result).toBe(5); // Math.abs(50 - 55) = 5 | ||
| }); | ||
|
|
||
| it("should return 0 when used is less than or equal to base", () => { | ||
| mockSub.smServiceAccounts = 40; | ||
| const result = service.getAdditionalServiceAccount(mockPlan, mockSub); | ||
| expect(result).toBe(0); | ||
| }); | ||
|
|
||
| it("should return 0 when used equals base", () => { | ||
| mockSub.smServiceAccounts = 50; | ||
| const result = service.getAdditionalServiceAccount(mockPlan, mockSub); | ||
| expect(result).toBe(0); | ||
| }); | ||
|
|
||
| it("should return 0 when plan is null", () => { | ||
| const result = service.getAdditionalServiceAccount(null, mockSub); | ||
| expect(result).toBe(0); | ||
| }); | ||
|
|
||
| it("should return 0 when plan has no SecretsManager", () => { | ||
| mockPlan.SecretsManager = null; | ||
| const result = service.getAdditionalServiceAccount(mockPlan, mockSub); | ||
| expect(result).toBe(0); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ export class PricingSummaryService { | |
|
|
||
| const additionalStorageTotal = plan.PasswordManager?.hasAdditionalStorageOption | ||
| ? plan.PasswordManager.additionalStoragePricePerGb * | ||
| (sub?.maxStorageGb ? sub.maxStorageGb - 1 : 0) | ||
| (sub.maxStorageGb - plan.PasswordManager.baseStorageGb) | ||
sbrown-livefront marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| : 0; | ||
|
|
||
| const additionalStoragePriceMonthly = plan.PasswordManager?.additionalStoragePricePerGb || 0; | ||
|
|
@@ -66,7 +66,9 @@ export class PricingSummaryService { | |
| : (sub?.customerDiscount?.percentOff ?? 0); | ||
| const discountPercentage = 20; | ||
sbrown-livefront marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const acceptingSponsorship = false; | ||
sbrown-livefront marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const storageGb = sub?.maxStorageGb ? sub?.maxStorageGb - 1 : 0; | ||
| const storageGb = sub?.maxStorageGb | ||
| ? sub?.maxStorageGb - plan.PasswordManager.baseStorageGb | ||
| : 0; | ||
|
|
||
| const total = organization?.useSecretsManager | ||
| ? passwordManagerSubtotal + secretsManagerSubtotal + estimatedTax | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.