44 StoreModule ,
55} from '@ngrx/store' ;
66import { MockStore } from '@ngrx/store/testing' ;
7+ import { of } from 'rxjs' ;
78
89import {
910 appReducers ,
@@ -13,7 +14,10 @@ import {
1314import { UUIDService } from '../core/shared/uuid.service' ;
1415import { CookieServiceMock } from '../shared/mocks/cookie.service.mock' ;
1516import { SetCorrelationIdAction } from './correlation-id.actions' ;
16- import { CorrelationIdService } from './correlation-id.service' ;
17+ import {
18+ CORRELATION_ID_COOKIE ,
19+ CorrelationIdService ,
20+ } from './correlation-id.service' ;
1721
1822describe ( 'CorrelationIdService' , ( ) => {
1923 let service : CorrelationIdService ;
@@ -34,7 +38,13 @@ describe('CorrelationIdService', () => {
3438 cookieService = new CookieServiceMock ( ) ;
3539 uuidService = new UUIDService ( ) ;
3640 store = TestBed . inject ( Store ) as MockStore < AppState > ;
37- service = new CorrelationIdService ( cookieService , uuidService , store ) ;
41+ const mockOrejimeService = {
42+ getSavedPreferences : ( ) => of ( { CORRELATION_ID_OREJIME_KEY : true } ) ,
43+ initialize : jasmine . createSpy ( 'initialize' ) ,
44+ showSettings : jasmine . createSpy ( 'showSettings' ) ,
45+ } ;
46+
47+ service = new CorrelationIdService ( cookieService , uuidService , store , mockOrejimeService , { nativeWindow : undefined } ) ;
3848 } ) ;
3949
4050 describe ( 'getCorrelationId' , ( ) => {
@@ -46,45 +56,45 @@ describe('CorrelationIdService', () => {
4656 } ) ;
4757
4858
49- describe ( 'initCorrelationId ' , ( ) => {
59+ describe ( 'setCorrelationId ' , ( ) => {
5060 const cookieCID = 'cookie CID' ;
5161 const storeCID = 'store CID' ;
5262
5363 it ( 'should set cookie and store values to a newly generated value if neither ex' , ( ) => {
54- service . initCorrelationId ( ) ;
64+ service . setCorrelationId ( ) ;
5565
56- expect ( cookieService . get ( 'CORRELATION-ID' ) ) . toBeTruthy ( ) ;
66+ expect ( cookieService . get ( CORRELATION_ID_COOKIE ) ) . toBeTruthy ( ) ;
5767 expect ( service . getCorrelationId ( ) ) . toBeTruthy ( ) ;
58- expect ( cookieService . get ( 'CORRELATION-ID' ) ) . toEqual ( service . getCorrelationId ( ) ) ;
68+ expect ( cookieService . get ( CORRELATION_ID_COOKIE ) ) . toEqual ( service . getCorrelationId ( ) ) ;
5969 } ) ;
6070
6171 it ( 'should set store value to cookie value if present' , ( ) => {
6272 expect ( service . getCorrelationId ( ) ) . toBe ( null ) ;
6373
64- cookieService . set ( 'CORRELATION-ID' , cookieCID ) ;
74+ cookieService . set ( CORRELATION_ID_COOKIE , cookieCID ) ;
6575
66- service . initCorrelationId ( ) ;
76+ service . setCorrelationId ( ) ;
6777
68- expect ( cookieService . get ( 'CORRELATION-ID' ) ) . toBe ( cookieCID ) ;
78+ expect ( cookieService . get ( CORRELATION_ID_COOKIE ) ) . toBe ( cookieCID ) ;
6979 expect ( service . getCorrelationId ( ) ) . toBe ( cookieCID ) ;
7080 } ) ;
7181
7282 it ( 'should set cookie value to store value if present' , ( ) => {
7383 store . dispatch ( new SetCorrelationIdAction ( storeCID ) ) ;
7484
75- service . initCorrelationId ( ) ;
85+ service . setCorrelationId ( ) ;
7686
77- expect ( cookieService . get ( 'CORRELATION-ID' ) ) . toBe ( storeCID ) ;
87+ expect ( cookieService . get ( CORRELATION_ID_COOKIE ) ) . toBe ( storeCID ) ;
7888 expect ( service . getCorrelationId ( ) ) . toBe ( storeCID ) ;
7989 } ) ;
8090
8191 it ( 'should set store value to cookie value if both are present' , ( ) => {
82- cookieService . set ( 'CORRELATION-ID' , cookieCID ) ;
92+ cookieService . set ( CORRELATION_ID_COOKIE , cookieCID ) ;
8393 store . dispatch ( new SetCorrelationIdAction ( storeCID ) ) ;
8494
85- service . initCorrelationId ( ) ;
95+ service . setCorrelationId ( ) ;
8696
87- expect ( cookieService . get ( 'CORRELATION-ID' ) ) . toBe ( cookieCID ) ;
97+ expect ( cookieService . get ( CORRELATION_ID_COOKIE ) ) . toBe ( cookieCID ) ;
8898 expect ( service . getCorrelationId ( ) ) . toBe ( cookieCID ) ;
8999 } ) ;
90100 } ) ;
0 commit comments