diff --git a/services/web/app/src/Features/Subscription/PlansHelper.mjs b/services/web/app/src/Features/Subscription/PlansHelper.mjs index fa310a9316..8647b35270 100644 --- a/services/web/app/src/Features/Subscription/PlansHelper.mjs +++ b/services/web/app/src/Features/Subscription/PlansHelper.mjs @@ -15,7 +15,20 @@ export function isProfessionalGroupPlan(subscription) { return subscription.groupPlan && isProfessional } +/** + * The per-month price shown when a plan or add-on is billed annually: the + * annual price divided by twelve, rounded up to the nearest 0.05 for a tidy + * display value. + * + * @param {number} annual + * @returns {number} + */ +export function roundedTwelfth(annual) { + return Math.round(Math.ceil(annual / 12 / 0.05) * 5) / 100 +} + export default { isProfessionalPlan, isProfessionalGroupPlan, + roundedTwelfth, } diff --git a/services/web/test/unit/src/Project/ProjectController.test.mjs b/services/web/test/unit/src/Project/ProjectController.test.mjs index 35ef2693e0..1e7cb8e496 100644 --- a/services/web/test/unit/src/Project/ProjectController.test.mjs +++ b/services/web/test/unit/src/Project/ProjectController.test.mjs @@ -43,7 +43,6 @@ describe('ProjectController', function () { collaborator: { monthly: 15, annual: 180, - annualDividedByTwelve: 15, }, }, }, @@ -1602,7 +1601,6 @@ describe('ProjectController', function () { assistant: { annual: 60, monthly: 5, - annualDividedByTwelve: 5, }, }, } diff --git a/services/web/test/unit/src/Subscription/PlansHelper.test.mjs b/services/web/test/unit/src/Subscription/PlansHelper.test.mjs new file mode 100644 index 0000000000..bcdee76b8e --- /dev/null +++ b/services/web/test/unit/src/Subscription/PlansHelper.test.mjs @@ -0,0 +1,18 @@ +import { describe, expect, it } from 'vitest' +import { roundedTwelfth } from '../../../../app/src/Features/Subscription/PlansHelper.mjs' + +describe('PlansHelper', function () { + describe('roundedTwelfth', function () { + it('divides by twelve when the result is already a multiple of 0.05', function () { + expect(roundedTwelfth(120)).to.equal(10) + expect(roundedTwelfth(180)).to.equal(15) + }) + + it('rounds up to the nearest 0.05 for display', function () { + // 263 / 12 = 21.9166… -> 21.95 + expect(roundedTwelfth(263)).to.equal(21.95) + // 505 / 12 = 42.0833… -> 42.1 + expect(roundedTwelfth(505)).to.equal(42.1) + }) + }) +})