diff --git a/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.spec.ts index ea217bb937..15dd42f8da 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.spec.ts @@ -16,15 +16,17 @@ */ import { TestBed } from '@angular/core/testing'; -import { setupTestBed, AlfrescoApiService } from '@alfresco/adf-core'; +import { setupTestBed, AlfrescoApiService, LogService } from '@alfresco/adf-core'; import { ServiceTaskListCloudService } from './service-task-list-cloud.service'; import { ServiceTaskQueryCloudRequestModel } from '../models/service-task-cloud.model'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; +import { of } from 'rxjs'; describe('Activiti ServiceTaskList Cloud Service', () => { let service: ServiceTaskListCloudService; let alfrescoApiService: AlfrescoApiService; + let logService: LogService; const returnCallQueryParameters = (): any => ({ oauth2Auth: { @@ -50,6 +52,7 @@ describe('Activiti ServiceTaskList Cloud Service', () => { beforeEach(() => { alfrescoApiService = TestBed.inject(AlfrescoApiService); service = TestBed.inject(ServiceTaskListCloudService); + logService = TestBed.inject(LogService); }); it('should append to the call all the parameters', (done) => { @@ -101,4 +104,69 @@ describe('Activiti ServiceTaskList Cloud Service', () => { } ); }); + + describe('run replayServiceTaskRequest method', () => { + + let logServiceErrorSpy: jasmine.Spy; + + beforeEach(() => { + spyOn(service, 'getBasePath').and.returnValue('http://localhost/fakeName'); + spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallUrl); + logServiceErrorSpy = spyOn(logService, 'error'); + }); + + + it('should execute post method if all parameters are provided', async () => { + const expected = { + expectedQueryUrl: 'http://localhost/fakeName/rb/admin/v1/executions/executionId_1/replay/service-task', + expectedPayload: { + flowNodeId: 'flowNodeId_1' + } + }; + + const spyOnPost = spyOn(service, 'post').and.returnValue(of({})); + const params = ['fakeName', 'executionId_1', 'flowNodeId_1'] as const; + await service.replayServiceTaskRequest(...params).toPromise(); + expect(spyOnPost).toHaveBeenCalledWith(expected.expectedQueryUrl, expected.expectedPayload); + expect(logServiceErrorSpy).not.toHaveBeenCalled(); + + }); + + it('should throw an exeption and execute logService error if appName is null', () => { + const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured'; + const params = [null, 'executionId_1', 'flowNodeId_1'] as const; + service.replayServiceTaskRequest(...params).toPromise().catch((error) => { + expect(error).toEqual(expectedErrorMessage); + expect(logServiceErrorSpy).toHaveBeenCalled(); + }); + }); + + it('should throw an exeption and execute logService error if executionId is null', () => { + const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured'; + const params = ['fakeName', null, 'flowNodeId_1'] as const; + service.replayServiceTaskRequest(...params).toPromise().catch((error) => { + expect(error).toEqual(expectedErrorMessage); + expect(logServiceErrorSpy).toHaveBeenCalled(); + }); + }); + + it('should throw an exeption and execute logService error if flowNodeId is null', () => { + const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured'; + const params = ['fakeName', 'executionId_1', null] as const; + service.replayServiceTaskRequest(...params).toPromise().catch((error) => { + expect(error).toEqual(expectedErrorMessage); + expect(logServiceErrorSpy).toHaveBeenCalled(); + }); + }); + + it('should throw an exeption and execute logService error if appName, executionId and flowNodeId are null', () => { + const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured'; + const params = [null, null, null] as const; + service.replayServiceTaskRequest(...params).toPromise().catch((error) => { + expect(error).toEqual(expectedErrorMessage); + expect(logServiceErrorSpy).toHaveBeenCalled(); + }); + }); + }); + }); diff --git a/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.ts b/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.ts index 6128193a43..7fce2d73ec 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.ts @@ -72,6 +72,25 @@ export class ServiceTaskListCloudService extends BaseCloudService { } } + /** + * Replay a service task based on the related execution id and flow-node id + * + * @param appName string + * @param executionId string + * @param flowNodeId string + * @returns Replay task informations + */ + replayServiceTaskRequest(appName: string, executionId: string, flowNodeId: string): Observable { + if (appName && executionId && flowNodeId) { + const payload = { flowNodeId }; + const queryUrl = `${this.getBasePath(appName)}/rb/admin/v1/executions/${executionId}/replay/service-task`; + return this.post(queryUrl, payload); + } else { + this.logService.error('Appname, executionId and flowNodeId are mandatory to replaying a service task'); + return throwError('Appname/executionId/flowNodeId not configured'); + } + } + protected buildQueryParams(requestNode: ServiceTaskQueryCloudRequestModel): any { const queryParam: any = {}; for (const property in requestNode) {