mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
migrate js-api tests from Jest to Node.js native test runner (#12104)
This commit is contained in:
@@ -16,8 +16,10 @@
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { resetGlobalMockAgent } from '../mockObjects/base.mock';
|
||||
import { BpmAuthMock, ProcessInstanceVariablesMock } from '../mockObjects';
|
||||
import { ProcessInstanceVariablesApi, AlfrescoApi } from '../../src';
|
||||
import { describe, it, beforeEach, afterEach } from 'node:test';
|
||||
|
||||
describe('Activiti Process Instance Variables Api', () => {
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
@@ -25,10 +27,6 @@ describe('Activiti Process Instance Variables Api', () => {
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
let processInstanceVariablesApi: ProcessInstanceVariablesApi;
|
||||
|
||||
const NOOP = () => {
|
||||
/* empty */
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const BPM_HOST = 'https://127.0.0.1:9999';
|
||||
|
||||
@@ -47,128 +45,129 @@ describe('Activiti Process Instance Variables Api', () => {
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
resetGlobalMockAgent();
|
||||
});
|
||||
|
||||
describe('get variables', () => {
|
||||
it('should return all variables for a process instance', (done) => {
|
||||
it('should return all variables for a process instance', async () => {
|
||||
const processInstanceId = '111';
|
||||
variablesMock.addListProcessInstanceVariables200Response(processInstanceId);
|
||||
|
||||
processInstanceVariablesApi.getProcessInstanceVariables(processInstanceId).then((data) => {
|
||||
assert.equal(data.length, 2);
|
||||
done();
|
||||
});
|
||||
const data = await processInstanceVariablesApi.getProcessInstanceVariables(processInstanceId);
|
||||
assert.equal(data.length, 2);
|
||||
});
|
||||
|
||||
it('should emit an error when API returns an error response', (done) => {
|
||||
it('should emit an error when API returns an error response', async () => {
|
||||
const processInstanceId = '111';
|
||||
variablesMock.addListProcessInstanceVariables500Response(processInstanceId);
|
||||
|
||||
processInstanceVariablesApi.getProcessInstanceVariables(processInstanceId).then(NOOP, (error) => {
|
||||
try {
|
||||
await processInstanceVariablesApi.getProcessInstanceVariables(processInstanceId);
|
||||
assert.fail('Expected getProcessInstanceVariables to throw error on 500 response');
|
||||
} catch (error: any) {
|
||||
assert.equal(error.status, 500);
|
||||
assert.equal(error.message, '{"messageKey":"UNKNOWN","message":"Unknown error"}');
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('create or update variables', () => {
|
||||
it('should return all variables for a process instance', (done) => {
|
||||
it('should return all variables for a process instance', async () => {
|
||||
const processInstanceId = '111';
|
||||
variablesMock.addPutProcessInstanceVariables200Response(processInstanceId);
|
||||
|
||||
processInstanceVariablesApi.createOrUpdateProcessInstanceVariables(processInstanceId, []).then((data) => {
|
||||
assert.equal(data.length, 2);
|
||||
done();
|
||||
});
|
||||
const data = await processInstanceVariablesApi.createOrUpdateProcessInstanceVariables(processInstanceId, []);
|
||||
assert.equal(data.length, 2);
|
||||
});
|
||||
|
||||
it('should emit an error when API returns an error response', (done) => {
|
||||
it('should emit an error when API returns an error response', async () => {
|
||||
const processInstanceId = '111';
|
||||
variablesMock.addPutProcessInstanceVariables500Response(processInstanceId);
|
||||
|
||||
processInstanceVariablesApi.createOrUpdateProcessInstanceVariables(processInstanceId, []).then(NOOP, (error) => {
|
||||
try {
|
||||
await processInstanceVariablesApi.createOrUpdateProcessInstanceVariables(processInstanceId, []);
|
||||
assert.fail('Expected createOrUpdateProcessInstanceVariables to throw error on 500 response');
|
||||
} catch (error: any) {
|
||||
assert.equal(error.status, 500);
|
||||
assert.equal(error.message, '{"messageKey":"UNKNOWN","message":"Unknown error"}');
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('get variable', () => {
|
||||
it('should call API to get variable', (done) => {
|
||||
it('should call API to get variable', async () => {
|
||||
const processInstanceId = '111';
|
||||
const variableName = 'var1';
|
||||
variablesMock.addGetProcessInstanceVariable200Response(processInstanceId, variableName);
|
||||
|
||||
processInstanceVariablesApi.getProcessInstanceVariable(processInstanceId, variableName).then(
|
||||
(data) => {
|
||||
assert.equal(data.name, 'variable1');
|
||||
assert.equal(data.value, 'Value 123');
|
||||
done();
|
||||
},
|
||||
() => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
const data = await processInstanceVariablesApi.getProcessInstanceVariable(processInstanceId, variableName);
|
||||
assert.equal(data.name, 'variable1');
|
||||
assert.equal(data.value, 'Value 123');
|
||||
});
|
||||
|
||||
it('should emit an error when API returns an error response', (done) => {
|
||||
it('should emit an error when API returns an error response', async () => {
|
||||
const processInstanceId = '111';
|
||||
const variableName = 'var1';
|
||||
variablesMock.addGetProcessInstanceVariable500Response(processInstanceId, variableName);
|
||||
|
||||
processInstanceVariablesApi.getProcessInstanceVariable(processInstanceId, variableName).then(NOOP, (error) => {
|
||||
try {
|
||||
await processInstanceVariablesApi.getProcessInstanceVariable(processInstanceId, variableName);
|
||||
assert.fail('Expected getProcessInstanceVariable to throw error on 500 response');
|
||||
} catch (error: any) {
|
||||
assert.equal(error.status, 500);
|
||||
assert.equal(error.message, '{"messageKey":"UNKNOWN","message":"Unknown error"}');
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('update variable', () => {
|
||||
it('should call API to update variable', (done) => {
|
||||
it('should call API to update variable', async () => {
|
||||
const processInstanceId = '111';
|
||||
const variableName = 'var1';
|
||||
variablesMock.addUpdateProcessInstanceVariable200Response(processInstanceId, variableName);
|
||||
|
||||
processInstanceVariablesApi.updateProcessInstanceVariable(processInstanceId, variableName, {}).then(() => {
|
||||
done();
|
||||
});
|
||||
const result = await processInstanceVariablesApi.updateProcessInstanceVariable(processInstanceId, variableName, {});
|
||||
assert.ok(result !== undefined, 'updateProcessInstanceVariable should complete successfully');
|
||||
});
|
||||
|
||||
it('should emit an error when API returns an error response', (done) => {
|
||||
it('should emit an error when API returns an error response', async () => {
|
||||
const processInstanceId = '111';
|
||||
const variableName = 'var1';
|
||||
variablesMock.addUpdateProcessInstanceVariable500Response(processInstanceId, variableName);
|
||||
|
||||
processInstanceVariablesApi.updateProcessInstanceVariable(processInstanceId, variableName, {}).then(NOOP, (error) => {
|
||||
try {
|
||||
await processInstanceVariablesApi.updateProcessInstanceVariable(processInstanceId, variableName, {});
|
||||
assert.fail('Expected updateProcessInstanceVariable to throw error on 500 response');
|
||||
} catch (error: any) {
|
||||
assert.equal(error.status, 500);
|
||||
assert.equal(error.message, '{"messageKey":"UNKNOWN","message":"Unknown error"}');
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('delete variable', () => {
|
||||
it('should call API to delete variables', (done) => {
|
||||
it('should call API to delete variables', async () => {
|
||||
const processInstanceId = '111';
|
||||
const variableName = 'var1';
|
||||
variablesMock.addDeleteProcessInstanceVariable200Response(processInstanceId, variableName);
|
||||
|
||||
processInstanceVariablesApi.deleteProcessInstanceVariable(processInstanceId, variableName).then(() => {
|
||||
done();
|
||||
});
|
||||
const result = await processInstanceVariablesApi.deleteProcessInstanceVariable(processInstanceId, variableName);
|
||||
assert.ok(result !== undefined, 'deleteProcessInstanceVariable should complete successfully');
|
||||
});
|
||||
|
||||
it('should emit an error when API returns an error response', (done) => {
|
||||
it('should emit an error when API returns an error response', async () => {
|
||||
const processInstanceId = '111';
|
||||
const variableName = 'var1';
|
||||
variablesMock.addDeleteProcessInstanceVariable500Response(processInstanceId, variableName);
|
||||
|
||||
processInstanceVariablesApi.deleteProcessInstanceVariable(processInstanceId, variableName).then(NOOP, (error) => {
|
||||
try {
|
||||
await processInstanceVariablesApi.deleteProcessInstanceVariable(processInstanceId, variableName);
|
||||
assert.fail('Expected deleteProcessInstanceVariable to throw error on 500 response');
|
||||
} catch (error: any) {
|
||||
assert.equal(error.status, 500);
|
||||
assert.equal(error.message, '{"messageKey":"UNKNOWN","message":"Unknown error"}');
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user