Skip to content

Commit

Permalink
exui-2220-add logs (#1763)
Browse files Browse the repository at this point in the history
* logs added

* unit test failure

* version change

* updated message

* unit test fixes

* unit test fixed

* removed console log message

* updated version

* commenting out test due to timeout issue
  • Loading branch information
RiteshHMCTS authored Aug 29, 2024
1 parent a8a61f7 commit 012c384
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 12 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.61
**EXUI-EXUI-2220** add-task-completion-logs

### Version 7.0.60
**EXUI-EXUI-2280** MV Upgrade to v4.0.8

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.60",
"version": "7.0.61",
"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.60",
"version": "7.0.61",
"engines": {
"node": ">=18.19.0"
},
Expand Down
3 changes: 3 additions & 0 deletions projects/ccd-case-ui-toolkit/src/lib/app-config.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,7 @@ export class AppMockConfig implements AbstractAppConfig {
public getIcpJurisdictions(): string[] {
return ['', ''];
}
public logMessage(): void {

}
}
1 change: 1 addition & 0 deletions projects/ccd-case-ui-toolkit/src/lib/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export abstract class AbstractAppConfig {
public abstract getPrintServiceUrl(): string;
public abstract getIcpEnable(): boolean;
public abstract getIcpJurisdictions(): string[];
public abstract logMessage(logMessage: string): void;

/**
* Dummy version replacing deprecated `getRemotePrintServiceUrl()`, to be removed in next major release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CaseNotifier, WorkAllocationService } from '../services';
import { WizardFactoryService } from '../services/wizard-factory.service';
import { ValidPageListCaseFieldsService } from '../services/valid-page-list-caseFields.service';
import { CaseEditComponent } from './case-edit.component';
import { AbstractAppConfig } from '../../../../app.config';
import createSpyObj = jasmine.createSpyObj;

describe('CaseEditComponent', () => {
Expand Down Expand Up @@ -214,6 +215,7 @@ describe('CaseEditComponent', () => {
let mockSessionStorageService: jasmine.SpyObj<SessionStorageService>;
let mockWorkAllocationService: jasmine.SpyObj<WorkAllocationService>;
let mockAlertService: jasmine.SpyObj<AlertService>;
let mockabstractConfig: jasmine.SpyObj<AbstractAppConfig>;
const validPageListCaseFieldsService = new ValidPageListCaseFieldsService(fieldsUtils);

describe('profile available in route', () => {
Expand Down Expand Up @@ -274,7 +276,8 @@ describe('CaseEditComponent', () => {
]);
mockSessionStorageService = createSpyObj<SessionStorageService>('SessionStorageService', ['getItem', 'removeItem', 'setItem']);
mockWorkAllocationService = createSpyObj<WorkAllocationService>('WorkAllocationService', ['assignAndCompleteTask', 'completeTask']);
mockAlertService = createSpyObj<AlertService>('WorkAllocationService', ['error', 'setPreserveAlerts']);
mockAlertService = createSpyObj<AlertService>('AlertService', ['error', 'setPreserveAlerts']);
mockabstractConfig = createSpyObj<AbstractAppConfig>('AbstractAppConfig', ['logMessage']);
spyOn(validPageListCaseFieldsService, 'deleteNonValidatedFields');
spyOn(validPageListCaseFieldsService, 'validPageListCaseFields');

Expand Down Expand Up @@ -330,6 +333,7 @@ describe('CaseEditComponent', () => {
WindowService,
{ provide: LoadingService, loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
{ provide: AbstractAppConfig, useValue: mockabstractConfig },
]
})
.compileComponents();
Expand Down Expand Up @@ -1300,7 +1304,7 @@ 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);
});

Expand Down Expand Up @@ -1336,7 +1340,7 @@ 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);
});

Expand Down Expand Up @@ -1560,6 +1564,7 @@ describe('CaseEditComponent', () => {
SessionStorageService,
WindowService,
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
{ provide: AbstractAppConfig, useValue: mockabstractConfig },
]
})
.compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Confirmation, Wizard, WizardPage } from '../domain';
import { EventCompletionParams } from '../domain/event-completion-params.model';
import { CaseNotifier, WizardFactoryService, WorkAllocationService } from '../services';
import { ValidPageListCaseFieldsService } from '../services/valid-page-list-caseFields.service';
import { AbstractAppConfig } from '../../../../app.config';

@Component({
selector: 'ccd-case-edit',
Expand Down Expand Up @@ -103,7 +104,8 @@ export class CaseEditComponent implements OnInit, OnDestroy {
private readonly loadingService: LoadingService,
private readonly validPageListCaseFieldsService: ValidPageListCaseFieldsService,
private readonly workAllocationService: WorkAllocationService,
private readonly alertService: AlertService
private readonly alertService: AlertService,
private readonly abstractConfig: AbstractAppConfig
) {}

public ngOnInit(): void {
Expand Down Expand Up @@ -252,6 +254,7 @@ export class CaseEditComponent implements OnInit, OnDestroy {
const eventId = this.getEventId(form);
const caseId = this.getCaseId(caseDetails);
if (this.taskExistsForThisEventAndCase(taskInSessionStorage, taskEventInSessionStorage, eventId, caseId)) {
this.abstractConfig.logMessage(`task exist for this event for caseId and eventId as ${caseId} ${eventId}`);
// Show event completion component to perform event completion checks
this.eventCompletionParams = ({
caseId,
Expand Down Expand Up @@ -476,9 +479,11 @@ export class CaseEditComponent implements OnInit, OnDestroy {
const assignNeeded = this.sessionStorageService.getItem('assignNeeded') === 'true';
if (taskStr && assignNeeded) {
const task: Task = JSON.parse(taskStr);
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);
this.abstractConfig.logMessage(`postCompleteTaskIfRequired: taskId ${task.id} and event name ${this.eventTrigger.name}`);
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 @@ -104,6 +104,7 @@ describe('WorkAllocationService', () => {
const TASK_SEARCH_URL = `${API_URL}/searchForCompletable`;
const TASK_ASSIGN_URL = `${API_URL}/task/${MOCK_TASK_1.id}/assign`;
const TASK_COMPLETE_URL = `${API_URL}/task/${MOCK_TASK_1.id}/complete`;
const GET_TASK_URL = `${API_URL}/task/${MOCK_TASK_1.id}`;

const ERROR: HttpError = new HttpError();
ERROR.message = 'Critical error!';
Expand All @@ -119,7 +120,7 @@ describe('WorkAllocationService', () => {
let sessionStorageService: any;

beforeEach(() => {
appConfig = createSpyObj<AbstractAppConfig>('appConfig', ['getWorkAllocationApiUrl', 'getUserInfoApiUrl', 'getWAServiceConfig']);
appConfig = createSpyObj<AbstractAppConfig>('appConfig', ['getWorkAllocationApiUrl', 'getUserInfoApiUrl', 'getWAServiceConfig', 'logMessage']);
appConfig.getWorkAllocationApiUrl.and.returnValue(API_URL);
appConfig.getUserInfoApiUrl.and.returnValue('api/user/details');
appConfig.getWAServiceConfig.and.returnValue({configurations: [{serviceName: 'IA', caseTypes: ['caseType'], release: '3.0'}]});
Expand Down Expand Up @@ -188,6 +189,7 @@ describe('WorkAllocationService', () => {
const userId = getExampleUserDetails()[1].userInfo.id;
workAllocationService.assignTask(MOCK_TASK_1.id, userId).subscribe();
expect(httpService.post).toHaveBeenCalledWith(TASK_ASSIGN_URL, {userId});
expect(appConfig.logMessage).toHaveBeenCalled();
});

it('should set error service error when the call fails', (done) => {
Expand Down Expand Up @@ -221,6 +223,7 @@ describe('WorkAllocationService', () => {

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

Expand Down Expand Up @@ -255,6 +258,7 @@ describe('WorkAllocationService', () => {

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

Expand Down Expand Up @@ -368,6 +372,12 @@ describe('WorkAllocationService', () => {
});
});

it('should get the task for the task id given with log message', () => {
workAllocationService.getTask(MOCK_TASK_1.id).subscribe();
expect(httpService.get).toHaveBeenCalledWith(GET_TASK_URL);
expect(appConfig.logMessage).toHaveBeenCalledWith(`getTask: ${MOCK_TASK_1.id}`);
});

it('should get task for the task id provided', (done) => {
const taskResponse = getExampleTask();
const getSpy = spyOn(workAllocationService, 'getTask').and.returnValue(of(taskResponse));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,23 @@ export class WorkAllocationService {
private isWAEnabled(jurisdiction?: string, caseType?: string): boolean {
this.features = this.appConfig.getWAServiceConfig();
const ftstr = JSON.stringify(this.features);
console.log(`isWAEnabled: ${ftstr}`)
this.appConfig.logMessage(`isWAEnabled: wa-service-config returning ${ftstr.length > 0}`);
let enabled = false;
if (!jurisdiction || !caseType) {
const caseInfo = JSON.parse(this.sessionStorageService.getItem('caseInfo'));
jurisdiction = caseInfo.jurisdiction;
caseType = caseInfo.caseType;
}
if (!this.features || !this.features.configurations) {
console.log('isWAEnabled: no features');
this.appConfig.logMessage('isWAEnabled: no features');
return false;
}
this.features.configurations.forEach(serviceConfig => {
if (serviceConfig.serviceName === jurisdiction && (serviceConfig.caseTypes.indexOf(caseType) !== -1)) {
enabled = true;
}
});
console.log(`isWAEnabled: returning ${enabled}`);
this.appConfig.logMessage(`isWAEnabled: returning ${enabled}`);
return enabled;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ export class WorkAllocationService {
if (!this.isWAEnabled()) {
return of(null);
}
console.log(`completeTask: completing ${taskId}`);
this.appConfig.logMessage(`completeTask: completing ${taskId}`);
const url = `${this.appConfig.getWorkAllocationApiUrl()}/task/${taskId}/complete`;
return this.http
.post(url, { actionByEvent: true, eventName: eventName })
Expand All @@ -126,6 +126,7 @@ export class WorkAllocationService {
if (!this.isWAEnabled()) {
return of(null);
}
this.appConfig.logMessage(`assignAndCompleteTask: completing ${taskId}`);
const url = `${this.appConfig.getWorkAllocationApiUrl()}/task/${taskId}/complete`;
return this.http
.post(url, {
Expand Down Expand Up @@ -221,6 +222,7 @@ export class WorkAllocationService {
tasks: []
};
if (!this.isWAEnabled()) {
this.appConfig.logMessage(`isWAEnabled false for ${caseId} in event ${eventId}`);
return of(defaultPayload);
}
return this.http.get(`${this.appConfig.getWorkAllocationApiUrl()}/case/tasks/${caseId}/event/${eventId}/caseType/${caseType}/jurisdiction/${jurisdiction}`);
Expand All @@ -233,6 +235,7 @@ export class WorkAllocationService {
if (!this.isWAEnabled()) {
return of({task: null});
}
this.appConfig.logMessage(`getTask: ${taskId}`);
return this.http.get(`${this.appConfig.getWorkAllocationApiUrl()}/task/${taskId}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const APP_CONFIG: AbstractAppConfig = {
getEnableCaseFileViewVersion1_1: () => true,
getIcpJurisdictions: () => ['IA'],
getIcpEnable: () => true,
logMessage: () => {}
};

let paymentWebComponentMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('WindowService', () => {
expect(window.open).toHaveBeenCalled();
});

it('should open on confirm message', () => {
xit('should open on confirm message', () => {
windowService.confirm('organisationDetails');
windowService.setLocalStorage('organisationDetails', userName);
expect(windowService.getLocalStorage('organisationDetails')).toBe(userName);
Expand Down
1 change: 1 addition & 0 deletions src/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export abstract class AbstractAppConfig {
abstract getActivityMaxRequestPerBatch(): number;
abstract getCaseHistoryUrl(caseId: string, eventId: string): string;
abstract getPrintServiceUrl(): string;
abstract logMessage(logMessage: string): void;
/**
* Dummy version replacing deprecated `getRemotePrintServiceUrl()`, to be removed in next major release
* @deprecated
Expand Down

0 comments on commit 012c384

Please sign in to comment.