Disallow downgrades in package shop
This commit is contained in:
@@ -1,14 +1,28 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { classifyPackageTier, selectRecommendedPackageId } from '../lib/packageShop';
|
||||
import { classifyPackageChange, selectRecommendedPackageId } from '../lib/packageShop';
|
||||
|
||||
describe('classifyPackageTier', () => {
|
||||
it('returns neutral when no active price', () => {
|
||||
expect(classifyPackageTier(100, null)).toEqual({ isUpgrade: false, isDowngrade: false });
|
||||
describe('classifyPackageChange', () => {
|
||||
const active = {
|
||||
id: 1,
|
||||
price: 200,
|
||||
max_photos: 100,
|
||||
max_guests: 50,
|
||||
gallery_days: 30,
|
||||
features: { advanced_analytics: false },
|
||||
} as any;
|
||||
|
||||
it('returns neutral when no active package', () => {
|
||||
expect(classifyPackageChange(active, null)).toEqual({ isUpgrade: false, isDowngrade: false });
|
||||
});
|
||||
|
||||
it('marks upgrades and downgrades by price', () => {
|
||||
expect(classifyPackageTier(150, 100)).toEqual({ isUpgrade: true, isDowngrade: false });
|
||||
expect(classifyPackageTier(80, 100)).toEqual({ isUpgrade: false, isDowngrade: true });
|
||||
it('marks upgrade when candidate adds features', () => {
|
||||
const candidate = { ...active, id: 2, price: 150, features: { advanced_analytics: true } } as any;
|
||||
expect(classifyPackageChange(candidate, active)).toEqual({ isUpgrade: true, isDowngrade: false });
|
||||
});
|
||||
|
||||
it('marks downgrade when candidate removes features or limits', () => {
|
||||
const candidate = { ...active, id: 3, max_photos: 50, features: { advanced_analytics: false } } as any;
|
||||
expect(classifyPackageChange(candidate, active)).toEqual({ isUpgrade: false, isDowngrade: true });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,10 +38,12 @@ describe('selectRecommendedPackageId', () => {
|
||||
});
|
||||
|
||||
it('selects the cheapest upgrade with the feature', () => {
|
||||
expect(selectRecommendedPackageId(packages, 'advanced_analytics', 120)).toBe(2);
|
||||
const active = { id: 10, price: 120, max_photos: 100, max_guests: 50, gallery_days: 30, features: {} } as any;
|
||||
expect(selectRecommendedPackageId(packages, 'advanced_analytics', active)).toBe(2);
|
||||
});
|
||||
|
||||
it('falls back to cheapest feature package if no upgrades exist', () => {
|
||||
expect(selectRecommendedPackageId(packages, 'advanced_analytics', 250)).toBe(2);
|
||||
const active = { id: 10, price: 250, max_photos: 999, max_guests: 999, gallery_days: 365, features: { advanced_analytics: true } } as any;
|
||||
expect(selectRecommendedPackageId(packages, 'advanced_analytics', active)).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user