125927e0e8
   TODO: 补充说明书链接 Reviewed-on: https://git.genarrative.world/git/GenarrativeAI/Genarrative/pulls/86 Co-authored-by: 王德宇 <kvtodev@outlook.com> Co-committed-by: 王德宇 <kvtodev@outlook.com>
151 lines
3.8 KiB
TypeScript
151 lines
3.8 KiB
TypeScript
import { expect, test } from 'vitest';
|
|
|
|
import type {
|
|
ProfileMembership,
|
|
ProfileRechargeProduct,
|
|
} from '../../../packages/shared/src/contracts/runtime';
|
|
import {
|
|
buildMembershipCycleLabel,
|
|
buildMembershipLabel,
|
|
buildRechargeProductValueLabel,
|
|
formatRechargePrice,
|
|
} from './rpgEntryProfileFundsViewModel';
|
|
|
|
function buildRechargeProduct(
|
|
overrides: Partial<ProfileRechargeProduct> = {},
|
|
): ProfileRechargeProduct {
|
|
return {
|
|
productId: 'points_60',
|
|
title: '60泥点',
|
|
priceCents: 600,
|
|
kind: 'points',
|
|
pointsAmount: 60,
|
|
bonusPoints: 0,
|
|
durationDays: 0,
|
|
badgeLabel: '',
|
|
description: '60泥点',
|
|
tier: 'normal',
|
|
membershipPeriodPoints: 0,
|
|
membershipPeriodDays: 0,
|
|
membershipQueueLimit: 0,
|
|
membershipDiscountBps: 0,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function buildMembership(
|
|
overrides: Partial<ProfileMembership> = {},
|
|
): ProfileMembership {
|
|
return {
|
|
status: 'normal',
|
|
tier: 'normal',
|
|
startedAt: null,
|
|
expiresAt: null,
|
|
updatedAt: null,
|
|
cycleStartedAt: null,
|
|
cycleResetsAt: null,
|
|
cycleGrantedPoints: 0,
|
|
cycleRemainingPoints: 0,
|
|
cyclePeriodDays: 30,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
test('profile funds ViewModel formats recharge product and membership labels', () => {
|
|
expect(formatRechargePrice(600)).toBe('¥6');
|
|
expect(formatRechargePrice(650)).toBe('¥6.50');
|
|
expect(buildRechargeProductValueLabel(buildRechargeProduct())).toBe('60泥点');
|
|
expect(
|
|
buildRechargeProductValueLabel(
|
|
buildRechargeProduct({
|
|
productId: 'points_180',
|
|
title: '180泥点',
|
|
priceCents: 1800,
|
|
pointsAmount: 180,
|
|
bonusPoints: 90,
|
|
badgeLabel: '首充加赠',
|
|
description: '首充加赠90泥点',
|
|
}),
|
|
),
|
|
).toBe('180+90泥点');
|
|
expect(
|
|
buildRechargeProductValueLabel(
|
|
buildRechargeProduct({
|
|
kind: 'membership',
|
|
pointsAmount: 0,
|
|
bonusPoints: 0,
|
|
durationDays: 30,
|
|
membershipPeriodPoints: 200,
|
|
membershipPeriodDays: 30,
|
|
}),
|
|
),
|
|
).toBe('每月200泥点');
|
|
expect(
|
|
buildRechargeProductValueLabel(
|
|
buildRechargeProduct({
|
|
kind: 'membership',
|
|
pointsAmount: 0,
|
|
bonusPoints: 0,
|
|
durationDays: 7,
|
|
membershipPeriodPoints: 80,
|
|
membershipPeriodDays: 7,
|
|
}),
|
|
),
|
|
).toBe('每周80泥点');
|
|
expect(
|
|
buildRechargeProductValueLabel(
|
|
buildRechargeProduct({
|
|
kind: 'membership',
|
|
pointsAmount: 0,
|
|
bonusPoints: 0,
|
|
durationDays: 14,
|
|
membershipPeriodPoints: 300,
|
|
membershipPeriodDays: 14,
|
|
}),
|
|
),
|
|
).toBe('每14天300泥点');
|
|
expect(
|
|
buildRechargeProductValueLabel(
|
|
buildRechargeProduct({
|
|
kind: 'membership',
|
|
pointsAmount: 0,
|
|
bonusPoints: 0,
|
|
durationDays: 90,
|
|
membershipPeriodPoints: 1200,
|
|
membershipPeriodDays: 90,
|
|
}),
|
|
),
|
|
).toBe('每90天1200泥点');
|
|
expect(buildMembershipLabel(buildMembership(), (value) => value)).toBe(
|
|
'普通用户',
|
|
);
|
|
expect(
|
|
buildMembershipLabel(
|
|
buildMembership({ status: 'active', expiresAt: null }),
|
|
(value) => value,
|
|
),
|
|
).toBe('会员已生效');
|
|
expect(
|
|
buildMembershipLabel(
|
|
buildMembership({
|
|
status: 'active',
|
|
expiresAt: '2026-06-03T00:00:00.000Z',
|
|
cycleResetsAt: '2026-06-02T00:00:00.000Z',
|
|
}),
|
|
(value) =>
|
|
value === '2026-06-03T00:00:00.000Z' ? '06/03 08:00' : '06/02 08:00',
|
|
),
|
|
).toBe('会员至 06/03 08:00 · 06/02 08:00重置');
|
|
expect(
|
|
buildMembershipCycleLabel(
|
|
buildMembership({
|
|
status: 'active',
|
|
tier: 'basic',
|
|
cycleRemainingPoints: 120,
|
|
cycleResetsAt: '2026-06-02T00:00:00.000Z',
|
|
}),
|
|
() => '06/02 08:00',
|
|
),
|
|
).toBe('本周期剩余 120 泥点 · 06/02 08:00重置');
|
|
});
|