import { queryParamsFactory } from '../http.router.query.factory' ; describe ( '#queryParamsFactory' , ( ) => { test ( 'returns empty object when passed URL with no valid params' , ( ) => { const invalidURLS = [ '' , null , undefined ] ; invalidURLS . forEach ( url => { const params = queryParamsFactory ( url ) ; expect ( params ) . toEqual ( { } ) ; } ) ; } ) ; test ( 'returns empty string when no value for provided key' , ( ) => { const exampleURL = 'testParam' ; const expectedParamsObj = { testParam : '' } ; const params = queryParamsFactory ( exampleURL ) ; expect ( params ) . toEqual ( expectedParamsObj ) ; } ) ; test ( 'returns object with multiple keys' , ( ) => { const exampleURL = 'testParam=test&testParam2=test2' ; const expectedParamsObj = { testParam : 'test' , testParam2 : 'test2' } ; const params = queryParamsFactory ( exampleURL ) ; expect ( params ) . toEqual ( expectedParamsObj ) ; } ) ; test ( 'returns array when passed two times same parameter' , ( ) => { const exampleURL = 'testParam=test&testParam=123' ; const expectedParamsObj = { testParam : [ 'test' , '123' ] } ; const params = queryParamsFactory ( exampleURL ) ; expect ( params ) . toEqual ( expectedParamsObj ) ; } ) ; test ( 'returns nested object' , ( ) => { const exampleURL = 'testParam[testNested]=test' ; const expectedParamsObj = { testParam : { testNested : 'test' } } ; const params = queryParamsFactory ( exampleURL ) ; expect ( params ) . toEqual ( expectedParamsObj ) ; } ) ; test ( 'parses URL like parameter' , ( ) => { const exampleURL = 'user=test%40test.com' ; const expectedParamsObj = { user : 'test@test.com' } ; const params = queryParamsFactory ( exampleURL ) ; expect ( params ) . toEqual ( expectedParamsObj ) ; } ) ; } ) ;