refactor(core): Post-release refactorings of Public API (#3495)

*  Post-release refactorings

* 🧪 Add `--forceExit`

* 🛠 typing refactor (#3486)

* 🐛 Fix middleware arguments

* 👕 Fix lint

*  Restore commented out block

Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
This commit is contained in:
Iván Ovejero
2022-06-14 18:32:19 +02:00
committed by GitHub
parent 2ebcf4bb91
commit b8e3bcc052
19 changed files with 307 additions and 343 deletions

View File

@@ -1,7 +1,7 @@
import express = require('express');
import express from 'express';
import { ActiveWorkflowRunner, Db } from '../../../src';
import config = require('../../../config');
import config from '../../../config';
import { Role } from '../../../src/databases/entities/Role';
import { randomApiKey } from '../shared/random';
@@ -14,11 +14,8 @@ let testDbName = '';
let globalOwnerRole: Role;
let globalMemberRole: Role;
let workflowOwnerRole: Role;
let credentialOwnerRole: Role;
let workflowRunner: ActiveWorkflowRunner.ActiveWorkflowRunner;
jest.mock('../../../src/telemetry');
beforeAll(async () => {
app = await utils.initTestServer({ endpointGroups: ['publicApi'], applyAuth: false });
const initResult = await testDb.init();
@@ -28,13 +25,11 @@ beforeAll(async () => {
fetchedGlobalOwnerRole,
fetchedGlobalMemberRole,
fetchedWorkflowOwnerRole,
fetchedCredentialOwnerRole,
] = await testDb.getAllRoles();
globalOwnerRole = fetchedGlobalOwnerRole;
globalMemberRole = fetchedGlobalMemberRole;
workflowOwnerRole = fetchedWorkflowOwnerRole;
credentialOwnerRole = fetchedCredentialOwnerRole;
utils.initTestTelemetry();
utils.initTestLogger();
@@ -43,13 +38,13 @@ beforeAll(async () => {
});
beforeEach(async () => {
// do not combine calls - shared tables must be cleared first and separately
await testDb.truncate(['SharedCredentials', 'SharedWorkflow'], testDbName);
await testDb.truncate(['User', 'Workflow', 'Credentials'], testDbName);
await testDb.truncate(
['SharedCredentials', 'SharedWorkflow', 'User', 'Workflow', 'Credentials'],
testDbName,
);
config.set('userManagement.disabled', false);
config.set('userManagement.isInstanceOwnerSetUp', true);
config.set('userManagement.emails.mode', 'smtp');
});
afterEach(async () => {
@@ -352,7 +347,7 @@ test('GET /workflows should return all workflows for owner', async () => {
}
});
test('GET /workflows/:workflowId should fail due to missing API Key', async () => {
test('GET /workflows/:id should fail due to missing API Key', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
owner.apiKey = null;
@@ -369,7 +364,7 @@ test('GET /workflows/:workflowId should fail due to missing API Key', async () =
expect(response.statusCode).toBe(401);
});
test('GET /workflows/:workflowId should fail due to invalid API Key', async () => {
test('GET /workflows/:id should fail due to invalid API Key', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
owner.apiKey = 'abcXYZ';
@@ -386,7 +381,7 @@ test('GET /workflows/:workflowId should fail due to invalid API Key', async () =
expect(response.statusCode).toBe(401);
});
test('GET /workflows/:workflowId should fail due to non existing workflow', async () => {
test('GET /workflows/:id should fail due to non existing workflow', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const authOwnerAgent = utils.createAgent(app, {
@@ -401,7 +396,7 @@ test('GET /workflows/:workflowId should fail due to non existing workflow', asyn
expect(response.statusCode).toBe(404);
});
test('GET /workflows/:workflowId should retrieve workflow', async () => {
test('GET /workflows/:id should retrieve workflow', async () => {
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: randomApiKey() });
const authAgent = utils.createAgent(app, {
@@ -432,7 +427,7 @@ test('GET /workflows/:workflowId should retrieve workflow', async () => {
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
});
test('GET /workflows/:workflowId should retrieve non-owned workflow for owner', async () => {
test('GET /workflows/:id should retrieve non-owned workflow for owner', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const member = await testDb.createUser({ globalRole: globalMemberRole });
@@ -464,7 +459,7 @@ test('GET /workflows/:workflowId should retrieve non-owned workflow for owner',
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
});
test('DELETE /workflows/:workflowId should fail due to missing API Key', async () => {
test('DELETE /workflows/:id should fail due to missing API Key', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
const authOwnerAgent = utils.createAgent(app, {
@@ -479,7 +474,7 @@ test('DELETE /workflows/:workflowId should fail due to missing API Key', async (
expect(response.statusCode).toBe(401);
});
test('DELETE /workflows/:workflowId should fail due to invalid API Key', async () => {
test('DELETE /workflows/:id should fail due to invalid API Key', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
owner.apiKey = 'abcXYZ';
@@ -496,7 +491,7 @@ test('DELETE /workflows/:workflowId should fail due to invalid API Key', async (
expect(response.statusCode).toBe(401);
});
test('DELETE /workflows/:workflowId should fail due to non existing workflow', async () => {
test('DELETE /workflows/:id should fail due to non existing workflow', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const authOwnerAgent = utils.createAgent(app, {
@@ -511,7 +506,7 @@ test('DELETE /workflows/:workflowId should fail due to non existing workflow', a
expect(response.statusCode).toBe(404);
});
test('DELETE /workflows/:workflowId should delete the workflow', async () => {
test('DELETE /workflows/:id should delete the workflow', async () => {
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: randomApiKey() });
const authAgent = utils.createAgent(app, {
@@ -549,7 +544,7 @@ test('DELETE /workflows/:workflowId should delete the workflow', async () => {
expect(sharedWorkflow).toBeUndefined();
});
test('DELETE /workflows/:workflowId should delete non-owned workflow when owner', async () => {
test('DELETE /workflows/:id should delete non-owned workflow when owner', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const member = await testDb.createUser({ globalRole: globalMemberRole });
@@ -588,7 +583,7 @@ test('DELETE /workflows/:workflowId should delete non-owned workflow when owner'
expect(sharedWorkflow).toBeUndefined();
});
test('POST /workflows/:workflowId/activate should fail due to missing API Key', async () => {
test('POST /workflows/:id/activate should fail due to missing API Key', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
const authOwnerAgent = utils.createAgent(app, {
@@ -603,7 +598,7 @@ test('POST /workflows/:workflowId/activate should fail due to missing API Key',
expect(response.statusCode).toBe(401);
});
test('POST /workflows/:workflowId/activate should fail due to invalid API Key', async () => {
test('POST /workflows/:id/activate should fail due to invalid API Key', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
owner.apiKey = 'abcXYZ';
@@ -620,7 +615,7 @@ test('POST /workflows/:workflowId/activate should fail due to invalid API Key',
expect(response.statusCode).toBe(401);
});
test('POST /workflows/:workflowId/activate should fail due to non existing workflow', async () => {
test('POST /workflows/:id/activate should fail due to non existing workflow', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const authOwnerAgent = utils.createAgent(app, {
@@ -635,7 +630,7 @@ test('POST /workflows/:workflowId/activate should fail due to non existing workf
expect(response.statusCode).toBe(404);
});
test('POST /workflows/:workflowId/activate should fail due to trying to activate a workflow without a trigger', async () => {
test('POST /workflows/:id/activate should fail due to trying to activate a workflow without a trigger', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const authOwnerAgent = utils.createAgent(app, {
@@ -652,7 +647,7 @@ test('POST /workflows/:workflowId/activate should fail due to trying to activate
expect(response.statusCode).toBe(400);
});
test.skip('POST /workflows/:workflowId/activate should set workflow as active', async () => {
test.skip('POST /workflows/:id/activate should set workflow as active', async () => {
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: randomApiKey() });
const authAgent = utils.createAgent(app, {
@@ -696,7 +691,7 @@ test.skip('POST /workflows/:workflowId/activate should set workflow as active',
expect(await workflowRunner.isActive(workflow.id.toString())).toBe(true);
});
test.skip('POST /workflows/:workflowId/activate should set non-owned workflow as active when owner', async () => {
test.skip('POST /workflows/:id/activate should set non-owned workflow as active when owner', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const member = await testDb.createUser({ globalRole: globalMemberRole });
@@ -750,7 +745,7 @@ test.skip('POST /workflows/:workflowId/activate should set non-owned workflow as
expect(await workflowRunner.isActive(workflow.id.toString())).toBe(true);
});
test('POST /workflows/:workflowId/deactivate should fail due to missing API Key', async () => {
test('POST /workflows/:id/deactivate should fail due to missing API Key', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
const authOwnerAgent = utils.createAgent(app, {
@@ -765,7 +760,7 @@ test('POST /workflows/:workflowId/deactivate should fail due to missing API Key'
expect(response.statusCode).toBe(401);
});
test('POST /workflows/:workflowId/deactivate should fail due to invalid API Key', async () => {
test('POST /workflows/:id/deactivate should fail due to invalid API Key', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
owner.apiKey = 'abcXYZ';
@@ -782,7 +777,7 @@ test('POST /workflows/:workflowId/deactivate should fail due to invalid API Key'
expect(response.statusCode).toBe(401);
});
test('POST /workflows/:workflowId/deactivate should fail due to non existing workflow', async () => {
test('POST /workflows/:id/deactivate should fail due to non existing workflow', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const authOwnerAgent = utils.createAgent(app, {
@@ -797,7 +792,7 @@ test('POST /workflows/:workflowId/deactivate should fail due to non existing wor
expect(response.statusCode).toBe(404);
});
test('POST /workflows/:workflowId/deactivate should deactive workflow', async () => {
test('POST /workflows/:id/deactivate should deactive workflow', async () => {
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: randomApiKey() });
const authAgent = utils.createAgent(app, {
@@ -841,7 +836,7 @@ test('POST /workflows/:workflowId/deactivate should deactive workflow', async ()
expect(await workflowRunner.isActive(workflow.id.toString())).toBe(false);
});
test('POST /workflows/:workflowId/deactivate should deactive non-owned workflow when owner', async () => {
test('POST /workflows/:id/deactivate should deactive non-owned workflow when owner', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const member = await testDb.createUser({ globalRole: globalMemberRole });
@@ -904,7 +899,7 @@ test('POST /workflows should fail due to missing API Key', async () => {
version: 1,
});
const response = await authOwnerAgent.post(`/workflows`);
const response = await authOwnerAgent.post('/workflows');
expect(response.statusCode).toBe(401);
});
@@ -921,7 +916,7 @@ test('POST /workflows should fail due to invalid API Key', async () => {
version: 1,
});
const response = await authOwnerAgent.post(`/workflows`);
const response = await authOwnerAgent.post('/workflows');
expect(response.statusCode).toBe(401);
});
@@ -936,7 +931,7 @@ test('POST /workflows should fail due to invalid body', async () => {
version: 1,
});
const response = await authOwnerAgent.post(`/workflows`).send({});
const response = await authOwnerAgent.post('/workflows').send({});
expect(response.statusCode).toBe(400);
});
@@ -974,7 +969,7 @@ test('POST /workflows should create workflow', async () => {
},
};
const response = await authAgent.post(`/workflows`).send(payload);
const response = await authAgent.post('/workflows').send(payload);
expect(response.statusCode).toBe(200);
@@ -1005,7 +1000,7 @@ test('POST /workflows should create workflow', async () => {
expect(sharedWorkflow?.role).toEqual(workflowOwnerRole);
});
test('PUT /workflows/:workflowId should fail due to missing API Key', async () => {
test('PUT /workflows/:id should fail due to missing API Key', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
const authOwnerAgent = utils.createAgent(app, {
@@ -1020,7 +1015,7 @@ test('PUT /workflows/:workflowId should fail due to missing API Key', async () =
expect(response.statusCode).toBe(401);
});
test('PUT /workflows/:workflowId should fail due to invalid API Key', async () => {
test('PUT /workflows/:id should fail due to invalid API Key', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
owner.apiKey = 'abcXYZ';
@@ -1037,7 +1032,7 @@ test('PUT /workflows/:workflowId should fail due to invalid API Key', async () =
expect(response.statusCode).toBe(401);
});
test('PUT /workflows/:workflowId should fail due to non existing workflow', async () => {
test('PUT /workflows/:id should fail due to non existing workflow', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const authOwnerAgent = utils.createAgent(app, {
@@ -1073,7 +1068,7 @@ test('PUT /workflows/:workflowId should fail due to non existing workflow', asyn
expect(response.statusCode).toBe(404);
});
test('PUT /workflows/:workflowId should fail due to invalid body', async () => {
test('PUT /workflows/:id should fail due to invalid body', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const authOwnerAgent = utils.createAgent(app, {
@@ -1108,7 +1103,7 @@ test('PUT /workflows/:workflowId should fail due to invalid body', async () => {
expect(response.statusCode).toBe(400);
});
test('PUT /workflows/:workflowId should update workflow', async () => {
test('PUT /workflows/:id should update workflow', async () => {
const member = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const workflow = await testDb.createWorkflow({}, member);
@@ -1182,7 +1177,7 @@ test('PUT /workflows/:workflowId should update workflow', async () => {
);
});
test('PUT /workflows/:workflowId should update non-owned workflow if owner', async () => {
test('PUT /workflows/:id should update non-owned workflow if owner', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
const member = await testDb.createUser({ globalRole: globalMemberRole });