feat(user): sync entitlement snapshot

This commit is contained in:
2026-06-29 10:37:37 +08:00
parent 455204e1e4
commit 58cd2a7545
22 changed files with 479 additions and 54 deletions
@@ -1,6 +1,9 @@
import { describe, expect, it } from "vitest";
import { toView } from "@/stores/user/user-machine.helpers";
import {
applyEntitlementSnapshotToView,
toView,
} from "@/stores/user/user-machine.helpers";
describe("toView", () => {
it("fills optional user fields with stable defaults", () => {
@@ -11,6 +14,8 @@ describe("toView", () => {
avatarUrl: "",
intimacy: 0,
dolBalance: 0,
creditBalance: 0,
vipExpiresAt: null,
relationshipStage: "",
currentMood: "",
isGuest: false,
@@ -28,6 +33,8 @@ describe("toView", () => {
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,
@@ -41,6 +48,8 @@ describe("toView", () => {
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,
@@ -48,4 +57,19 @@ describe("toView", () => {
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,
});
});
});