@@ -250,16 +250,58 @@ describe('lib', () => {
250250} ) ;
251251
252252describe ( 'mergeMessages' , ( ) => {
253+ it ( 'should merge objects' , ( ) => {
254+ configure ( {
255+ loggingService : { logError : jest . fn ( ) } ,
256+ config : {
257+ ENVIRONMENT : 'production' ,
258+ LANGUAGE_PREFERENCE_COOKIE_NAME : 'yum' ,
259+ } ,
260+ messages : {
261+ ar : { message : 'ar-hah' } ,
262+ } ,
263+ } ) ;
264+ const result = mergeMessages ( { en : { foo : 'bar' } , de : { buh : 'baz' } , jp : { gah : 'wut' } } ) ;
265+ expect ( result ) . toEqual ( {
266+ ar : { message : 'ar-hah' } ,
267+ en : { foo : 'bar' } ,
268+ de : { buh : 'baz' } ,
269+ jp : { gah : 'wut' } ,
270+ } ) ;
271+ } ) ;
272+
253273 it ( 'should merge objects from an array' , ( ) => {
274+ configure ( {
275+ loggingService : { logError : jest . fn ( ) } ,
276+ config : {
277+ ENVIRONMENT : 'production' ,
278+ LANGUAGE_PREFERENCE_COOKIE_NAME : 'yum' ,
279+ } ,
280+ messages : {
281+ ar : { message : 'ar-hah' } ,
282+ } ,
283+ } ) ;
254284 const result = mergeMessages ( [ { foo : 'bar' } , { buh : 'baz' } , { gah : 'wut' } ] ) ;
255285 expect ( result ) . toEqual ( {
286+ ar : { message : 'ar-hah' } ,
256287 foo : 'bar' ,
257288 buh : 'baz' ,
258289 gah : 'wut' ,
259290 } ) ;
260291 } ) ;
261292
262293 it ( 'should merge nested objects from an array' , ( ) => {
294+ configure ( {
295+ loggingService : { logError : jest . fn ( ) } ,
296+ config : {
297+ ENVIRONMENT : 'production' ,
298+ LANGUAGE_PREFERENCE_COOKIE_NAME : 'yum' ,
299+ } ,
300+ messages : {
301+ en : { init : 'initial' } ,
302+ es : { init : 'inicial' } ,
303+ } ,
304+ } ) ;
263305 const messages = [
264306 {
265307 en : { hello : 'hello' } ,
@@ -274,19 +316,45 @@ describe('mergeMessages', () => {
274316 const result = mergeMessages ( messages ) ;
275317 expect ( result ) . toEqual ( {
276318 en : {
319+ init : 'initial' ,
277320 hello : 'hello' ,
278321 goodbye : 'goodbye' ,
279322 } ,
280323 es : {
324+ init : 'inicial' ,
281325 hello : 'hola' ,
282326 goodbye : 'adiós' ,
283327 } ,
284328 } ) ;
285329 } ) ;
286330
287331 it ( 'should return an empty object if no messages' , ( ) => {
332+ configure ( {
333+ loggingService : { logError : jest . fn ( ) } ,
334+ config : {
335+ ENVIRONMENT : 'production' ,
336+ LANGUAGE_PREFERENCE_COOKIE_NAME : 'yum' ,
337+ } ,
338+ messages : { } ,
339+ } ) ;
288340 expect ( mergeMessages ( undefined ) ) . toEqual ( { } ) ;
289341 expect ( mergeMessages ( null ) ) . toEqual ( { } ) ;
290342 expect ( mergeMessages ( [ ] ) ) . toEqual ( { } ) ;
343+ expect ( mergeMessages ( { } ) ) . toEqual ( { } ) ;
344+ } ) ;
345+
346+ it ( 'should return the original object if no messages' , ( ) => {
347+ configure ( {
348+ loggingService : { logError : jest . fn ( ) } ,
349+ config : {
350+ ENVIRONMENT : 'production' ,
351+ LANGUAGE_PREFERENCE_COOKIE_NAME : 'yum' ,
352+ } ,
353+ messages : { en : { hello : 'world ' } } ,
354+ } ) ;
355+ expect ( mergeMessages ( undefined ) ) . toEqual ( { en : { hello : 'world ' } } ) ;
356+ expect ( mergeMessages ( null ) ) . toEqual ( { en : { hello : 'world ' } } ) ;
357+ expect ( mergeMessages ( [ ] ) ) . toEqual ( { en : { hello : 'world ' } } ) ;
358+ expect ( mergeMessages ( { } ) ) . toEqual ( { en : { hello : 'world ' } } ) ;
291359 } ) ;
292360} ) ;
0 commit comments