76 lines
1.9 KiB
TypeScript
76 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
applyEntitlementSnapshotToView,
|
|
toView,
|
|
} from "@/stores/user/user-machine.helpers";
|
|
|
|
describe("toView", () => {
|
|
it("fills optional user fields with stable defaults", () => {
|
|
expect(toView({ id: "user-1", username: "Luna" })).toEqual({
|
|
id: "user-1",
|
|
username: "Luna",
|
|
email: "",
|
|
avatarUrl: "",
|
|
intimacy: 0,
|
|
dolBalance: 0,
|
|
creditBalance: 0,
|
|
vipExpiresAt: null,
|
|
relationshipStage: "",
|
|
currentMood: "",
|
|
isGuest: false,
|
|
isVip: false,
|
|
voiceMinutesRemaining: 0,
|
|
});
|
|
});
|
|
|
|
it("preserves provided user fields", () => {
|
|
expect(
|
|
toView({
|
|
id: "user-2",
|
|
username: "Elio",
|
|
email: "elio@example.com",
|
|
avatarUrl: "https://example.com/avatar.png",
|
|
intimacy: 42,
|
|
dolBalance: 12,
|
|
creditBalance: 120,
|
|
vipExpiresAt: "2026-07-26T00:00:00+00:00",
|
|
relationshipStage: "close_friend",
|
|
currentMood: "playful",
|
|
isGuest: true,
|
|
isVip: true,
|
|
voiceMinutesRemaining: 30,
|
|
}),
|
|
).toEqual({
|
|
id: "user-2",
|
|
username: "Elio",
|
|
email: "elio@example.com",
|
|
avatarUrl: "https://example.com/avatar.png",
|
|
intimacy: 42,
|
|
dolBalance: 12,
|
|
creditBalance: 120,
|
|
vipExpiresAt: "2026-07-26T00:00:00+00:00",
|
|
relationshipStage: "close_friend",
|
|
currentMood: "playful",
|
|
isGuest: true,
|
|
isVip: true,
|
|
voiceMinutesRemaining: 30,
|
|
});
|
|
});
|
|
|
|
it("merges entitlement snapshot into user view fields", () => {
|
|
const user = toView({ id: "user-3", username: "Nora", isVip: false });
|
|
|
|
expect(
|
|
applyEntitlementSnapshotToView(user, {
|
|
isVip: true,
|
|
creditBalance: 120,
|
|
}),
|
|
).toMatchObject({
|
|
isVip: true,
|
|
creditBalance: 120,
|
|
dolBalance: 120,
|
|
});
|
|
});
|
|
});
|