mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[AAE-11588] Send Process Variables as a post body in admin process instances (#8067)
* [AAE-11588] Send variable keys as a post body in admin process instances * [AAE-11588] Add tests * [AAE-11588] Add async/await functionality to test suite * [AEE-11588] Improve logic in service and added test cases
This commit is contained in:
parent
0c4d48e2e9
commit
eb27d38eba
@ -39,6 +39,20 @@ describe('ProcessListCloudService', () => {
|
||||
isEcmLoggedIn: () => false
|
||||
});
|
||||
|
||||
const returnCallOperation = (): any => ({
|
||||
oauth2Auth: {
|
||||
callCustomApi: (_queryUrl, operation, _context, _queryParams) => Promise.resolve(operation)
|
||||
},
|
||||
isEcmLoggedIn: () => false
|
||||
});
|
||||
|
||||
const returnCallBody = (): any => ({
|
||||
oauth2Auth: {
|
||||
callCustomApi: (_queryUrl, _operation, _context, _queryParams, _headerParams, _formParams, bodyParam) => Promise.resolve(bodyParam)
|
||||
},
|
||||
isEcmLoggedIn: () => false
|
||||
});
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
ProcessServiceCloudTestingModule
|
||||
@ -99,4 +113,87 @@ describe('ProcessListCloudService', () => {
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('getAdminProcessRequest', () => {
|
||||
|
||||
it('should append to the call all the parameters', async () => {
|
||||
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel;
|
||||
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallQueryParameters);
|
||||
const request = await service.getAdminProcessByRequest(processRequest).toPromise();
|
||||
|
||||
expect(request).toBeDefined();
|
||||
expect(request).not.toBeNull();
|
||||
expect(request.skipCount).toBe(0);
|
||||
expect(request.maxItems).toBe(20);
|
||||
expect(request.service).toBe('fake-service');
|
||||
});
|
||||
|
||||
it('should concat the app name to the request url', async () => {
|
||||
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel;
|
||||
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallUrl);
|
||||
const requestUrl = await service.getAdminProcessByRequest(processRequest).toPromise();
|
||||
|
||||
expect(requestUrl).toBeDefined();
|
||||
expect(requestUrl).not.toBeNull();
|
||||
expect(requestUrl).toContain('/fakeName/query/admin/v1/process-instances');
|
||||
});
|
||||
|
||||
it('should concat the sorting to append as parameters', async () => {
|
||||
const processRequest = {
|
||||
appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service',
|
||||
sorting: [{ orderBy: 'NAME', direction: 'DESC' }, { orderBy: 'TITLE', direction: 'ASC' }]
|
||||
} as ProcessQueryCloudRequestModel;
|
||||
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallQueryParameters);
|
||||
const request = await service.getAdminProcessByRequest(processRequest).toPromise();
|
||||
|
||||
expect(request).toBeDefined();
|
||||
expect(request).not.toBeNull();
|
||||
expect(request.sort).toBe('NAME,DESC&TITLE,ASC');
|
||||
});
|
||||
|
||||
it('should return an error when app name is not specified', async () => {
|
||||
const processRequest = { appName: null } as ProcessQueryCloudRequestModel;
|
||||
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallUrl);
|
||||
|
||||
try {
|
||||
await service.getAdminProcessByRequest(processRequest).toPromise();
|
||||
|
||||
fail('Should have thrown error');
|
||||
} catch(error) {
|
||||
expect(error).toBe('Appname not configured');
|
||||
}
|
||||
});
|
||||
|
||||
it('should make post request', async () => {
|
||||
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel;
|
||||
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallOperation);
|
||||
const requestMethod = await service.getAdminProcessByRequest(processRequest).toPromise();
|
||||
expect(requestMethod).toBeDefined();
|
||||
expect(requestMethod).not.toBeNull();
|
||||
expect(requestMethod).toBe('POST');
|
||||
});
|
||||
|
||||
it('should not have variable keys as part of query parameters', async () => {
|
||||
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service', variableKeys: ['test-one', 'test-two'] } as ProcessQueryCloudRequestModel;
|
||||
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallQueryParameters);
|
||||
const requestParams = await service.getAdminProcessByRequest(processRequest).toPromise();
|
||||
|
||||
expect(requestParams).toBeDefined();
|
||||
expect(requestParams).not.toBeNull();
|
||||
expect(requestParams.variableKeys).not.toBeDefined();
|
||||
});
|
||||
|
||||
it('should send right variable keys as post body', async () => {
|
||||
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service', variableKeys: ['test-one', 'test-two'] } as ProcessQueryCloudRequestModel;
|
||||
spyOn(alfrescoApiService, 'getInstance').and.callFake(returnCallBody);
|
||||
const requestBodyParams = await service.getAdminProcessByRequest(processRequest).toPromise();
|
||||
|
||||
expect(requestBodyParams).toBeDefined();
|
||||
expect(requestBodyParams).not.toBeNull();
|
||||
expect(requestBodyParams.variableKeys).toBeDefined();
|
||||
expect(requestBodyParams.variableKeys.length).toBe(2);
|
||||
expect(requestBodyParams.variableKeys[0]).toBe('test-one');
|
||||
expect(requestBodyParams.variableKeys[1]).toBe('test-two');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -32,23 +32,21 @@ export class ProcessListCloudService extends BaseCloudService {
|
||||
super(apiService, appConfigService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a process using an object with optional query properties.
|
||||
*
|
||||
* @param requestNode Query object
|
||||
* @param queryUrl Query url
|
||||
* @returns Process information
|
||||
*/
|
||||
getProcessByRequest(requestNode: ProcessQueryCloudRequestModel, queryUrl?: string): Observable<any> {
|
||||
private getProcess(
|
||||
callback: (queryUrl: string, queryParams: any) => Observable<any>,
|
||||
defaultQueryUrl: string,
|
||||
requestNode: ProcessQueryCloudRequestModel,
|
||||
queryUrl?: string
|
||||
): Observable<any> {
|
||||
if (requestNode.appName || requestNode.appName === '') {
|
||||
queryUrl = queryUrl || `${this.getBasePath(requestNode.appName)}/query/v1/process-instances`;
|
||||
queryUrl = queryUrl || `${this.getBasePath(requestNode.appName)}/${defaultQueryUrl}`;
|
||||
const queryParams = this.buildQueryParams(requestNode);
|
||||
const sortingParams = this.buildSortingParam(requestNode.sorting);
|
||||
if (sortingParams) {
|
||||
queryParams['sort'] = sortingParams;
|
||||
}
|
||||
|
||||
return this.get(queryUrl, queryParams).pipe(
|
||||
return callback(queryUrl, queryParams).pipe(
|
||||
map((response: any) => {
|
||||
const entries = response.list && response.list.entries;
|
||||
if (entries) {
|
||||
@ -63,6 +61,51 @@ export class ProcessListCloudService extends BaseCloudService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a process using an object with optional query properties.
|
||||
*
|
||||
* @param requestNode Query object
|
||||
* @param queryUrl Query url
|
||||
* @returns Process information
|
||||
*/
|
||||
getProcessByRequest(requestNode: ProcessQueryCloudRequestModel, queryUrl?: string): Observable<any> {
|
||||
const callback = (url: string, queryParams: any) => this.get(url, queryParams);
|
||||
const defaultQueryUrl = 'query/v1/process-instances';
|
||||
|
||||
return this.getProcess(callback, defaultQueryUrl, requestNode, queryUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a process using an object with optional query properties in admin app.
|
||||
*
|
||||
* @param requestNode Query object
|
||||
* @param queryUrl Query url
|
||||
* @returns Process information
|
||||
*/
|
||||
getAdminProcessByRequest(requestNode: ProcessQueryCloudRequestModel, queryUrl?: string): Observable<any> {
|
||||
const callback = (url: string, params: any) => {
|
||||
const postBody = {
|
||||
variableKeys: this.getVariableKeysFromQueryParams(params)
|
||||
};
|
||||
|
||||
delete params['variableKeys'];
|
||||
|
||||
return this.post(url, postBody, params);
|
||||
};
|
||||
|
||||
const defaultQueryUrl = 'query/admin/v1/process-instances';
|
||||
|
||||
return this.getProcess(callback, defaultQueryUrl, requestNode, queryUrl);
|
||||
}
|
||||
|
||||
private getVariableKeysFromQueryParams(queryParams: any): string[] {
|
||||
if (!queryParams['variableKeys'] || queryParams['variableKeys'].length <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return queryParams['variableKeys'].split(',');
|
||||
}
|
||||
|
||||
protected isPropertyValueValid(requestNode: any, property: string): boolean {
|
||||
return requestNode[property] !== '' && requestNode[property] !== null && requestNode[property] !== undefined;
|
||||
}
|
||||
|
@ -52,13 +52,14 @@ export class BaseCloudService {
|
||||
: this.contextRoot;
|
||||
}
|
||||
|
||||
protected post<T, R>(url: string, data?: T): Observable<R> {
|
||||
protected post<T, R>(url: string, data?: T, queryParams?: any): Observable<R> {
|
||||
return from(
|
||||
this.callApi<R>({
|
||||
...this.defaultParams,
|
||||
path: url,
|
||||
httpMethod: 'POST',
|
||||
bodyParam: data
|
||||
bodyParam: data,
|
||||
queryParams
|
||||
})
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user