@@ -358,15 +358,15 @@ describe('Validation', () => {
358358 expect ( data . founded ) . toBe ( 1999 )
359359 } )
360360
361- it ( 'rejects an un-coercible value for an optional number column' , ( ) => {
361+ it ( 'rejects an un-coercible value for an optional number column under `reject` ' , ( ) => {
362362 const data = { name : 'Acme' , founded : 2000 , age : 'unknown' }
363- const result = coerceRowToSchema ( data , schema )
363+ const result = coerceRowToSchema ( data , schema , 'reject' )
364364 expect ( result . valid ) . toBe ( false )
365365 } )
366366
367- it ( 'nulls an un-coercible optional value under the `null` policy ' , ( ) => {
367+ it ( 'nulls an un-coercible optional value by default ' , ( ) => {
368368 const data = { name : 'Acme' , founded : 2000 , age : 'unknown' }
369- const result = coerceRowToSchema ( data , schema , 'null' )
369+ const result = coerceRowToSchema ( data , schema )
370370 expect ( result . valid ) . toBe ( true )
371371 expect ( data . age ) . toBeNull ( )
372372 } )
@@ -393,12 +393,20 @@ describe('Validation', () => {
393393 expect ( data . active ) . toBe ( false )
394394 } )
395395
396- it ( 'refuses a bare epoch number, whose unit the value cannot state' , ( ) => {
396+ it ( 'refuses a bare epoch number under `reject` , whose unit the value cannot state' , ( ) => {
397397 const data = { name : 'Acme' , founded : 2000 , created : Date . parse ( '2024-01-15T00:00:00Z' ) }
398- const result = coerceRowToSchema ( data , schema )
398+ const result = coerceRowToSchema ( data , schema , 'reject' )
399399 expect ( result . valid ) . toBe ( false )
400400 } )
401401
402+ it ( 'coerces an epoch number to an ISO date string by default' , ( ) => {
403+ const epoch = Date . parse ( '2024-01-15T00:00:00Z' )
404+ const data = { name : 'Acme' , founded : 2000 , created : epoch }
405+ const result = coerceRowToSchema ( data , schema )
406+ expect ( result . valid ) . toBe ( true )
407+ expect ( data . created ) . toBe ( new Date ( epoch ) . toISOString ( ) )
408+ } )
409+
402410 it ( 'coerces a Date instance to an ISO date string' , ( ) => {
403411 const date = new Date ( '2024-01-15T00:00:00Z' )
404412 const data = { name : 'Acme' , founded : 2000 , created : date }
@@ -407,16 +415,16 @@ describe('Validation', () => {
407415 expect ( data . created ) . toBe ( date . toISOString ( ) )
408416 } )
409417
410- it ( 'nulls an out-of-range epoch number under the `null` policy without throwing' , ( ) => {
418+ it ( 'nulls an out-of-range epoch number without throwing' , ( ) => {
411419 const data = { name : 'Acme' , founded : 2000 , created : 1e20 }
412- const result = coerceRowToSchema ( data , schema , 'null' )
420+ const result = coerceRowToSchema ( data , schema )
413421 expect ( result . valid ) . toBe ( true )
414422 expect ( data . created ) . toBeNull ( )
415423 } )
416424
417- it ( 'nulls an invalid Date instance under the `null` policy without throwing' , ( ) => {
425+ it ( 'nulls an invalid Date instance without throwing' , ( ) => {
418426 const data = { name : 'Acme' , founded : 2000 , created : new Date ( 'not-a-date' ) }
419- const result = coerceRowToSchema ( data , schema , 'null' )
427+ const result = coerceRowToSchema ( data , schema )
420428 expect ( result . valid ) . toBe ( true )
421429 expect ( data . created ) . toBeNull ( )
422430 } )
@@ -451,15 +459,15 @@ describe('Validation', () => {
451459 expect ( patch . age ) . toBe ( 42 )
452460 } )
453461
454- it ( 'leaves an un-coercible optional patch value in place for downstream validation ' , ( ) => {
462+ it ( 'leaves an un-coercible optional patch value in place under `reject` ' , ( ) => {
455463 const patch : { age : unknown } = { age : 'nope' }
456- coerceRowValues ( patch as never , schema )
464+ coerceRowValues ( patch as never , schema , 'reject' )
457465 expect ( patch . age ) . toBe ( 'nope' )
458466 } )
459467
460- it ( 'nulls an un-coercible optional patch value under the `null` policy ' , ( ) => {
468+ it ( 'nulls an un-coercible optional patch value by default ' , ( ) => {
461469 const patch : { age : unknown } = { age : 'nope' }
462- coerceRowValues ( patch as never , schema , 'null' )
470+ coerceRowValues ( patch as never , schema )
463471 expect ( patch . age ) . toBeNull ( )
464472 } )
465473
@@ -533,15 +541,15 @@ describe('Validation', () => {
533541 expect ( patch . price ) . toBe ( 42 )
534542 } )
535543
536- it ( 'leaves an unreadable amount in place on an optional column so validation reports it ' , ( ) => {
544+ it ( 'leaves an unreadable amount in place on an optional column under `reject` ' , ( ) => {
537545 const patch : Record < string , unknown > = { price : 'ask sales' }
538- coerceRowValues ( patch as never , currencySchema )
546+ coerceRowValues ( patch as never , currencySchema , 'reject' )
539547 expect ( patch . price ) . toBe ( 'ask sales' )
540548 } )
541549
542- it ( 'nulls an unreadable amount on an optional column under the `null` policy ' , ( ) => {
550+ it ( 'nulls an unreadable amount on an optional column by default ' , ( ) => {
543551 const patch : Record < string , unknown > = { price : 'ask sales' }
544- coerceRowValues ( patch as never , currencySchema , 'null' )
552+ coerceRowValues ( patch as never , currencySchema )
545553 expect ( patch . price ) . toBeNull ( )
546554 } )
547555
0 commit comments