import Immutable from 'immutable' ; import * as Data from './data' ; export const isNotMapException = `Immutable.Map should be a Immutable.Map, was given
"""
object
"""
[object Map]
"""
` ; export const isNotKeyException = 'key should be a string, was given 8 of type number' ; describe ( 'isMapElseThrow' , ( ) => { it ( 'return true if parameter is an Map' , ( ) => { const testMap = Immutable . Map < any , any > ( ) ; const test = Data . isMapElseThrow ( testMap ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'throw an error if parameter is not an Map' , ( ) => { const testMap = new Map ( ) ; expect ( ( ) => Data . isMapElseThrow ( testMap as any ) ) . toThrow ( isNotMapException ) ; } ) ; } ) ; describe ( 'isKeyElseThrow' , ( ) => { it ( 'return true if parameter key is a String' , ( ) => { const testString = 'a String' ; const test = Data . isKeyElseThrow ( testString ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'throw an error if parameter is not a String' , ( ) => { const testString = 8 ; expect ( ( ) => Data . isKeyElseThrow ( testString ) ) . toThrow ( isNotKeyException ) ; } ) ; } ) ; describe ( 'Data' , ( ) => { describe ( 'set' , ( ) => { it ( 'given a proper key and map update said map' , ( ) => { const key = 'key' ; const value = 'value' ; const map = Immutable . Map ( { withValue : 'value' , } ) ; const test = Data . set ( key , value , map ) ; expect ( test . get ( key ) ) . toEqual ( value ) ; } ) ; it ( 'given an improper key throw' , ( ) => { const key = 8 ; const value = 'value' ; const map = Immutable . Map ( { withValue : 'value' , } ) ; expect ( ( ) => Data . set ( key , value , map ) ) . toThrow ( isNotKeyException ) ; } ) ; it ( 'given an improper map throw' , ( ) => { const key = 'key' ; const value = 'value' ; const map = new Map ( ) ; expect ( ( ) => Data . set ( key , value , map as any ) ) . toThrow ( isNotMapException ) ; } ) ; } ) ; describe ( 'get' , ( ) => { it ( 'given a key and map containing said key return value' , ( ) => { const key = 'key' ; const value = 'value' ; const map = Immutable . Map ( { key : value , } ) ; const test = Data . get ( key , map ) ; expect ( test ) . toEqual ( value ) ; } ) ; it ( 'given a key and map not containing said key return undefined' , ( ) => { const key = 'anotherKey' ; const value = 'value' ; const map = Immutable . Map ( { key : value , } ) ; const test = Data . get ( key , map ) ; expect ( test ) . toEqual ( undefined ) ; } ) ; it ( 'given an improper key throw' , ( ) => { const key = 8 ; const map = Immutable . Map ( { withValue : 'value' , } ) ; expect ( ( ) => Data . get ( key , map ) ) . toThrow ( isNotKeyException ) ; } ) ; it ( 'given an improper map throw' , ( ) => { const key = 'key' ; const map = new Map ( ) ; expect ( ( ) => Data . get ( key , map as any ) ) . toThrow ( isNotMapException ) ; } ) ; } ) ; describe ( 'has' , ( ) => { it ( 'given a key and map containing said key return true' , ( ) => { const key = 'key' ; const value = 'value' ; const map = Immutable . Map ( { key : value , } ) ; const test = Data . has ( key , map ) ; expect ( test ) . toEqual ( true ) ; } ) ; it ( 'given a key and map not containing said key return false' , ( ) => { const key = 'anotherKey' ; const value = 'value' ; const map = Immutable . Map ( { key : value , } ) ; const test = Data . has ( key , map ) ; expect ( test ) . toEqual ( false ) ; } ) ; it ( 'given an improper key throw' , ( ) => { const key = 8 ; const map = Immutable . Map ( { withValue : 'value' , } ) ; expect ( ( ) => Data . has ( key , map ) ) . toThrow ( isNotKeyException ) ; } ) ; it ( 'given an improper map throw' , ( ) => { const key = 'key' ; const map = new Map ( ) ; expect ( ( ) => Data . has ( key , map as any ) ) . toThrow ( isNotMapException ) ; } ) ; } ) ; describe ( 'delete' , ( ) => { it ( 'given a key and map containing said key return map without this value' , ( ) => { const key = 'key' ; const value = 'value' ; const map = Immutable . Map ( { key : value , } ) ; const test = Data . deleteKey ( key , map ) ; expect ( test ) . toEqual ( Immutable . Map ( ) ) ; } ) ; it ( 'given a key and map not containing said key return same map' , ( ) => { const key = 'anotherKey' ; const value = 'value' ; const map = Immutable . Map ( { key : value , } ) ; const test = Data . deleteKey ( key , map ) ; expect ( test ) . toEqual ( map ) ; } ) ; it ( 'given an improper key throw' , ( ) => { const key = 8 ; const map = Immutable . Map ( { withValue : 'value' , } ) ; expect ( ( ) => Data . deleteKey ( key , map ) ) . toThrow ( isNotKeyException ) ; } ) ; it ( 'given an improper map throw' , ( ) => { const key = 'key' ; const map = new Map ( ) ; expect ( ( ) => Data . deleteKey ( key , map as any ) ) . toThrow ( isNotMapException ) ; } ) ; } ) ; } ) ;