diff --git a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts index d1f6de7bf2..7e2cc2ed70 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts @@ -17,7 +17,7 @@ import { SimpleChange, DebugElement, CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; import { Observable, of, throwError } from 'rxjs'; import { FormFieldModel, FormFieldTypes, FormService, FormOutcomeEvent, FormOutcomeModel, LogService, WidgetVisibilityService, @@ -237,6 +237,45 @@ describe('FormCloudComponent', () => { expect(formComponent.getFormByTaskId).toHaveBeenCalledWith(appName, taskId); }); + it('should call the process storage to retrieve the folder with only the taskId', fakeAsync(() => { + spyOn(formCloudService, 'getTaskForm').and.returnValue(of(cloudFormMock)); + spyOn(formCloudService, 'getTaskVariables').and.returnValue(of({list: { entries: []}})); + spyOn(formCloudService, 'getProcessStorageFolderTask') + .and.returnValue( of({nodeId : '123', path: '/a/path/type', type: 'fakeType'})); + const taskId = ''; + const appName = 'test-app'; + formComponent.appName = appName; + formComponent.taskId = taskId; + + const change = new SimpleChange(null, appName, true); + formComponent.ngOnChanges({ 'appName': change }); + tick(); + + expect(formCloudService.getProcessStorageFolderTask).toHaveBeenCalledWith(appName, taskId, undefined); + expect(formComponent.form.nodeId).toBe('123'); + expect(formComponent.form.contentHost).toBe('/a/path/type'); + })); + + it('should call the process storage to retrieve the folder with taskId and processInstanceId', fakeAsync(() => { + spyOn(formCloudService, 'getTaskForm').and.returnValue(of(cloudFormMock)); + spyOn(formCloudService, 'getTaskVariables').and.returnValue(of({list: { entries: []}})); + spyOn(formCloudService, 'getProcessStorageFolderTask') + .and.returnValue( of({nodeId : '123', path: '/a/path/type', type: 'fakeType'})); + const taskId = ''; + const processInstanceId = 'i-am-the-process-instance-id'; + const appName = 'test-app'; + formComponent.appName = appName; + formComponent.taskId = taskId; + formComponent.processInstanceId = processInstanceId; + + const change = new SimpleChange(null, 'new-app-name', true); + formComponent.ngOnChanges({ 'appName': change }); + tick(); + expect(formCloudService.getProcessStorageFolderTask).toHaveBeenCalledWith(appName, taskId, processInstanceId); + expect(formComponent.form.nodeId).toBe('123'); + expect(formComponent.form.contentHost).toBe('/a/path/type'); + })); + it('should reload form definition by form id on binding changes', () => { spyOn(formComponent, 'getFormById').and.stub(); const formId = '123'; diff --git a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts index 883887b3f5..83c555edeb 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts @@ -117,10 +117,8 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges, ngOnChanges(changes: SimpleChanges) { const appName = changes['appName']; if (appName && appName.currentValue) { - if (this.taskId && this.processInstanceId) { + if (this.taskId) { this.getFormDefinitionWithFolderTask(this.appName, this.taskId, this.processInstanceId); - } else if (this.taskId) { - this.getFormByTaskId(this.appName, this.taskId); } else if (this.formId) { this.getFormById(appName.currentValue, this.formId); } diff --git a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts index b708222fec..3c7d61b3e8 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts @@ -138,7 +138,6 @@ describe('Form Cloud service', () => { expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('GET'); done(); }); - }); it('should fetch task form flattened', (done) => { @@ -187,5 +186,43 @@ describe('Form Cloud service', () => { }); + it('should fetch process storage folder with process instance id and task id', (done) => { + oauth2Auth.callCustomApi.and.returnValue(Promise.resolve({ + nodeId: 'fake-node-id-really-long', + path: 'path/to/node/id', + type: 'nodeType' + })); + + service.getProcessStorageFolderTask(appName, taskId, processInstanceId).subscribe((result) => { + expect(result).toBeDefined(); + expect(result).not.toBeNull(); + expect(result.nodeId).toBe('fake-node-id-really-long'); + expect(result.path).toBe('path/to/node/id'); + expect(result.type).toBe('nodeType'); + expect(oauth2Auth.callCustomApi.calls.mostRecent().args[0].endsWith(`${appName}/process-storage/v1/folders/${processInstanceId}/${taskId}`)).toBeTruthy(); + expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('GET'); + done(); + }); + }); + + it('should fetch process storage folder with task id only', (done) => { + oauth2Auth.callCustomApi.and.returnValue(Promise.resolve({ + nodeId: 'fake-node-id-really-long', + path: 'path/to/node/id', + type: 'nodeType' + })); + + service.getProcessStorageFolderTask(appName, taskId, null).subscribe((result) => { + expect(result).toBeDefined(); + expect(result).not.toBeNull(); + expect(result.nodeId).toBe('fake-node-id-really-long'); + expect(result.path).toBe('path/to/node/id'); + expect(result.type).toBe('nodeType'); + expect(oauth2Auth.callCustomApi.calls.mostRecent().args[0].endsWith(`${appName}/process-storage/v1/folders/${taskId}`)).toBeTruthy(); + expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('GET'); + done(); + }); + }); + }); }); diff --git a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts index 10f2e555fc..295622263b 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts @@ -299,7 +299,9 @@ export class FormCloudService extends BaseCloudService { } private buildFolderTask(appName: string, taskId: string, processInstanceId: string): string { - return `${this.getBasePath(appName)}/process-storage/v1/folders/${processInstanceId}/${taskId}`; + return processInstanceId + ? `${this.getBasePath(appName)}/process-storage/v1/folders/${processInstanceId}/${taskId}` + : `${this.getBasePath(appName)}/process-storage/v1/folders/${taskId}`; } private handleError(error: any) {