1+ import { ZodError as ZodErrorV3 } from "zod" ;
12import { ZodError , z } from "zod/v4" ;
23import { faker } from "@faker-js/faker" ;
3- import { IDSchema , RGBHexSchema , TimezoneSchema } from "@core/types/type.utils" ;
4+ import {
5+ IDSchema ,
6+ IDSchemaV4 ,
7+ RGBHexSchema ,
8+ TimezoneSchema ,
9+ } from "@core/types/type.utils" ;
410
511describe ( "IDSchema" , ( ) => {
612 it ( "validates a correct ObjectId string" , ( ) => {
@@ -13,6 +19,27 @@ describe("IDSchema", () => {
1319 const invalidId = faker . string . ulid ( ) ;
1420 const result = IDSchema . safeParse ( invalidId ) ;
1521
22+ expect ( result . success ) . toBe ( false ) ;
23+ expect ( result . error ) . toBeInstanceOf ( ZodErrorV3 ) ;
24+ expect ( result . error ?. errors ) . toEqual (
25+ expect . arrayContaining ( [
26+ expect . objectContaining ( { message : "Invalid id" } ) ,
27+ ] ) ,
28+ ) ;
29+ } ) ;
30+ } ) ;
31+
32+ describe ( "IDSchemaV4" , ( ) => {
33+ it ( "validates a correct ObjectId string" , ( ) => {
34+ const validId = faker . database . mongodbObjectId ( ) ;
35+
36+ expect ( IDSchemaV4 . safeParse ( validId ) . success ) . toBe ( true ) ;
37+ } ) ;
38+
39+ it ( "rejects an invalid ObjectId string" , ( ) => {
40+ const invalidId = faker . string . ulid ( ) ;
41+ const result = IDSchemaV4 . safeParse ( invalidId ) ;
42+
1643 expect ( result . success ) . toBe ( false ) ;
1744 expect ( result . error ) . toBeInstanceOf ( ZodError ) ;
1845 expect ( z . treeifyError ( result . error ! ) . errors ) . toEqual ( [ "Invalid id" ] ) ;
0 commit comments