From a804ce9cab89cd92deac40c42858ed8c04ea1c8f Mon Sep 17 00:00:00 2001 From: Madeorsk Date: Sat, 28 Jun 2025 21:49:03 +0200 Subject: [PATCH] WIP --- tests/model/types/string.test.ts | 109 +++++++++++++++++++------------ 1 file changed, 69 insertions(+), 40 deletions(-) diff --git a/tests/model/types/string.test.ts b/tests/model/types/string.test.ts index 30b55a6..a17b2bb 100644 --- a/tests/model/types/string.test.ts +++ b/tests/model/types/string.test.ts @@ -2,24 +2,55 @@ import {describe, expect, test} from "vitest"; import {s, StringType} from "../../../src/library"; describe("string type", () => { - test("string type definition", () => { + test("definition", () => { const stringType = s.property.string(); expect(stringType.type).toBeInstanceOf(StringType); }); - test("string type functions", () => { + test("serialize", () => { expect(s.property.string().type.serialize("test")).toBe("test"); - expect(s.property.string().type.deserialize("test")).toBe("test"); - expect(s.property.string().type.serializeDiff("test")).toBe("test"); - expect(s.property.string().type.serialize(null)).toBe(null); - expect(s.property.string().type.deserialize(null)).toBe(null); - expect(s.property.string().type.serializeDiff(null)).toBe(null); - expect(s.property.string().type.serialize(undefined)).toBe(undefined); + + test("invalid parameters", () => { + const testDate = new Date(); + expect(s.property.string().type.serialize({} as any)).toBe( + "[object Object]", + ); + expect(s.property.string().type.serialize(2120 as any)).toBe("2120"); + expect(s.property.string().type.serialize(testDate as any)).toBe( + testDate.toString(), + ); + }); + }); + + test("deserialize", () => { + expect(s.property.string().type.deserialize("test")).toBe("test"); + expect(s.property.string().type.deserialize(null)).toBe(null); expect(s.property.string().type.deserialize(undefined)).toBe(undefined); + + test("invalid parameters", () => { + expect(s.property.string().type.deserialize({} as any)).toBe( + "[object Object]", + ); + expect(s.property.string().type.deserialize(2120 as any)).toBe("2120"); + }); + }); + + test("serializeDiff", () => { + expect(s.property.string().type.serializeDiff("test")).toBe("test"); + expect(s.property.string().type.serializeDiff(null)).toBe(null); expect(s.property.string().type.serializeDiff(undefined)).toBe(undefined); + test("invalid parameters", () => { + expect(s.property.string().type.serializeDiff({} as any)).toBe( + "[object Object]", + ); + expect(s.property.string().type.serializeDiff(2120 as any)).toBe("2120"); + }); + }); + + test("hasChanged", () => { expect(s.property.string().type.hasChanged("test", "test")).toBeFalsy(); expect(s.property.string().type.hasChanged(null, null)).toBeFalsy(); expect( @@ -32,6 +63,17 @@ describe("string type", () => { expect(s.property.string().type.hasChanged("test", null)).toBeTruthy(); expect(s.property.string().type.hasChanged("test", undefined)).toBeTruthy(); + test("invalid parameters", () => { + expect( + s.property.string().type.hasChanged({} as any, {} as any), + ).toBeTruthy(); + expect( + s.property.string().type.hasChanged(false as any, false as any), + ).toBeFalsy(); + }); + }); + + test("serializedHasChanged", () => { expect( s.property.string().type.serializedHasChanged("test", "test"), ).toBeFalsy(); @@ -60,10 +102,29 @@ describe("string type", () => { s.property.string().type.serializedHasChanged("test", undefined), ).toBeTruthy(); + test("invalid parameters", () => { + expect( + s.property.string().type.serializedHasChanged({} as any, {} as any), + ).toBeTruthy(); + expect( + s.property + .string() + .type.serializedHasChanged(false as any, false as any), + ).toBeFalsy(); + }); + }); + + test("resetDiff", () => { s.property.string().type.resetDiff("test"); s.property.string().type.resetDiff(undefined); s.property.string().type.resetDiff(null); + }); + test("clone", () => { + expect(s.property.string().type.clone({} as any)).toStrictEqual({}); + }); + + test("applyPatch", () => { expect(s.property.string().type.applyPatch("another", "test", false)).toBe( "test", ); @@ -78,36 +139,4 @@ describe("string type", () => { ).toBeUndefined(); expect(s.property.string().type.applyPatch("test", null, false)).toBeNull(); }); - - test("invalid parameters types", () => { - const testDate = new Date(); - expect(s.property.string().type.serialize({} as any)).toBe( - "[object Object]", - ); - expect(s.property.string().type.serialize(2120 as any)).toBe("2120"); - expect(s.property.string().type.serialize(testDate as any)).toBe( - testDate.toString(), - ); - expect(s.property.string().type.deserialize({} as any)).toBe( - "[object Object]", - ); - expect(s.property.string().type.deserialize(2120 as any)).toBe("2120"); - expect(s.property.string().type.serializeDiff({} as any)).toBe( - "[object Object]", - ); - expect(s.property.string().type.serializeDiff(2120 as any)).toBe("2120"); - expect( - s.property.string().type.hasChanged({} as any, {} as any), - ).toBeTruthy(); - expect( - s.property.string().type.hasChanged(false as any, false as any), - ).toBeFalsy(); - expect( - s.property.string().type.serializedHasChanged({} as any, {} as any), - ).toBeTruthy(); - expect( - s.property.string().type.serializedHasChanged(false as any, false as any), - ).toBeFalsy(); - expect(s.property.string().type.clone({} as any)).toStrictEqual({}); - }); });