Skip to content

Commit

Permalink
Bug/ex UI 2624 user task missing (#1822)
Browse files Browse the repository at this point in the history
* Update event-start.guard.ts

Fix regression issue that overwrites user_task

* Change version

* Update event-start.guard.ts

Add 'en' even if no cookie
Add language to existing client_context object, not just object with user_task

* Add version

* Update event-start.guard.spec.ts

Add helpful test

* update to rel name

---------

Co-authored-by: Josh <[email protected]>
  • Loading branch information
connorpgpmcelroy and Josh-HMCTS authored Dec 9, 2024
1 parent e73c77b commit 4d5c79d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "7.0.75-exui-2315",
"version": "7.0.75-user-task-missing-rel",
"engines": {
"node": ">=18.19.0"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/ccd-case-ui-toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "7.0.75-exui-2315",
"version": "7.0.75-user-task-missing-rel",
"engines": {
"node": ">=18.19.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,21 @@ describe('EventStartGuard', () => {
const result$ = guard.canActivate(route);
result$.subscribe(result => {
expect(result).toEqual(false);
// check client contesxt is set correctly
// check client context is set correctly
expect(sessionStorageService.setItem).toHaveBeenCalledWith('clientContext', JSON.stringify(mockClientContext));
});
});

it('client context should be set with language regardless if client context already exists', () => {
const mockClientContext: any = { client_context: { user_task: {}, additional_field: 'test' } };
sessionStorageService.getItem.and.returnValues(null, null, JSON.stringify(mockClientContext));
mockCookieService.getCookie.and.returnValue('cookieString');
const route = createActivatedRouteSnapshot('caseId', 'eventId');
const result$ = guard.canActivate(route);
mockClientContext.client_context.user_language = { language: 'cookieString' };
result$.subscribe(result => {
expect(result).toEqual(false);
// check client context is set correctly
expect(sessionStorageService.setItem).toHaveBeenCalledWith('clientContext', JSON.stringify(mockClientContext));
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,34 @@ export class EventStartGuard implements CanActivate {
userId = userInfo.id ? userInfo.id : userInfo.uid;
}
const caseInfoStr = this.sessionStorageService.getItem('caseInfo');
const currentLanguage = this.cookieService.getCookie('exui-preferred-language');
// if one task assigned to user, allow user to complete event
const storeClientContext = {
client_context: {
user_language: {
language: currentLanguage
const languageCookie = this.cookieService.getCookie('exui-preferred-language');
const currentLanguage = !!languageCookie && languageCookie !== '' ? languageCookie : 'en';
const preClientContext = this.sessionStorageService.getItem(EventStartGuard.CLIENT_CONTEXT);
if (!preClientContext) {
// creates client context for language if not already existing
const storeClientContext = {
client_context: {
user_language: {
language: currentLanguage
}
}
};
this.sessionStorageService.setItem(EventStartGuard.CLIENT_CONTEXT, JSON.stringify(storeClientContext));
} else {
const clientContextObj = JSON.parse(preClientContext);
if (!clientContextObj?.client_context?.user_language) {
const clientContextAddLanguage = {
...clientContextObj,
client_context: {
...clientContextObj.client_context,
user_language: {
language: currentLanguage
}
}
}
this.sessionStorageService.setItem(EventStartGuard.CLIENT_CONTEXT, JSON.stringify(clientContextAddLanguage));
}
};
this.sessionStorageService.setItem(EventStartGuard.CLIENT_CONTEXT, JSON.stringify(storeClientContext));
}
if (caseInfoStr) {
const caseInfo = JSON.parse(caseInfoStr);
if (caseInfo && caseInfo.cid === caseId) {
Expand Down

0 comments on commit 4d5c79d

Please sign in to comment.