Recheck the agreement before opening the store purchase sheet [skip ci]

This commit is contained in:
Maurice
2026-12-02 16:33:34 +01:00
parent bf6a66d52c
commit e54f954f31
4 changed files with 164 additions and 13 deletions
+16 -1
View File
@@ -1,5 +1,11 @@
import { describe, expect, it } from 'vitest';
import { isNewCloudPlan, opensSoon, planForUnclaimedPurchase, refundedBeforeOpening } from './cloudOrders';
import {
isNewCloudPlan,
matchesPurchaseAgreement,
opensSoon,
planForUnclaimedPurchase,
refundedBeforeOpening,
} from './cloudOrders';
describe('opensSoon', () => {
const base = { available: true, closed: true, sandbox: false, onPlay: false };
@@ -35,6 +41,15 @@ describe('refundedBeforeOpening', () => {
});
describe('Cloud catalog and purchase recovery', () => {
it('only carries the accepted agreement into a new purchase if the current version and text still match', () => {
const accepted = { version: '2026-12-01', text: 'Agreed changes' };
expect(matchesPurchaseAgreement(accepted, { ...accepted })).toBe(true);
expect(matchesPurchaseAgreement(accepted, null)).toBe(false);
expect(matchesPurchaseAgreement(null, accepted)).toBe(false);
expect(matchesPurchaseAgreement(accepted, { ...accepted, version: '2026-12-02' })).toBe(false);
expect(matchesPurchaseAgreement(accepted, { ...accepted, text: 'Changed conditions' })).toBe(false);
});
it('only offers Start and Plus even when the server still lists retired plans', () => {
expect(['start', 'basis', 'plus', 'pro'].filter(isNewCloudPlan)).toEqual(['start', 'plus']);
});
+15
View File
@@ -29,6 +29,21 @@ export function isNewCloudPlan(id: string): boolean {
return id === 'start' || id === 'plus';
}
export interface CloudPurchaseAgreement {
version: string;
text: string;
}
/** Recheck the agreement before opening the store sheet. No agreement means no new purchase. */
export function matchesPurchaseAgreement(
accepted: CloudPurchaseAgreement | null,
current: CloudPurchaseAgreement | null
): boolean {
return (
accepted !== null && current !== null && accepted.version === current.version && accepted.text === current.text
);
}
const PLAN_NAMES: Record<string, string> = { start: 'Start', basis: 'Basis', plus: 'Plus', pro: 'Pro' };
/** A verified purchase can predate the current offer and still need its instance set up. */