Highlight upgrades in package shop
This commit is contained in:
33
resources/js/admin/mobile/__tests__/packageShop.test.ts
Normal file
33
resources/js/admin/mobile/__tests__/packageShop.test.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { classifyPackageTier, selectRecommendedPackageId } from '../lib/packageShop';
|
||||
|
||||
describe('classifyPackageTier', () => {
|
||||
it('returns neutral when no active price', () => {
|
||||
expect(classifyPackageTier(100, 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 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('selectRecommendedPackageId', () => {
|
||||
const packages = [
|
||||
{ id: 1, price: 100, features: { advanced_analytics: false } },
|
||||
{ id: 2, price: 150, features: { advanced_analytics: true } },
|
||||
{ id: 3, price: 200, features: { advanced_analytics: true } },
|
||||
] as any;
|
||||
|
||||
it('returns null when no feature is requested', () => {
|
||||
expect(selectRecommendedPackageId(packages, null, 100)).toBeNull();
|
||||
});
|
||||
|
||||
it('selects the cheapest upgrade with the feature', () => {
|
||||
expect(selectRecommendedPackageId(packages, 'advanced_analytics', 120)).toBe(2);
|
||||
});
|
||||
|
||||
it('falls back to cheapest feature package if no upgrades exist', () => {
|
||||
expect(selectRecommendedPackageId(packages, 'advanced_analytics', 250)).toBe(2);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user