Skip to content

Commit

Permalink
Commit full client context changes (#1733)
Browse files Browse the repository at this point in the history
* Commit full client context changes

* Edit test and version

* Update event-completion-state-machine.service.ts

* Update cases.service.ts

* Update event-completion-state-machine.service.ts

* Add test sonar

* Fix task completion issue

* Add tests for Sonar

* Update event-completion-state-machine.service.spec.ts

* Edit version

* Update cases.service.spec.ts

* Update case-edit.component.spec.ts

* Update to release version number, update release-notes

* Make changes for PR comments

---------

Co-authored-by: Josh <josh.glasgow@hmcts.net>
  • Loading branch information
connorpgpmcelroy and Josh-HMCTS authored Sep 10, 2024
1 parent 2d557a4 commit fbbfda6
Show file tree
Hide file tree
Showing 17 changed files with 398 additions and 108 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## RELEASE NOTES

### Version 7.0.63
**EXUI-1838/39/40** Task Completion - EXUI Header

### Version 7.0.61
**EXUI-EXUI-2220** add-task-completion-logs

Expand Down
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.62",
"version": "7.0.63",
"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.62",
"version": "7.0.63",
"engines": {
"node": ">=18.19.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ describe('CaseEditComponent', () => {
case_field_id: CASE_FIELD_3_COLLECTION.id
};

const CLIENT_CONTEXT = { client_context: {
user_task: {
task_data: {
id: '1',
name: 'Example task',
case_id: '1234567890'
},
complete_task: true
}
}};

let fixture: ComponentFixture<CaseEditComponent>;
let component: CaseEditComponent;
let de: DebugElement;
Expand Down Expand Up @@ -1273,7 +1284,7 @@ describe('CaseEditComponent', () => {
});

it('should submit the case and assign and complete task for an event submission', () => {
mockSessionStorageService.getItem.and.returnValues(`{"id": "12345"}`, 'true');
mockSessionStorageService.getItem.and.returnValues(JSON.stringify(CLIENT_CONTEXT), 'true');
fixture.detectChanges();
const mockClass = {
submit: () => of({})
Expand Down Expand Up @@ -1304,12 +1315,49 @@ describe('CaseEditComponent', () => {
form: component.form,
submit: mockClass.submit,
});
expect(mockabstractConfig.logMessage).toHaveBeenCalledWith('postCompleteTaskIfRequired with assignNeeded: taskId 12345 and event name Test Trigger');
expect(mockWorkAllocationService.assignAndCompleteTask).toHaveBeenCalledWith('12345', component.eventTrigger.name);
expect(mockabstractConfig.logMessage).toHaveBeenCalledWith('postCompleteTaskIfRequired with assignNeeded: taskId 1 and event name Test Trigger');
expect(mockWorkAllocationService.assignAndCompleteTask).toHaveBeenCalledWith('1', component.eventTrigger.name);
});

it('should submit the case and complete task for an event submission', () => {
mockSessionStorageService.getItem.and.returnValues(`{"id": "12345"}`, 'false');
mockSessionStorageService.getItem.and.returnValues(JSON.stringify(CLIENT_CONTEXT), 'false');
fixture.detectChanges();
const mockClass = {
submit: () => of({})
};
spyOn(mockClass, 'submit').and.returnValue(of({
id: 'id',
/* tslint:disable:object-literal-key-quotes */
'callback_response_status': 'CALLBACK_HASNOT_COMPLETED',
/* tslint:disable:object-literal-key-quotes */
'after_submit_callback_response': {
/* tslint:disable:object-literal-key-quotes */
'confirmation_header': 'confirmation_header',
/* tslint:disable:object-literal-key-quotes */
'confirmation_body': 'confirmation_body'
}
}));

spyOn(component, 'confirm');

component.isCaseFlagSubmission = true;
component.confirmation = {} as unknown as Confirmation;

formValueService.sanitise.and.returnValue({name: 'sweet'});
component.onEventCanBeCompleted({
eventTrigger: component.eventTrigger,
eventCanBeCompleted: true,
caseDetails: component.caseDetails,
form: component.form,
submit: mockClass.submit,
});

expect(mockWorkAllocationService.completeTask).toHaveBeenCalledWith('1', component.eventTrigger.name);
});

it('should submit the case and not complete task for an event submission when service makes this clear', () => {
CLIENT_CONTEXT.client_context.user_task.complete_task = false;
mockSessionStorageService.getItem.and.returnValues(JSON.stringify(CLIENT_CONTEXT), 'false');
fixture.detectChanges();
const mockClass = {
submit: () => of({})
Expand Down Expand Up @@ -1340,8 +1388,8 @@ describe('CaseEditComponent', () => {
form: component.form,
submit: mockClass.submit,
});
expect(mockabstractConfig.logMessage).toHaveBeenCalledWith('postCompleteTaskIfRequired: taskId 12345 and event name Test Trigger');
expect(mockWorkAllocationService.completeTask).toHaveBeenCalledWith('12345', component.eventTrigger.name);

expect(mockWorkAllocationService.completeTask).not.toHaveBeenCalled();
});

it('should NOT submit the case due to error', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,12 @@ export class CaseEditComponent implements OnInit, OnDestroy {
this.isSubmitting = true;
// We have to run the event completion checks if task in session storage
// and if the task is in session storage, then is it associated to the case
let taskInSessionStorage: Task;
const clientContextStr = this.sessionStorageService.getItem('clientContext');
const userTask = FieldsUtils.getUserTaskFromClientContext(clientContextStr);
const taskInSessionStorage = userTask ? userTask.task_data : null;
let taskEventInSessionStorage: TaskEvent;
const taskStr = this.sessionStorageService.getItem('taskToComplete');
const taskEventStr = this.sessionStorageService.getItem('taskEvent');
if (taskStr) {
taskInSessionStorage = JSON.parse(taskStr);
}
if (taskEventStr) {
taskEventInSessionStorage = JSON.parse(taskEventStr);
}
Expand Down Expand Up @@ -475,14 +474,14 @@ export class CaseEditComponent implements OnInit, OnDestroy {
}

private postCompleteTaskIfRequired(): Observable<any> {
const taskStr = this.sessionStorageService.getItem('taskToComplete');
const clientContextStr = this.sessionStorageService.getItem('clientContext');
const userTask = FieldsUtils.getUserTaskFromClientContext(clientContextStr);
const [task, taskToBeCompleted] = userTask ? [userTask.task_data, userTask.complete_task] : [null, false];
const assignNeeded = this.sessionStorageService.getItem('assignNeeded') === 'true';
if (taskStr && assignNeeded) {
const task: Task = JSON.parse(taskStr);
if (task && assignNeeded && taskToBeCompleted) {
this.abstractConfig.logMessage(`postCompleteTaskIfRequired with assignNeeded: taskId ${task.id} and event name ${this.eventTrigger.name}`);
return this.workAllocationService.assignAndCompleteTask(task.id, this.eventTrigger.name);
} else if (taskStr) {
const task: Task = JSON.parse(taskStr);
} else if (task && taskToBeCompleted) {
this.abstractConfig.logMessage(`postCompleteTaskIfRequired: taskId ${task.id} and event name ${this.eventTrigger.name}`);
return this.workAllocationService.completeTask(task.id, this.eventTrigger.name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ describe('TaskReassignedComponent', () => {
}
};

const CLIENT_CONTEXT = { client_context: {
user_task: {
task_data: {
id: '1',
name: 'Example task',
case_id: '1234567890'
},
complete_task: true
}
}};


appConfig = createSpyObj<AbstractAppConfig>('appConfig', ['getApiUrl', 'getCaseDataUrl', 'getWorkAllocationApiUrl', 'getCamRoleAssignmentsApiUrl']);
appConfig.getApiUrl.and.returnValue(API_URL);
appConfig.getCaseDataUrl.and.returnValue(API_URL);
Expand All @@ -104,7 +116,7 @@ describe('TaskReassignedComponent', () => {

beforeEach(async () => {
mockSessionStorageService = createSpyObj<SessionStorageService>('sessionStorageService', ['getItem', 'setItem']);
mockSessionStorageService.getItem.and.returnValue(JSON.stringify(task));
mockSessionStorageService.getItem.and.returnValue(JSON.stringify(CLIENT_CONTEXT));
TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [CaseEventCompletionTaskReassignedComponent, MockRpxTranslatePipe],
Expand Down Expand Up @@ -142,6 +154,15 @@ describe('TaskReassignedComponent', () => {
spyOn(mockWorkAllocationService, 'assignAndCompleteTask').and.returnValue({subscribe: () => {}});
component.onContinue();
expect(mockSessionStorageService.getItem).toHaveBeenCalledTimes(1);
expect(mockSessionStorageService.setItem).toHaveBeenCalledWith('assignNeeded', 'true');
});

it('should task on continue event', () => {
mockSessionStorageService.getItem.and.returnValue('');
spyOn(mockWorkAllocationService, 'assignAndCompleteTask').and.returnValue({subscribe: () => {}});
component.onContinue();
expect(mockSessionStorageService.getItem).toHaveBeenCalledTimes(1);
expect(mockSessionStorageService.setItem).not.toHaveBeenCalled();
});

it('should unsubscribe subscriptions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Subscription, throwError } from 'rxjs';
import { Task } from '../../../../../domain/work-allocation/Task';
import { AlertService } from '../../../../../services/alert/alert.service';
import { SessionStorageService } from '../../../../../services/session/session-storage.service';
import {
AlertService,
FieldsUtils,
SessionStorageService
} from '../../../../../services';
import { CaseworkerService } from '../../../services/case-worker.service';
import { JudicialworkerService } from '../../../services/judicial-worker.service';
import { WorkAllocationService } from '../../../services/work-allocation.service';
Expand Down Expand Up @@ -77,8 +80,12 @@ export class CaseEventCompletionTaskReassignedComponent implements OnInit, OnDes

public onContinue(): void {
// Get task details
const taskStr = this.sessionStorageService.getItem('taskToComplete');
if (taskStr) {
const clientContextStr = this.sessionStorageService.getItem('clientContext');
const userTask = FieldsUtils.getUserTaskFromClientContext(clientContextStr);
const task = userTask ? userTask.task_data : null;
// not complete_task not utilised here as related to event completion
// service wanting task associated with event to not be completed not directly relevant
if (task) {
this.sessionStorageService.setItem('assignNeeded', 'true');
// set event can be completed to true
this.parentComponent.eventCanBeCompleted.emit(true);
Expand Down
Loading

0 comments on commit fbbfda6

Please sign in to comment.