Skip to content

Commit

Permalink
exui-2235-add event name in app insight log while task completion (#1761
Browse files Browse the repository at this point in the history
)

* add event name in app insight log while task completion

* version updated
  • Loading branch information
RiteshHMCTS authored Aug 19, 2024
1 parent adb144d commit 2766f0b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 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.58
**EXUI-2235** add event name in task completion log

### Version 7.0.57
**EXUI-2209** MV Upgrade to v4.0.7

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.57",
"version": "7.0.58",
"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.57",
"version": "7.0.58",
"engines": {
"node": ">=18.19.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ describe('CaseEditComponent', () => {
submit: mockClass.submit,
});

expect(mockWorkAllocationService.assignAndCompleteTask).toHaveBeenCalledWith('12345');
expect(mockWorkAllocationService.assignAndCompleteTask).toHaveBeenCalledWith('12345', component.eventTrigger.name);
});

it('should submit the case and complete task for an event submission', () => {
Expand Down Expand Up @@ -1337,7 +1337,7 @@ describe('CaseEditComponent', () => {
submit: mockClass.submit,
});

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

it('should NOT submit the case due to error', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,10 @@ export class CaseEditComponent implements OnInit, OnDestroy {
const assignNeeded = this.sessionStorageService.getItem('assignNeeded') === 'true';
if (taskStr && assignNeeded) {
const task: Task = JSON.parse(taskStr);
return this.workAllocationService.assignAndCompleteTask(task.id);
return this.workAllocationService.assignAndCompleteTask(task.id, this.eventTrigger.name);
} else if (taskStr) {
const task: Task = JSON.parse(taskStr);
return this.workAllocationService.completeTask(task.id);
return this.workAllocationService.completeTask(task.id, this.eventTrigger.name);
}
return of(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ describe('WorkAllocationService', () => {
}));

it('should call post with the correct parameters', () => {
workAllocationService.completeTask(MOCK_TASK_1.id).subscribe();
expect(httpService.post).toHaveBeenCalledWith(TASK_COMPLETE_URL, { actionByEvent: true });
workAllocationService.completeTask(MOCK_TASK_1.id, 'Add case number').subscribe();
expect(httpService.post).toHaveBeenCalledWith(TASK_COMPLETE_URL, { actionByEvent: true, eventName: 'Add case number' });
});

it('should set error service error when the call fails', (done) => {
Expand Down Expand Up @@ -254,8 +254,8 @@ describe('WorkAllocationService', () => {
}));

it('should call post with the correct parameters', () => {
workAllocationService.assignAndCompleteTask(MOCK_TASK_1.id).subscribe();
expect(httpService.post).toHaveBeenCalledWith(TASK_COMPLETE_URL, {completion_options: {assign_and_complete: true}, actionByEvent: true});
workAllocationService.assignAndCompleteTask(MOCK_TASK_1.id, 'Add case number').subscribe();
expect(httpService.post).toHaveBeenCalledWith(TASK_COMPLETE_URL, {completion_options: {assign_and_complete: true}, actionByEvent: true, eventName: 'Add case number'});
});

it('should set error service error when the call fails', (done) => {
Expand Down Expand Up @@ -333,7 +333,7 @@ describe('WorkAllocationService', () => {
tasks: [ MOCK_TASK_2 ]
}));
workAllocationService.completeAppropriateTask('1234567890', 'event', 'IA', 'caseType').subscribe(result => {
expect(completeSpy).toHaveBeenCalledWith(MOCK_TASK_2.id);
expect(completeSpy).toHaveBeenCalledWith(MOCK_TASK_2.id, 'event');
done();
});
});
Expand Down Expand Up @@ -362,7 +362,7 @@ describe('WorkAllocationService', () => {
// Should not get here... so if we do, make sure it fails.
done.fail('Completed task instead of erroring');
}, error => {
expect(completeSpy).toHaveBeenCalledWith(MOCK_TASK_2.id);
expect(completeSpy).toHaveBeenCalledWith(MOCK_TASK_2.id, 'event');
expect(error.message).toEqual(COMPLETE_ERROR.message); // The error for completing the task.
done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ export class WorkAllocationService {
* Call the API to complete a task.
* @param taskId specifies which task should be completed.
*/
public completeTask(taskId: string): Observable<any> {
public completeTask(taskId: string, eventName?: string): Observable<any> {
if (!this.isWAEnabled()) {
return of(null);
}
console.log(`completeTask: completing ${taskId}`);
const url = `${this.appConfig.getWorkAllocationApiUrl()}/task/${taskId}/complete`;
return this.http
.post(url, { actionByEvent: true })
.post(url, { actionByEvent: true, eventName: eventName })
.pipe(
catchError(error => {
this.errorService.setError(error);
Expand All @@ -122,7 +122,7 @@ export class WorkAllocationService {
* Call the API to assign and complete a task.
* @param taskId specifies which task should be completed.
*/
public assignAndCompleteTask(taskId: string): Observable<any> {
public assignAndCompleteTask(taskId: string, eventName?: string): Observable<any> {
if (!this.isWAEnabled()) {
return of(null);
}
Expand All @@ -132,7 +132,8 @@ export class WorkAllocationService {
completion_options: {
assign_and_complete: true
},
actionByEvent: true
actionByEvent: true,
eventName: eventName
})
.pipe(
catchError(error => {
Expand Down Expand Up @@ -196,7 +197,7 @@ export class WorkAllocationService {
const tasks: any[] = response.tasks;
if (tasks && tasks.length > 0) {
if (tasks.length === 1) {
this.completeTask(tasks[0].id).subscribe();
this.completeTask(tasks[0].id, eventId).subscribe();
} else {
// This is a problem. Throw an appropriate error.
throw new Error(MULTIPLE_TASKS_FOUND);
Expand Down

0 comments on commit 2766f0b

Please sign in to comment.