[ADF-4753] - fixed calling for standalone task (#4952)

* [ADF-4753] - fixed calling for standalone task

* [ADF-4753] added unit test

* [ADF-4753] added unit test

* [ADF-4753] improved unit tests

* [ADF-4753] - removed extra parameter not needed
This commit is contained in:
Vito 2019-07-26 12:23:27 +01:00 committed by Maurizio Vitale
parent 05e73a8aa1
commit bb80d2b6d9
4 changed files with 82 additions and 6 deletions

View File

@ -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 = '<task id>';
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 = '<task id>';
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';

View File

@ -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);
}

View File

@ -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();
});
});
});
});

View File

@ -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) {