[CST-6782] Fixed failing tests

This commit is contained in:
Vincenzo Mecca
2022-09-19 16:26:31 +02:00
parent 36b8b8b61b
commit 4484c3ebbc
2 changed files with 54 additions and 13 deletions

View File

@@ -262,8 +262,10 @@ describe('BrowserKlaroService', () => {
describe('initialize google analytics configuration', () => {
let GOOGLE_ANALYTICS_KEY;
let REGISTRATION_VERIFICATION_ENABLED_KEY;
beforeEach(() => {
GOOGLE_ANALYTICS_KEY = clone((service as any).GOOGLE_ANALYTICS_KEY);
REGISTRATION_VERIFICATION_ENABLED_KEY = clone((service as any).REGISTRATION_VERIFICATION_ENABLED_KEY);
spyOn((service as any), 'getUser$').and.returnValue(observableOf(user));
translateService.get.and.returnValue(observableOf('loading...'));
spyOn(service, 'addAppMessages');
@@ -292,27 +294,64 @@ describe('BrowserKlaroService', () => {
expect(service.klaroConfig.services).toContain(jasmine.objectContaining({name: googleAnalytics}));
});
it('should filter googleAnalytics when empty configuration is retrieved', () => {
configurationDataService.findByPropertyName = jasmine.createSpy().withArgs(GOOGLE_ANALYTICS_KEY).and.returnValue(
createSuccessfulRemoteDataObject$({
... new ConfigurationProperty(),
name: googleAnalytics,
values: [],
}));
configurationDataService.findByPropertyName =
jasmine.createSpy()
.withArgs(GOOGLE_ANALYTICS_KEY)
.and
.returnValue(
createSuccessfulRemoteDataObject$({
... new ConfigurationProperty(),
name: googleAnalytics,
values: [],
}
)
)
.withArgs(REGISTRATION_VERIFICATION_ENABLED_KEY)
.and
.returnValue(
createSuccessfulRemoteDataObject$({
... new ConfigurationProperty(),
name: trackingIdTestValue,
values: ['false'],
})
);
service.initialize();
expect(service.klaroConfig.services).not.toContain(jasmine.objectContaining({name: googleAnalytics}));
});
it('should filter googleAnalytics when an error occurs', () => {
configurationDataService.findByPropertyName = jasmine.createSpy().withArgs(GOOGLE_ANALYTICS_KEY).and.returnValue(
createFailedRemoteDataObject$('Erro while loading GA')
);
configurationDataService.findByPropertyName =
jasmine.createSpy()
.withArgs(GOOGLE_ANALYTICS_KEY).and.returnValue(
createFailedRemoteDataObject$('Error while loading GA')
)
.withArgs(REGISTRATION_VERIFICATION_ENABLED_KEY)
.and
.returnValue(
createSuccessfulRemoteDataObject$({
... new ConfigurationProperty(),
name: trackingIdTestValue,
values: ['false'],
})
);
service.initialize();
expect(service.klaroConfig.services).not.toContain(jasmine.objectContaining({name: googleAnalytics}));
});
it('should filter googleAnalytics when an invalid payload is retrieved', () => {
configurationDataService.findByPropertyName = jasmine.createSpy().withArgs(GOOGLE_ANALYTICS_KEY).and.returnValue(
createSuccessfulRemoteDataObject$(null)
);
configurationDataService.findByPropertyName =
jasmine.createSpy()
.withArgs(GOOGLE_ANALYTICS_KEY).and.returnValue(
createSuccessfulRemoteDataObject$(null)
)
.withArgs(REGISTRATION_VERIFICATION_ENABLED_KEY)
.and
.returnValue(
createSuccessfulRemoteDataObject$({
... new ConfigurationProperty(),
name: trackingIdTestValue,
values: ['false'],
})
);
service.initialize();
expect(service.klaroConfig.services).not.toContain(jasmine.objectContaining({name: googleAnalytics}));
});

View File

@@ -50,6 +50,8 @@ export class BrowserKlaroService extends KlaroService {
private readonly GOOGLE_ANALYTICS_KEY = 'google.analytics.key';
private readonly REGISTRATION_VERIFICATION_ENABLED_KEY = 'registration.verification.enabled';
private readonly GOOGLE_ANALYTICS_SERVICE_NAME = 'google-analytics';
/**
@@ -90,7 +92,7 @@ export class BrowserKlaroService extends KlaroService {
}),
);
this.configService.findByPropertyName('registration.verification.enabled').pipe(
this.configService.findByPropertyName(this.REGISTRATION_VERIFICATION_ENABLED_KEY).pipe(
getFirstCompletedRemoteData(),
).subscribe((remoteData) => {
if (remoteData.statusCode === 404 || isEmpty(remoteData.payload?.values) || remoteData.payload.values[0].toLowerCase() !== 'true') {