@@ -3,6 +3,7 @@ import { z } from "zod";
33import {
44 StarknetAddress ,
55 AgreementId ,
6+ IdempotencyKeySchema ,
67 parsePagination ,
78 MAX_PAGE_LIMIT ,
89 DEFAULT_PAGE_LIMIT ,
@@ -25,6 +26,20 @@ import {
2526} from "./validation" ;
2627import type { ValidationErrorMetric } from "./validation" ;
2728
29+ describe ( "IdempotencyKeySchema" , ( ) => {
30+ it ( "accepts bounded ASCII keys" , ( ) => {
31+ expect ( IdempotencyKeySchema . parse ( "checkout_2026-07-30" ) ) . toBe ( "checkout_2026-07-30" ) ;
32+ expect ( IdempotencyKeySchema . parse ( "a" . repeat ( 255 ) ) ) . toHaveLength ( 255 ) ;
33+ } ) ;
34+
35+ it . each ( [ "" , " " , "key with spaces" , "key/slash" , "a" . repeat ( 256 ) ] ) (
36+ "rejects unsafe key %j" ,
37+ ( value ) => {
38+ expect ( IdempotencyKeySchema . safeParse ( value ) . success ) . toBe ( false ) ;
39+ } ,
40+ ) ;
41+ } ) ;
42+
2843// --------------------------------------------------------------------------
2944// ValidationError
3045// --------------------------------------------------------------------------
@@ -41,9 +56,7 @@ describe("ValidationError", () => {
4156 expect ( err . name ) . toBe ( "ValidationError" ) ;
4257 expect ( err . validator ) . toBe ( "test" ) ;
4358 expect ( err . message ) . toBe ( "something went wrong" ) ;
44- expect ( err . issues ) . toEqual ( [
45- { path : [ "name" ] , message : "too short" , code : "too_small" } ,
46- ] ) ;
59+ expect ( err . issues ) . toEqual ( [ { path : [ "name" ] , message : "too short" , code : "too_small" } ] ) ;
4760 expect ( err . input ) . toBe ( "ab" ) ;
4861 } ) ;
4962
@@ -802,8 +815,8 @@ describe("formatValidationError", () => {
802815// ---- mapZodError ----
803816
804817describe ( "mapZodError" , ( ) => {
805- it ( "returns custom code for checksum fail" , ( ) => {
806- try {
818+ it ( "returns custom code for checksum fail" , ( ) => {
819+ try {
807820 StarknetAddress . parse ( "0x4718F5a0FC34Cc1AF16A1cdee98ffB20C31f5cd61d6ab07201858f4287c938d" ) ;
808821 } catch ( e ) {
809822 const mapped = mapZodError ( e ) ;
0 commit comments