@@ -10,7 +10,7 @@ import { AuthService } from '../../core/auth/auth.service';
1010import { CookieService } from '../../core/services/cookie.service' ;
1111import { getTestScheduler } from 'jasmine-marbles' ;
1212import { MetadataValue } from '../../core/shared/metadata.models' ;
13- import { cloneDeep } from 'lodash' ;
13+ import { clone , cloneDeep } from 'lodash' ;
1414import { ConfigurationDataService } from '../../core/data/configuration-data.service' ;
1515import { createFailedRemoteDataObject$ , createSuccessfulRemoteDataObject$ } from '../remote-data.utils' ;
1616import { ConfigurationProperty } from '../../core/shared/configuration-property.model' ;
@@ -34,9 +34,6 @@ describe('BrowserKlaroService', () => {
3434 values : values ,
3535 } ) ,
3636 } ) ;
37- const googleAnalyticsFilter =
38- ( bService : BrowserKlaroService ) =>
39- bService . klaroConfig . services . filter ( ( { name} ) => name === googleAnalytics ) ;
4037
4138 let mockConfig ;
4239 let appName ;
@@ -57,7 +54,7 @@ describe('BrowserKlaroService', () => {
5754 getAuthenticatedUserFromStore : observableOf ( user )
5855 } ) ;
5956 configurationDataService = createConfigSuccessSpy ( trackingIdTestValue ) ;
60- findByPropertyName = cloneDeep ( configurationDataService . findByPropertyName ) ;
57+ findByPropertyName = configurationDataService . findByPropertyName ;
6158 cookieService = jasmine . createSpyObj ( 'cookieService' , {
6259 get : '{%22token_item%22:true%2C%22impersonation%22:true%2C%22redirect%22:true%2C%22language%22:true%2C%22klaro%22:true%2C%22has_agreed_end_user%22:true%2C%22google-analytics%22:true}' ,
6360 set : ( ) => {
@@ -262,44 +259,48 @@ describe('BrowserKlaroService', () => {
262259 } ) ;
263260
264261 describe ( 'initialize google analytics configuration' , ( ) => {
262+ let GOOGLE_ANALYTICS_KEY ;
265263 beforeEach ( ( ) => {
264+ GOOGLE_ANALYTICS_KEY = clone ( ( service as any ) . GOOGLE_ANALYTICS_KEY ) ;
266265 configurationDataService . findByPropertyName = findByPropertyName ;
267266 spyOn ( ( service as any ) , 'getUser$' ) . and . returnValue ( observableOf ( user ) ) ;
268267 translateService . get . and . returnValue ( observableOf ( 'loading...' ) ) ;
269268 spyOn ( service , 'addAppMessages' ) ;
270269 spyOn ( ( service as any ) , 'initializeUser' ) ;
271270 spyOn ( service , 'translateConfiguration' ) ;
272271 } ) ;
272+ it ( 'should not filter any configuration' , ( ) => {
273+ const filteredConfig = ( service as any ) . filterConfigServices ( [ ] ) ;
274+ expect ( filteredConfig ) . toContain ( jasmine . objectContaining ( { name : googleAnalytics } ) ) ;
275+ } ) ;
273276 it ( 'should have been initialized with googleAnalytics' , ( ) => {
274- const filteredServices = googleAnalyticsFilter ( service ) ;
275- expect ( filteredServices . length ) . toBe ( 1 ) ;
277+ service . initialize ( ) ;
278+ expect ( service . klaroConfig . services ) . toContain ( jasmine . objectContaining ( { name : googleAnalytics } ) ) ;
276279 } ) ;
277- it ( 'should filter empty configuration' , ( ) => {
278- configurationDataService . findByPropertyName = jasmine . createSpy ( ) . and . returnValue (
280+ it ( 'should filter googleAnalytics when empty configuration is retrieved ' , ( ) => {
281+ configurationDataService . findByPropertyName = jasmine . createSpy ( ) . withArgs ( GOOGLE_ANALYTICS_KEY ) . and . returnValue (
279282 createSuccessfulRemoteDataObject$ ( {
280283 ... new ConfigurationProperty ( ) ,
281284 name : googleAnalytics ,
282285 values : [ ] ,
283286 } ) ) ;
287+
284288 service . initialize ( ) ;
285- const filteredServices = googleAnalyticsFilter ( service ) ;
286- expect ( filteredServices . length ) . toBe ( 0 ) ;
289+ expect ( service . klaroConfig . services ) . not . toContain ( jasmine . objectContaining ( { name : googleAnalytics } ) ) ;
287290 } ) ;
288- it ( 'should filter when error' , ( ) => {
289- configurationDataService . findByPropertyName = jasmine . createSpy ( ) . and . returnValue (
291+ it ( 'should filter googleAnalytics when an error occurs ' , ( ) => {
292+ configurationDataService . findByPropertyName = jasmine . createSpy ( ) . withArgs ( GOOGLE_ANALYTICS_KEY ) . and . returnValue (
290293 createFailedRemoteDataObject$ ( 'Erro while loading GA' )
291294 ) ;
292295 service . initialize ( ) ;
293- const filteredServices = googleAnalyticsFilter ( service ) ;
294- expect ( filteredServices . length ) . toBe ( 0 ) ;
296+ expect ( service . klaroConfig . services ) . not . toContain ( jasmine . objectContaining ( { name : googleAnalytics } ) ) ;
295297 } ) ;
296- it ( 'should filter when invalid payload' , ( ) => {
297- configurationDataService . findByPropertyName = jasmine . createSpy ( ) . and . returnValue (
298+ it ( 'should filter googleAnalytics when an invalid payload is retrieved ' , ( ) => {
299+ configurationDataService . findByPropertyName = jasmine . createSpy ( ) . withArgs ( GOOGLE_ANALYTICS_KEY ) . and . returnValue (
298300 createSuccessfulRemoteDataObject$ ( null )
299301 ) ;
300302 service . initialize ( ) ;
301- const filteredServices = googleAnalyticsFilter ( service ) ;
302- expect ( filteredServices . length ) . toBe ( 0 ) ;
303+ expect ( service . klaroConfig . services ) . not . toContain ( jasmine . objectContaining ( { name : googleAnalytics } ) ) ;
303304 } ) ;
304305 } ) ;
305306} ) ;
0 commit comments