Files
memecoin-botV2/.pnpm-store/v10/files/d8/c5677ac11e0d35d662ef9f9c8903c099ac109d13e4bb9907dcbd0b06d8eaebd00c9869646f24d4a4cfbb35551a5ddee7471d0048850800ff52df9a56e6794e

63 lines
1.6 KiB
Plaintext

import { expect, test } from "vitest";
import * as z from "zod/v4";
const beforeBenchmarkDate = new Date(Date.UTC(2022, 10, 4));
const benchmarkDate = new Date(Date.UTC(2022, 10, 5));
const afterBenchmarkDate = new Date(Date.UTC(2022, 10, 6));
const minCheck = z.date().min(benchmarkDate);
const maxCheck = z.date().max(benchmarkDate);
test("passing validations", () => {
minCheck.parse(benchmarkDate);
minCheck.parse(afterBenchmarkDate);
maxCheck.parse(benchmarkDate);
maxCheck.parse(beforeBenchmarkDate);
});
test("date min", () => {
const result = minCheck.safeParse(beforeBenchmarkDate);
expect(result.success).toEqual(false);
expect(result.error!.issues).toMatchInlineSnapshot(`
[
{
"code": "too_small",
"inclusive": true,
"message": "Too small: expected date to be >=1667606400000",
"minimum": 1667606400000,
"origin": "date",
"path": [],
},
]
`);
});
test("date max", () => {
const result = maxCheck.safeParse(afterBenchmarkDate);
expect(result.success).toEqual(false);
expect(result.error!.issues).toMatchInlineSnapshot(`
[
{
"code": "too_big",
"inclusive": true,
"maximum": 1667606400000,
"message": "Too big: expected date to be <=1667606400000",
"origin": "date",
"path": [],
},
]
`);
});
test("min max getters", () => {
expect(minCheck.minDate).toEqual(benchmarkDate);
expect(minCheck.min(afterBenchmarkDate).minDate).toEqual(afterBenchmarkDate);
expect(maxCheck.maxDate).toEqual(benchmarkDate);
expect(maxCheck.max(beforeBenchmarkDate).maxDate).toEqual(beforeBenchmarkDate);
});