mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
AAE-38334 Add link process payload (#11524)
* AAE-38334 Add link process payload * update * update
This commit is contained in:
+3
-3
@@ -863,7 +863,7 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
component.formCloud = null;
|
component.formCloud = null;
|
||||||
const payload: ProcessPayloadCloud = new ProcessPayloadCloud({
|
const payload: ProcessPayloadCloud = new ProcessPayloadCloud({
|
||||||
name: component.processInstanceName.value,
|
name: component.processInstanceName.value,
|
||||||
ProcessDefinitionKey: component.processPayloadCloud.processDefinitionKey,
|
processDefinitionKey: component.processPayloadCloud.processDefinitionKey,
|
||||||
variables: Object.assign(component.variables, component.formCloud)
|
variables: Object.assign(component.variables, component.formCloud)
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -889,7 +889,7 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
component.formCloud = undefined;
|
component.formCloud = undefined;
|
||||||
const payload: ProcessPayloadCloud = new ProcessPayloadCloud({
|
const payload: ProcessPayloadCloud = new ProcessPayloadCloud({
|
||||||
name: component.processInstanceName.value,
|
name: component.processInstanceName.value,
|
||||||
ProcessDefinitionKey: component.processPayloadCloud.processDefinitionKey,
|
processDefinitionKey: component.processPayloadCloud.processDefinitionKey,
|
||||||
variables: {}
|
variables: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -912,7 +912,7 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
|
|
||||||
const payload: ProcessPayloadCloud = new ProcessPayloadCloud({
|
const payload: ProcessPayloadCloud = new ProcessPayloadCloud({
|
||||||
name: component.processInstanceName.value,
|
name: component.processInstanceName.value,
|
||||||
ProcessDefinitionKey: component.processPayloadCloud.processDefinitionKey,
|
processDefinitionKey: component.processPayloadCloud.processDefinitionKey,
|
||||||
variables: Object.assign(component.variables, component.formCloud.values)
|
variables: Object.assign(component.variables, component.formCloud.values)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+12
-4
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
|
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
|
||||||
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
|
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
|
||||||
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
|
import { ProcessPayloadCloud, ProcessPayloadCloudData } from '../models/process-payload-cloud.model';
|
||||||
|
|
||||||
export const fakeProcessInstance: ProcessInstanceCloud = {
|
export const fakeProcessInstance: ProcessInstanceCloud = {
|
||||||
appName: 'simple-app',
|
appName: 'simple-app',
|
||||||
@@ -119,11 +119,19 @@ export const fakeNoNameProcessDefinitions: ProcessDefinitionCloud[] = [
|
|||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
export const fakeProcessPayload = new ProcessPayloadCloud({
|
export const getFakeProcessPayload = (overrides: ProcessPayloadCloudData = {}): ProcessPayloadCloud => {
|
||||||
|
const defaultData: ProcessPayloadCloudData = {
|
||||||
processDefinitionKey: 'NewProcess:1',
|
processDefinitionKey: 'NewProcess:1',
|
||||||
name: 'NewProcess 1',
|
name: 'NewProcess 1',
|
||||||
payloadType: 'string'
|
payloadType: 'string',
|
||||||
});
|
linkedProcessInstanceId: '1234',
|
||||||
|
linkedProcessInstanceType: 'type1'
|
||||||
|
};
|
||||||
|
return new ProcessPayloadCloud({
|
||||||
|
...defaultData,
|
||||||
|
...overrides
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const fakeStartForm = {
|
export const fakeStartForm = {
|
||||||
formRepresentation: {
|
formRepresentation: {
|
||||||
|
|||||||
+15
-1
@@ -15,17 +15,31 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export interface ProcessPayloadCloudData {
|
||||||
|
processDefinitionKey?: string;
|
||||||
|
name?: string;
|
||||||
|
businessKey?: string;
|
||||||
|
variables?: any;
|
||||||
|
payloadType?: string;
|
||||||
|
linkedProcessInstanceId?: string;
|
||||||
|
linkedProcessInstanceType?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class ProcessPayloadCloud {
|
export class ProcessPayloadCloud {
|
||||||
processDefinitionKey: string;
|
processDefinitionKey: string;
|
||||||
name: string;
|
name: string;
|
||||||
businessKey: string;
|
businessKey: string;
|
||||||
variables: any;
|
variables: any;
|
||||||
payloadType: string = 'StartProcessPayload';
|
payloadType: string = 'StartProcessPayload';
|
||||||
|
linkedProcessInstanceId?: string;
|
||||||
|
linkedProcessInstanceType?: string;
|
||||||
|
|
||||||
constructor(obj?: any) {
|
constructor(obj?: ProcessPayloadCloudData) {
|
||||||
this.processDefinitionKey = obj?.processDefinitionKey;
|
this.processDefinitionKey = obj?.processDefinitionKey;
|
||||||
this.name = obj?.name;
|
this.name = obj?.name;
|
||||||
this.businessKey = obj?.businessKey;
|
this.businessKey = obj?.businessKey;
|
||||||
this.variables = obj?.variables || {};
|
this.variables = obj?.variables || {};
|
||||||
|
this.linkedProcessInstanceType = obj?.linkedProcessInstanceType;
|
||||||
|
this.linkedProcessInstanceId = obj?.linkedProcessInstanceId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+62
-29
@@ -18,58 +18,89 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { firstValueFrom, of, throwError } from 'rxjs';
|
import { firstValueFrom, of, throwError } from 'rxjs';
|
||||||
import { StartProcessCloudService } from './start-process-cloud.service';
|
import { StartProcessCloudService } from './start-process-cloud.service';
|
||||||
import { fakeProcessPayload } from '../mock/start-process.component.mock';
|
import { fakeProcessInstance, fakeProcessWithFormInstance, getFakeProcessPayload } from '../mock/start-process.component.mock';
|
||||||
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
|
import { provideAppConfigTesting } from '@alfresco/adf-core';
|
||||||
import { HttpErrorResponse, HttpClientModule } from '@angular/common/http';
|
|
||||||
import { AdfHttpClient } from '@alfresco/adf-core/api';
|
import { AdfHttpClient } from '@alfresco/adf-core/api';
|
||||||
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
|
import { ProcessDefinitionCloud } from '@alfresco/adf-process-services-cloud';
|
||||||
|
|
||||||
describe('StartProcessCloudService', () => {
|
describe('StartProcessCloudService', () => {
|
||||||
let service: StartProcessCloudService;
|
let service: StartProcessCloudService;
|
||||||
let adfHttpClient: AdfHttpClient;
|
let adfHttpClient: AdfHttpClient;
|
||||||
|
let adfClientHttpRequestSpy: jasmine.Spy;
|
||||||
|
const bpmHost = 'https://adf-bpm-host.com';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [HttpClientModule]
|
providers: [
|
||||||
|
provideAppConfigTesting({
|
||||||
|
bpmHost
|
||||||
|
})
|
||||||
|
]
|
||||||
});
|
});
|
||||||
service = TestBed.inject(StartProcessCloudService);
|
service = TestBed.inject(StartProcessCloudService);
|
||||||
adfHttpClient = TestBed.inject(AdfHttpClient);
|
adfHttpClient = TestBed.inject(AdfHttpClient);
|
||||||
|
adfClientHttpRequestSpy = spyOn(adfHttpClient, 'request');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to create a new process', async () => {
|
it('should be able to create a new process', async () => {
|
||||||
spyOn(service, 'startProcess').and.returnValue(of({ id: 'fake-id', name: 'fake-name' }));
|
const appName = 'appName1';
|
||||||
const result = await firstValueFrom(service.startProcess('appName1', fakeProcessPayload));
|
const payload = getFakeProcessPayload();
|
||||||
|
const expectedPayload = getFakeProcessPayload({ payloadType: 'StartProcessPayload' });
|
||||||
|
|
||||||
expect(result).toBeDefined();
|
adfClientHttpRequestSpy.and.returnValue(Promise.resolve({ entry: fakeProcessInstance }));
|
||||||
expect(result.id).toEqual('fake-id');
|
|
||||||
expect(result.name).toEqual('fake-name');
|
const result = await firstValueFrom(service.startProcess(appName, payload));
|
||||||
|
|
||||||
|
expect(result).toEqual(fakeProcessInstance);
|
||||||
|
|
||||||
|
expect(adfClientHttpRequestSpy).toHaveBeenCalledWith(`${bpmHost}/${appName}/rb/v1/process-instances`, {
|
||||||
|
path: `${bpmHost}/${appName}/rb/v1/process-instances`,
|
||||||
|
httpMethod: 'POST',
|
||||||
|
contentTypes: ['application/json'],
|
||||||
|
accepts: ['application/json'],
|
||||||
|
bodyParam: expectedPayload,
|
||||||
|
queryParams: undefined
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to create a new process with form', async () => {
|
it('should be able to create a new process with form', async () => {
|
||||||
spyOn(service, 'startProcessWithForm').and.returnValue(of({ id: 'fake-id', name: 'fake-name' }));
|
const appName = 'appName1';
|
||||||
const result = await firstValueFrom(service.startProcessWithForm('appName1', 'mockFormId', 1, fakeProcessPayload));
|
const formId = 'mockFormId';
|
||||||
|
const payload = getFakeProcessPayload();
|
||||||
|
const expectedPayload = getFakeProcessPayload({ payloadType: 'StartProcessPayload' });
|
||||||
|
|
||||||
expect(result).toBeDefined();
|
adfClientHttpRequestSpy.and.returnValue(Promise.resolve(fakeProcessWithFormInstance));
|
||||||
expect(result.id).toEqual('fake-id');
|
|
||||||
expect(result.name).toEqual('fake-name');
|
const result = await firstValueFrom(service.startProcessWithForm(appName, formId, 1, payload));
|
||||||
|
|
||||||
|
expect(result.id).toEqual(fakeProcessWithFormInstance.id);
|
||||||
|
expect(result.name).toEqual(fakeProcessWithFormInstance.name);
|
||||||
|
|
||||||
|
expect(adfClientHttpRequestSpy).toHaveBeenCalledWith(`${bpmHost}/${appName}/form/v1/forms/${formId}/submit/versions/1`, {
|
||||||
|
path: `${bpmHost}/${appName}/form/v1/forms/${formId}/submit/versions/1`,
|
||||||
|
httpMethod: 'POST',
|
||||||
|
contentTypes: ['application/json'],
|
||||||
|
accepts: ['application/json'],
|
||||||
|
bodyParam: expectedPayload,
|
||||||
|
queryParams: undefined
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should not be able to create a process if error occurred', async () => {
|
it('should not be able to create a process if error occurred', async () => {
|
||||||
const errorResponse = new HttpErrorResponse({
|
const errorResponse = new HttpErrorResponse({
|
||||||
error: 'Mock Error',
|
error: 'Mock Error',
|
||||||
status: 404,
|
status: 404,
|
||||||
statusText: 'Not Found'
|
statusText: 'Not Found'
|
||||||
});
|
});
|
||||||
|
|
||||||
spyOn(service, 'startProcess').and.returnValue(throwError(errorResponse));
|
adfClientHttpRequestSpy.and.returnValue(Promise.reject(errorResponse));
|
||||||
const result = await firstValueFrom(service.startProcess('appName1', fakeProcessPayload)).catch((error) => {
|
|
||||||
|
await firstValueFrom(service.startProcess('appName1', getFakeProcessPayload())).catch((error) => {
|
||||||
expect(error.status).toEqual(404);
|
expect(error.status).toEqual(404);
|
||||||
expect(error.statusText).toEqual('Not Found');
|
expect(error.statusText).toEqual('Not Found');
|
||||||
expect(error.error).toEqual('Mock Error');
|
expect(error.error).toEqual('Mock Error');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result) {
|
|
||||||
fail('expected an error, not applications');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to get all the process definitions', async () => {
|
it('should be able to get all the process definitions', async () => {
|
||||||
@@ -102,8 +133,7 @@ describe('StartProcessCloudService', () => {
|
|||||||
it('should transform the response into task variables', async () => {
|
it('should transform the response into task variables', async () => {
|
||||||
const appName = 'test-app';
|
const appName = 'test-app';
|
||||||
const processDefinitionId = 'processDefinitionId';
|
const processDefinitionId = 'processDefinitionId';
|
||||||
const requestSpy = spyOn(adfHttpClient, 'request');
|
adfClientHttpRequestSpy.and.returnValue(Promise.resolve({ static1: 'value', static2: 0, static3: true }));
|
||||||
requestSpy.and.returnValue(Promise.resolve({ static1: 'value', static2: 0, static3: true }));
|
|
||||||
|
|
||||||
const result = await firstValueFrom(service.getStartEventFormStaticValuesMapping(appName, processDefinitionId));
|
const result = await firstValueFrom(service.getStartEventFormStaticValuesMapping(appName, processDefinitionId));
|
||||||
expect(result.length).toEqual(3);
|
expect(result.length).toEqual(3);
|
||||||
@@ -116,15 +146,16 @@ describe('StartProcessCloudService', () => {
|
|||||||
expect(result[2].name).toEqual('static3');
|
expect(result[2].name).toEqual('static3');
|
||||||
expect(result[2].id).toEqual('static3');
|
expect(result[2].id).toEqual('static3');
|
||||||
expect(result[2].value).toEqual(true);
|
expect(result[2].value).toEqual(true);
|
||||||
expect(requestSpy.calls.mostRecent().args[0]).toContain(`${appName}/rb/v1/process-definitions/${processDefinitionId}/static-values`);
|
expect(adfClientHttpRequestSpy.calls.mostRecent().args[0]).toContain(
|
||||||
expect(requestSpy.calls.mostRecent().args[1].httpMethod).toBe('GET');
|
`${appName}/rb/v1/process-definitions/${processDefinitionId}/static-values`
|
||||||
|
);
|
||||||
|
expect(adfClientHttpRequestSpy.calls.mostRecent().args[1].httpMethod).toBe('GET');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should transform the response into task variables when retrieving the constant values for the start event', async () => {
|
it('should transform the response into task variables when retrieving the constant values for the start event', async () => {
|
||||||
const appName = 'test-app';
|
const appName = 'test-app';
|
||||||
const processDefinitionId = 'processDefinitionId';
|
const processDefinitionId = 'processDefinitionId';
|
||||||
const requestSpy = spyOn(adfHttpClient, 'request');
|
adfClientHttpRequestSpy.and.returnValue(Promise.resolve({ constant1: 'value', constant2: '0', constant3: 'true' }));
|
||||||
requestSpy.and.returnValue(Promise.resolve({ constant1: 'value', constant2: '0', constant3: 'true' }));
|
|
||||||
|
|
||||||
const result = await firstValueFrom(service.getStartEventConstants(appName, processDefinitionId));
|
const result = await firstValueFrom(service.getStartEventConstants(appName, processDefinitionId));
|
||||||
|
|
||||||
@@ -141,7 +172,9 @@ describe('StartProcessCloudService', () => {
|
|||||||
expect(result[2].id).toEqual('constant3');
|
expect(result[2].id).toEqual('constant3');
|
||||||
expect(result[2].value).toEqual('true');
|
expect(result[2].value).toEqual('true');
|
||||||
expect(result[2].type).toEqual('string');
|
expect(result[2].type).toEqual('string');
|
||||||
expect(requestSpy.calls.mostRecent().args[0]).toContain(`${appName}/rb/v1/process-definitions/${processDefinitionId}/constant-values`);
|
expect(adfClientHttpRequestSpy.calls.mostRecent().args[0]).toContain(
|
||||||
expect(requestSpy.calls.mostRecent().args[1].httpMethod).toBe('GET');
|
`${appName}/rb/v1/process-definitions/${processDefinitionId}/constant-values`
|
||||||
|
);
|
||||||
|
expect(adfClientHttpRequestSpy.calls.mostRecent().args[1].httpMethod).toBe('GET');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user