import { expect, test } from "vitest" import { excludeFields, includeFields, objectDateFieldsToNumber } from "#Source/basic/object.ts" test("includeFields picks specified keys", () => { expect(includeFields({ a: 1, b: 2, c: 3 }, ["a", "c"])).toEqual({ a: 1, c: 3 }) // @ts-expect-error - Testing behavior with null input expect(includeFields(null, ["a"])).toEqual({}) }) test("excludeFields omits specified keys", () => { expect(excludeFields({ a: 1, b: 2 }, ["b"])).toEqual({ a: 1 }) // @ts-expect-error - Testing behavior with undefined input expect(excludeFields(undefined, ["a"])).toEqual({}) }) test("objectDateFieldsToNumber converts top-level Date fields", () => { const createdAt = new Date("2024-01-02T03:04:05.678Z") const updatedAt = new Date("2024-02-03T04:05:06.789Z") const nestedDate = new Date("2024-03-04T05:06:07.890Z") const source = { id: "x-1", createdAt, updatedAt, nested: { occurredAt: nestedDate, }, optional: undefined as Date | undefined, nullable: null as Date | null, } const result = objectDateFieldsToNumber(source) expect(result).toEqual({ id: "x-1", createdAt: createdAt.getTime(), updatedAt: updatedAt.getTime(), nested: { occurredAt: nestedDate, }, optional: undefined, nullable: null, }) expect(result).toBe(source) })