import { pipe } from 'fp-ts/lib/pipeable' ; import { left } from 'fp-ts/lib/Either' ; import { foldLeftRight , getPaths } from '@kbn/securitysolution-io-ts-utils' ; import { NonEmptyStringArray } from '.' ; describe ( 'non_empty_string_array' , ( ) => { test ( 'it should FAIL validation when given "null"' , ( ) => { const payload = null ; const decoded = NonEmptyStringArray . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ 'Invalid value "null" supplied to "NonEmptyStringArray"' , ] ) ; expect ( message . schema ) . toEqual ( { } ) ; } ) ; test ( 'it should FAIL validation when given "undefined"' , ( ) => { const payload = undefined ; const decoded = NonEmptyStringArray . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ 'Invalid value "undefined" supplied to "NonEmptyStringArray"' , ] ) ; expect ( message . schema ) . toEqual ( { } ) ; } ) ; test ( 'it should FAIL validation of single value of an empty string ""' , ( ) => { const payload = '' ; const decoded = NonEmptyStringArray . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ 'Invalid value "" supplied to "NonEmptyStringArray"' , ] ) ; expect ( message . schema ) . toEqual ( { } ) ; } ) ; test ( 'it should validate a single value of "a" into an array of size 1 of ["a"]' , ( ) => { const payload = 'a' ; const decoded = NonEmptyStringArray . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ; expect ( message . schema ) . toEqual ( [ 'a' ] ) ; } ) ; test ( 'it should validate 2 values of "a,b" into an array of size 2 of ["a", "b"]' , ( ) => { const payload = 'a,b' ; const decoded = NonEmptyStringArray . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ; expect ( message . schema ) . toEqual ( [ 'a' , 'b' ] ) ; } ) ; test ( 'it should validate 3 values of "a,b,c" into an array of size 3 of ["a", "b", "c"]' , ( ) => { const payload = 'a,b,c' ; const decoded = NonEmptyStringArray . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ; expect ( message . schema ) . toEqual ( [ 'a' , 'b' , 'c' ] ) ; } ) ; test ( 'it should FAIL validation of number' , ( ) => { const payload = 5 ; const decoded = NonEmptyStringArray . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ 'Invalid value "5" supplied to "NonEmptyStringArray"' , ] ) ; expect ( message . schema ) . toEqual ( { } ) ; } ) ; test ( 'it should validate 3 values of "   a,   b,    c  " into an array of size 3 of ["a", "b", "c"] even though they have spaces' , ( ) => { const payload = '   a,   b,    c  ' ; const decoded = NonEmptyStringArray . decode ( payload ) ; const message = pipe ( decoded , foldLeftRight ) ; expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ; expect ( message . schema ) . toEqual ( [ 'a' , 'b' , 'c' ] ) ; } ) ; } ) ;