refactor(data): replace schema classes with readonly models
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { UserEntitlements } from "@/data/schemas/user";
|
||||
import { User } from "@/data/schemas/user/user";
|
||||
import { UserEntitlementsSchema } from "@/data/schemas/user";
|
||||
import { UserSchema } from "@/data/schemas/user/user";
|
||||
|
||||
describe("User", () => {
|
||||
it("parses the latest backend user payload", () => {
|
||||
const user = User.fromJson({
|
||||
const user = UserSchema.parse({
|
||||
id: "d7bb2b3d-e9c5-474c-85fe-f503048f30dd",
|
||||
username: "guest_bbc90a38",
|
||||
email: "device_bbc90a38b996187348f54cf2cb0b789e@guest.local",
|
||||
@@ -45,7 +45,7 @@ describe("User", () => {
|
||||
lastMessageAt: "2026-06-24T11:00:23.156561+00:00",
|
||||
});
|
||||
|
||||
expect(user.toJson()).toEqual({
|
||||
expect(user).toEqual({
|
||||
id: "d7bb2b3d-e9c5-474c-85fe-f503048f30dd",
|
||||
username: "guest_bbc90a38",
|
||||
email: "device_bbc90a38b996187348f54cf2cb0b789e@guest.local",
|
||||
@@ -75,17 +75,17 @@ describe("User", () => {
|
||||
lastMessageAt: "2026-06-24T11:00:23.156561+00:00",
|
||||
});
|
||||
|
||||
expect("dailyQuotas" in user.toJson()).toBe(false);
|
||||
expect("dailyQuotas" in user).toBe(false);
|
||||
});
|
||||
|
||||
it("defaults nullable nested user fields through schema helpers", () => {
|
||||
const user = User.fromJson({
|
||||
const user = UserSchema.parse({
|
||||
id: "user-1",
|
||||
username: "guest_user",
|
||||
personalityTraits: null,
|
||||
});
|
||||
|
||||
expect(user.personalityTraits.toJson()).toEqual({
|
||||
expect(user.personalityTraits).toEqual({
|
||||
caring: 0.5,
|
||||
playful: 0.5,
|
||||
serious: 0.5,
|
||||
@@ -95,7 +95,7 @@ describe("User", () => {
|
||||
});
|
||||
|
||||
it("parses the latest backend entitlements payload", () => {
|
||||
const entitlements = UserEntitlements.fromJson({
|
||||
const entitlements = UserEntitlementsSchema.parse({
|
||||
userId: "user-1",
|
||||
isGuest: false,
|
||||
isVip: true,
|
||||
@@ -142,7 +142,7 @@ describe("User", () => {
|
||||
});
|
||||
|
||||
it("defaults nullable entitlement sections through schema helpers", () => {
|
||||
const entitlements = UserEntitlements.fromJson({
|
||||
const entitlements = UserEntitlementsSchema.parse({
|
||||
userId: "user-1",
|
||||
policy: null,
|
||||
costs: null,
|
||||
|
||||
Reference in New Issue
Block a user