mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 09:54:14 +00:00
Recheck the agreement before opening the store purchase sheet [skip ci]
This commit is contained in:
@@ -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']);
|
||||
});
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user