refactor(data): replace schema classes with readonly models

This commit is contained in:
2026-07-17 13:21:40 +08:00
parent 3437312167
commit ae97366a4a
103 changed files with 1220 additions and 2117 deletions
@@ -2,12 +2,12 @@ import { act } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { PaymentPlan } from "@/data/schemas/payment";
import { PaymentPlan, PaymentPlanSchema } from "@/data/schemas/payment";
import { behaviorAnalytics } from "@/lib/analytics";
import { usePaymentPlanAnalytics } from "../use-payment-plan-analytics";
const firstPlan = PaymentPlan.from({
const firstPlan = PaymentPlanSchema.parse({
planId: "plan-1",
planName: "Plan One",
orderType: "dol",
@@ -18,7 +18,7 @@ const firstPlan = PaymentPlan.from({
originalAmountCents: null,
currency: "USD",
});
const secondPlan = PaymentPlan.from({
const secondPlan = PaymentPlanSchema.parse({
planId: "plan-2",
planName: "Plan Two",
orderType: "dol",
@@ -43,8 +43,9 @@ describe("usePaymentPlanAnalytics", () => {
let root: Root;
beforeEach(() => {
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean })
.IS_REACT_ACT_ENVIRONMENT = true;
(
globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
).IS_REACT_ACT_ENVIRONMENT = true;
container = document.createElement("div");
document.body.appendChild(container);
root = createRoot(container);
@@ -1,16 +1,18 @@
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { PrivateAlbum } from "@/data/schemas/private-room";
import {
PrivateAlbumSchema,
type PrivateAlbum,
type PrivateAlbumInput,
} from "@/data/schemas/private-room";
import { PrivateAlbumCard } from "../private-album-card";
const COVER_URL = "/images/private-room/banner.png";
function makeAlbum(
overrides: Partial<Parameters<typeof PrivateAlbum.from>[0]> = {},
): PrivateAlbum {
return PrivateAlbum.from({
function makeAlbum(overrides: Partial<PrivateAlbumInput> = {}): PrivateAlbum {
return PrivateAlbumSchema.parse({
albumId: "album-1",
title: "Private morning",
content: "A quiet morning by the water.",
@@ -61,9 +63,7 @@ describe("PrivateAlbumCard", () => {
expect(html).toContain("8 photos");
expect(html).toContain("A quiet morning by the water.");
expect(html).toContain('aria-label="Open 8 private album photos"');
expect(html).toContain(
'data-analytics-key="private_album.open_gallery"',
);
expect(html).toContain('data-analytics-key="private_album.open_gallery"');
});
it("uses the backend first image as the locked cover", () => {
@@ -1,6 +1,10 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { PaymentPlan } from "@/data/schemas/payment";
import {
PaymentPlanSchema,
type PaymentPlan,
type PaymentPlanInput,
} from "@/data/schemas/payment";
import {
canChooseSubscriptionPayChannel,
@@ -13,10 +17,8 @@ import {
toVipOfferPlanViews,
} from "../subscription-screen.helpers";
function makePlan(
overrides: Partial<Parameters<typeof PaymentPlan.from>[0]>,
): PaymentPlan {
return PaymentPlan.from({
function makePlan(overrides: Partial<PaymentPlanInput>): PaymentPlan {
return PaymentPlanSchema.parse({
planId: "plan",
planName: "Plan",
orderType: "vip_monthly",
@@ -138,7 +140,9 @@ describe("subscription screen helpers", () => {
originalPrice: "",
},
],
coinPlans: [{ id: "coin_1000", coins: 1000, price: "9.90", currency: "US$" }],
coinPlans: [
{ id: "coin_1000", coins: 1000, price: "9.90", currency: "US$" },
],
});
expect(selected?.id).toBe("coin_1000");
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { PaymentPlan } from "@/data/schemas/payment";
import { PaymentPlan, PaymentPlanSchema } from "@/data/schemas/payment";
import type { PaymentPlanInput } from "@/data/schemas/payment/payment_plan";
import {
@@ -10,7 +10,7 @@ import {
} from "../tip-screen.helpers";
function makePlan(input: Partial<PaymentPlanInput>): PaymentPlan {
return PaymentPlan.from({
return PaymentPlanSchema.parse({
planId: "coins_100",
planName: "Coins",
orderType: "dol",