Skip to content

Commit f1a1aeb

Browse files
author
Andrea Barbasso
committed
[DURACOM-309] improve e2e pipeline, fix cookie issues
1 parent c0a5420 commit f1a1aeb

15 files changed

+79
-100
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
DSPACE_CACHE_SERVERSIDE_ANONYMOUSCACHE_MAX: 0
3030
# Tell Cypress to run e2e tests using the same UI URL
3131
CYPRESS_BASE_URL: http://127.0.0.1:4000
32+
# Disable the cookie consent banner in e2e tests to avoid errors because of elements hidden by it
33+
DSPACE_INFO_ENABLECOOKIECONSENTPOPUP: false
3234
# When Chrome version is specified, we pin to a specific version of Chrome
3335
# Comment this out to use the latest release
3436
#CHROME_VERSION: "90.0.4430.212-1"

angular.json

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -105,37 +105,6 @@
105105
"maximumError": "300kb"
106106
}
107107
]
108-
},
109-
"production-e2e": {
110-
"fileReplacements": [
111-
{
112-
"replace": "src/environments/environment.ts",
113-
"with": "src/environments/environment.production-e2e.ts"
114-
},
115-
{
116-
"replace": "src/config/store/devtools.ts",
117-
"with": "src/config/store/devtools.prod.ts"
118-
}
119-
],
120-
"optimization": true,
121-
"outputHashing": "all",
122-
"namedChunks": false,
123-
"aot": true,
124-
"extractLicenses": true,
125-
"vendorChunk": false,
126-
"buildOptimizer": true,
127-
"budgets": [
128-
{
129-
"type": "initial",
130-
"maximumWarning": "3mb",
131-
"maximumError": "5mb"
132-
},
133-
{
134-
"type": "anyComponentStyle",
135-
"maximumWarning": "200kb",
136-
"maximumError": "300kb"
137-
}
138-
]
139108
}
140109
}
141110
},
@@ -151,9 +120,6 @@
151120
},
152121
"production": {
153122
"buildTarget": "dspace-angular:build:production"
154-
},
155-
"production-e2e": {
156-
"buildTarget": "dspace-angular:build:production-e2e"
157123
}
158124
}
159125
},
@@ -215,9 +181,6 @@
215181
"configurations": {
216182
"production": {
217183
"devServerTarget": "dspace-angular:serve:production"
218-
},
219-
"production-e2e": {
220-
"devServerTarget": "dspace-angular:serve:production-e2e"
221184
}
222185
}
223186
},
@@ -252,20 +215,6 @@
252215
"with": "src/config/store/devtools.prod.ts"
253216
}
254217
]
255-
},
256-
"production-e2e": {
257-
"sourceMap": false,
258-
"optimization": true,
259-
"fileReplacements": [
260-
{
261-
"replace": "src/environments/environment.ts",
262-
"with": "src/environments/environment.production-e2e.ts"
263-
},
264-
{
265-
"replace": "src/config/store/devtools.ts",
266-
"with": "src/config/store/devtools.prod.ts"
267-
}
268-
]
269218
}
270219
}
271220
},
@@ -280,10 +229,6 @@
280229
"production": {
281230
"buildTarget": "dspace-angular:build:production",
282231
"serverTarget": "dspace-angular:server:production"
283-
},
284-
"production-e2e": {
285-
"buildTarget": "dspace-angular:build:production-e2e",
286-
"serverTarget": "dspace-angular:server:production-e2e"
287232
}
288233
}
289234
},
@@ -297,8 +242,7 @@
297242
]
298243
},
299244
"configurations": {
300-
"production": {},
301-
"production-e2e": {}
245+
"production": {}
302246
}
303247
},
304248
"cypress-run": {
@@ -309,9 +253,6 @@
309253
"configurations": {
310254
"production": {
311255
"devServerTarget": "dspace-angular:serve:production"
312-
},
313-
"production-e2e": {
314-
"devServerTarget": "dspace-angular:serve:production-e2e"
315256
}
316257
}
317258
},

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
"build": "ng build --configuration development",
1717
"build:stats": "ng build --stats-json",
1818
"build:prod": "cross-env NODE_ENV=production npm run build:ssr",
19-
"build:prod-e2e": "cross-env NODE_ENV=production npm run build:ssr-e2e",
2019
"build:ssr": "ng build --configuration production && ng run dspace-angular:server:production",
21-
"build:ssr-e2e": "ng build --configuration production-e2e && ng run dspace-angular:server:production-e2e",
2220
"build:lint": "rimraf 'lint/dist/**/*.js' 'lint/dist/**/*.js.map' && tsc -b lint/tsconfig.json",
2321
"test": "ng test --source-map=true --watch=false --configuration test",
2422
"test:watch": "nodemon --exec \"ng test --source-map=true --watch=true --configuration test\"",

src/app/core/log/log.interceptor.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import {
1616
appReducers,
1717
storeModuleConfig,
1818
} from '../../app.reducer';
19-
import { CorrelationIdService } from '../../correlation-id/correlation-id.service';
19+
import {
20+
CORRELATION_ID_COOKIE,
21+
CorrelationIdService,
22+
} from '../../correlation-id/correlation-id.service';
2023
import { OrejimeService } from '../../shared/cookies/orejime.service';
2124
import { CORRELATION_ID_OREJIME_KEY } from '../../shared/cookies/orejime-configuration';
2225
import { CookieServiceMock } from '../../shared/mocks/cookie.service.mock';
@@ -72,8 +75,8 @@ describe('LogInterceptor', () => {
7275
cookieService = TestBed.inject(CookieService);
7376
correlationIdService = TestBed.inject(CorrelationIdService);
7477

75-
cookieService.set('CORRELATION-ID','123455');
76-
correlationIdService.initCorrelationId();
78+
cookieService.set(CORRELATION_ID_COOKIE,'123455');
79+
correlationIdService.setCorrelationId();
7780
});
7881

7982

src/app/correlation-id/correlation-id.service.spec.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
StoreModule,
55
} from '@ngrx/store';
66
import { MockStore } from '@ngrx/store/testing';
7+
import { of } from 'rxjs';
78

89
import {
910
appReducers,
@@ -13,7 +14,10 @@ import {
1314
import { UUIDService } from '../core/shared/uuid.service';
1415
import { CookieServiceMock } from '../shared/mocks/cookie.service.mock';
1516
import { 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

1822
describe('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
});

src/app/correlation-id/correlation-id.service.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { Injectable } from '@angular/core';
1+
import {
2+
Inject,
3+
Injectable,
4+
} from '@angular/core';
25
import {
36
select,
47
Store,
@@ -7,12 +10,18 @@ import { take } from 'rxjs/operators';
710

811
import { AppState } from '../app.reducer';
912
import { CookieService } from '../core/services/cookie.service';
13+
import {
14+
NativeWindowRef,
15+
NativeWindowService,
16+
} from '../core/services/window.service';
1017
import { UUIDService } from '../core/shared/uuid.service';
18+
import { OrejimeService } from '../shared/cookies/orejime.service';
19+
import { CORRELATION_ID_OREJIME_KEY } from '../shared/cookies/orejime-configuration';
1120
import { isEmpty } from '../shared/empty.util';
1221
import { SetCorrelationIdAction } from './correlation-id.actions';
1322
import { correlationIdSelector } from './correlation-id.selector';
1423

15-
export const CORRELATION_ID_COOKIE = 'dsCorrelationId';
24+
export const CORRELATION_ID_COOKIE = 'CORRELATION-ID';
1625

1726
/**
1827
* Service to manage the correlation id, an id used to give context to server side logs
@@ -26,15 +35,32 @@ export class CorrelationIdService {
2635
protected cookieService: CookieService,
2736
protected uuidService: UUIDService,
2837
protected store: Store<AppState>,
38+
protected orejimeService: OrejimeService,
39+
@Inject(NativeWindowService) protected _window: NativeWindowRef,
2940
) {
41+
if (this._window?.nativeWindow) {
42+
this._window.nativeWindow.initCorrelationId = () => this.initCorrelationId();
43+
}
3044
}
3145

3246
/**
33-
* Initialize the correlation id based on the cookie or the ngrx store
47+
* Check if the correlation id is allowed to be set, then set it
3448
*/
3549
initCorrelationId(): void {
50+
this.orejimeService?.getSavedPreferences().subscribe(preferences => {
51+
if (preferences[CORRELATION_ID_OREJIME_KEY]) {
52+
this.setCorrelationId();
53+
}
54+
},
55+
);
56+
}
57+
58+
/**
59+
* Initialize the correlation id based on the cookie or the ngrx store
60+
*/
61+
setCorrelationId(): void {
3662
// first see of there's a cookie with a correlation-id
37-
let correlationId = this.cookieService.get('CORRELATION-ID');
63+
let correlationId = this.cookieService.get(CORRELATION_ID_COOKIE);
3864

3965
// if there isn't see if there's an ID in the store
4066
if (isEmpty(correlationId)) {
@@ -48,7 +74,7 @@ export class CorrelationIdService {
4874

4975
// Store the correct id both in the store and as a cookie to ensure they're in sync
5076
this.store.dispatch(new SetCorrelationIdAction(correlationId));
51-
this.cookieService.set('CORRELATION-ID', correlationId);
77+
this.cookieService.set(CORRELATION_ID_COOKIE, correlationId);
5278
}
5379

5480
/**

src/app/shared/cookies/browser-orejime.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class BrowserOrejimeService extends OrejimeService {
191191
*/
192192
this.translateConfiguration();
193193

194-
if (environment.isE2E) {
194+
if (!environment.info?.enableCookieConsentPopup) {
195195
this.orejimeConfig.apps = [];
196196
} else {
197197
this.orejimeConfig.apps = this.filterConfigApps(appsToHide);

src/app/shared/cookies/orejime-configuration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ export function getOrejimeConfiguration(_window: NativeWindowRef): any {
151151
cookies: [
152152
CORRELATION_ID_COOKIE,
153153
],
154+
callback: () => {
155+
_window?.nativeWindow.initCorrelationId();
156+
},
154157
},
155158
{
156159
name: MATOMO_OREJIME_KEY,

src/config/build-config.interface.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ import { SSRConfig } from './ssr-config.interface';
33

44
export interface BuildConfig extends AppConfig {
55
ssr: SSRConfig;
6-
isE2E?: boolean;
76
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Config } from './config.interface';
22

33
export interface InfoConfig extends Config {
4-
enableEndUserAgreement: boolean;
5-
enablePrivacyStatement: boolean;
6-
enableCOARNotifySupport: boolean;
4+
enableEndUserAgreement?: boolean;
5+
enablePrivacyStatement?: boolean;
6+
enableCOARNotifySupport?: boolean;
7+
enableCookieConsentPopup?: boolean;
78
}

0 commit comments

Comments
 (0)