n8n 0.178.2 → 0.181.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/export/workflow.js +4 -1
- package/dist/commands/export/workflow.js.map +1 -1
- package/dist/commands/import/workflow.js +22 -5
- package/dist/commands/import/workflow.js.map +1 -1
- package/dist/commands/worker.js +3 -2
- package/dist/commands/worker.js.map +1 -1
- package/dist/config/index.d.ts +4 -0
- package/dist/config/schema.d.ts +14 -0
- package/dist/config/schema.js +16 -2
- package/dist/config/schema.js.map +1 -1
- package/dist/src/ActiveWorkflowRunner.d.ts +2 -1
- package/dist/src/ActiveWorkflowRunner.js +66 -6
- package/dist/src/ActiveWorkflowRunner.js.map +1 -1
- package/dist/src/CredentialsHelper.d.ts +2 -0
- package/dist/src/CredentialsHelper.js +13 -5
- package/dist/src/CredentialsHelper.js.map +1 -1
- package/dist/src/Interfaces.d.ts +41 -6
- package/dist/src/InternalHooks.d.ts +46 -4
- package/dist/src/InternalHooks.js +36 -6
- package/dist/src/InternalHooks.js.map +1 -1
- package/dist/src/PublicApi/index.d.ts +5 -0
- package/dist/src/PublicApi/index.js +122 -0
- package/dist/src/PublicApi/index.js.map +1 -0
- package/dist/src/PublicApi/swaggerTheme.css +26 -0
- package/dist/src/PublicApi/v1/handlers/credentials/credentials.handler.d.ts +7 -0
- package/dist/src/PublicApi/v1/handlers/credentials/credentials.handler.js +72 -0
- package/dist/src/PublicApi/v1/handlers/credentials/credentials.handler.js.map +1 -0
- package/dist/src/PublicApi/v1/handlers/credentials/credentials.middleware.d.ts +3 -0
- package/dist/src/PublicApi/v1/handlers/credentials/credentials.middleware.js +34 -0
- package/dist/src/PublicApi/v1/handlers/credentials/credentials.middleware.js.map +1 -0
- package/dist/src/PublicApi/v1/handlers/credentials/credentials.service.d.ts +14 -0
- package/dist/src/PublicApi/v1/handlers/credentials/credentials.service.js +180 -0
- package/dist/src/PublicApi/v1/handlers/credentials/credentials.service.js.map +1 -0
- package/dist/src/PublicApi/v1/handlers/executions/executions.handler.d.ts +8 -0
- package/dist/src/PublicApi/v1/handlers/executions/executions.handler.js +97 -0
- package/dist/src/PublicApi/v1/handlers/executions/executions.handler.js.map +1 -0
- package/dist/src/PublicApi/v1/handlers/executions/executions.service.d.ts +19 -0
- package/dist/src/PublicApi/v1/handlers/executions/executions.service.js +80 -0
- package/dist/src/PublicApi/v1/handlers/executions/executions.service.js.map +1 -0
- package/dist/src/PublicApi/v1/handlers/users/users.service.d.ts +4 -0
- package/dist/src/PublicApi/v1/handlers/users/users.service.js +16 -0
- package/dist/src/PublicApi/v1/handlers/users/users.service.js.map +1 -0
- package/dist/src/PublicApi/v1/handlers/workflows/workflows.handler.d.ts +12 -0
- package/dist/src/PublicApi/v1/handlers/workflows/workflows.handler.js +199 -0
- package/dist/src/PublicApi/v1/handlers/workflows/workflows.handler.js.map +1 -0
- package/dist/src/PublicApi/v1/handlers/workflows/workflows.service.d.ts +24 -0
- package/dist/src/PublicApi/v1/handlers/workflows/workflows.service.js +113 -0
- package/dist/src/PublicApi/v1/handlers/workflows/workflows.service.js.map +1 -0
- package/dist/src/PublicApi/v1/openapi.yml +703 -0
- package/dist/src/PublicApi/v1/shared/middlewares/global.middleware.d.ts +5 -0
- package/dist/src/PublicApi/v1/shared/middlewares/global.middleware.js +38 -0
- package/dist/src/PublicApi/v1/shared/middlewares/global.middleware.js.map +1 -0
- package/dist/src/PublicApi/v1/shared/services/pagination.service.d.ts +3 -0
- package/dist/src/PublicApi/v1/shared/services/pagination.service.js +33 -0
- package/dist/src/PublicApi/v1/shared/services/pagination.service.js.map +1 -0
- package/dist/src/ResponseHelper.d.ts +1 -1
- package/dist/src/ResponseHelper.js +2 -2
- package/dist/src/ResponseHelper.js.map +1 -1
- package/dist/src/Server.js +29 -13
- package/dist/src/Server.js.map +1 -1
- package/dist/src/TagHelpers.d.ts +3 -1
- package/dist/src/TagHelpers.js +47 -1
- package/dist/src/TagHelpers.js.map +1 -1
- package/dist/src/UserManagement/UserManagementHelper.js +1 -1
- package/dist/src/UserManagement/UserManagementHelper.js.map +1 -1
- package/dist/src/UserManagement/auth/jwt.d.ts +1 -1
- package/dist/src/UserManagement/routes/me.js +27 -0
- package/dist/src/UserManagement/routes/me.js.map +1 -1
- package/dist/src/UserManagement/routes/passwordReset.js +2 -0
- package/dist/src/UserManagement/routes/passwordReset.js.map +1 -1
- package/dist/src/UserManagement/routes/users.js +7 -1
- package/dist/src/UserManagement/routes/users.js.map +1 -1
- package/dist/src/WebhookHelpers.js +8 -7
- package/dist/src/WebhookHelpers.js.map +1 -1
- package/dist/src/WebhookServer.js.map +1 -1
- package/dist/src/WorkflowExecuteAdditionalData.d.ts +2 -1
- package/dist/src/WorkflowExecuteAdditionalData.js +45 -16
- package/dist/src/WorkflowExecuteAdditionalData.js.map +1 -1
- package/dist/src/WorkflowHelpers.js +2 -0
- package/dist/src/WorkflowHelpers.js.map +1 -1
- package/dist/src/WorkflowRunner.js +2 -0
- package/dist/src/WorkflowRunner.js.map +1 -1
- package/dist/src/api/credentials.api.js +4 -3
- package/dist/src/api/credentials.api.js.map +1 -1
- package/dist/src/databases/entities/User.d.ts +1 -0
- package/dist/src/databases/entities/User.js +7 -2
- package/dist/src/databases/entities/User.js.map +1 -1
- package/dist/src/databases/mysqldb/migrations/1652905585850-AddAPIKeyColumn.d.ts +6 -0
- package/dist/src/databases/mysqldb/migrations/1652905585850-AddAPIKeyColumn.js +28 -0
- package/dist/src/databases/mysqldb/migrations/1652905585850-AddAPIKeyColumn.js.map +1 -0
- package/dist/src/databases/mysqldb/migrations/index.js +2 -0
- package/dist/src/databases/mysqldb/migrations/index.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1587669153312-InitialMigration.js +2 -0
- package/dist/src/databases/postgresdb/migrations/1587669153312-InitialMigration.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1589476000887-WebhookModel.js +2 -0
- package/dist/src/databases/postgresdb/migrations/1589476000887-WebhookModel.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1594828256133-CreateIndexStoppedAt.js +9 -2
- package/dist/src/databases/postgresdb/migrations/1594828256133-CreateIndexStoppedAt.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1607431743768-MakeStoppedAtNullable.js +1 -0
- package/dist/src/databases/postgresdb/migrations/1607431743768-MakeStoppedAtNullable.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1611144599516-AddWebhookId.js +2 -0
- package/dist/src/databases/postgresdb/migrations/1611144599516-AddWebhookId.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1617270242566-CreateTagEntity.js +2 -0
- package/dist/src/databases/postgresdb/migrations/1617270242566-CreateTagEntity.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1620824779533-UniqueWorkflowNames.js +2 -0
- package/dist/src/databases/postgresdb/migrations/1620824779533-UniqueWorkflowNames.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1626176912946-AddwaitTill.js +2 -0
- package/dist/src/databases/postgresdb/migrations/1626176912946-AddwaitTill.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1630419189837-UpdateWorkflowCredentials.js +2 -0
- package/dist/src/databases/postgresdb/migrations/1630419189837-UpdateWorkflowCredentials.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1644422880309-AddExecutionEntityIndexes.js +7 -6
- package/dist/src/databases/postgresdb/migrations/1644422880309-AddExecutionEntityIndexes.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1646834195327-IncreaseTypeVarcharLimit.js +6 -1
- package/dist/src/databases/postgresdb/migrations/1646834195327-IncreaseTypeVarcharLimit.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1646992772331-CreateUserManagement.js +5 -3
- package/dist/src/databases/postgresdb/migrations/1646992772331-CreateUserManagement.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1648740597343-LowerCaseUserEmail.js +1 -0
- package/dist/src/databases/postgresdb/migrations/1648740597343-LowerCaseUserEmail.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1652367743993-AddUserSettings.js +2 -0
- package/dist/src/databases/postgresdb/migrations/1652367743993-AddUserSettings.js.map +1 -1
- package/dist/src/databases/postgresdb/migrations/1652905585850-AddAPIKeyColumn.d.ts +6 -0
- package/dist/src/databases/postgresdb/migrations/1652905585850-AddAPIKeyColumn.js +32 -0
- package/dist/src/databases/postgresdb/migrations/1652905585850-AddAPIKeyColumn.js.map +1 -0
- package/dist/src/databases/postgresdb/migrations/index.js +2 -0
- package/dist/src/databases/postgresdb/migrations/index.js.map +1 -1
- package/dist/src/databases/sqlite/migrations/1652905585850-AddAPIKeyColumn.d.ts +6 -0
- package/dist/src/databases/sqlite/migrations/1652905585850-AddAPIKeyColumn.js +58 -0
- package/dist/src/databases/sqlite/migrations/1652905585850-AddAPIKeyColumn.js.map +1 -0
- package/dist/src/databases/sqlite/migrations/index.js +2 -0
- package/dist/src/databases/sqlite/migrations/index.js.map +1 -1
- package/dist/test/integration/auth.api.test.js +11 -6
- package/dist/test/integration/auth.api.test.js.map +1 -1
- package/dist/test/integration/auth.mw.test.js +1 -1
- package/dist/test/integration/auth.mw.test.js.map +1 -1
- package/dist/test/integration/commands/reset.cmd.test.d.ts +1 -0
- package/dist/test/integration/commands/reset.cmd.test.js +59 -0
- package/dist/test/integration/commands/reset.cmd.test.js.map +1 -0
- package/dist/test/integration/credentials.api.test.js +1 -1
- package/dist/test/integration/credentials.api.test.js.map +1 -1
- package/dist/test/integration/me.api.test.js +78 -7
- package/dist/test/integration/me.api.test.js.map +1 -1
- package/dist/test/integration/owner.api.test.js +3 -2
- package/dist/test/integration/owner.api.test.js.map +1 -1
- package/dist/test/integration/passwordReset.api.test.js +1 -1
- package/dist/test/integration/passwordReset.api.test.js.map +1 -1
- package/dist/test/integration/publicApi/credentials.test.d.ts +1 -0
- package/dist/test/integration/publicApi/credentials.test.js +321 -0
- package/dist/test/integration/publicApi/credentials.test.js.map +1 -0
- package/dist/test/integration/publicApi/executions.test.d.ts +1 -0
- package/dist/test/integration/publicApi/executions.test.js +289 -0
- package/dist/test/integration/publicApi/executions.test.js.map +1 -0
- package/dist/test/integration/publicApi/workflows.test.d.ts +1 -0
- package/dist/test/integration/publicApi/workflows.test.js +948 -0
- package/dist/test/integration/publicApi/workflows.test.js.map +1 -0
- package/dist/test/integration/shared/constants.d.ts +1 -0
- package/dist/test/integration/shared/constants.js +2 -1
- package/dist/test/integration/shared/constants.js.map +1 -1
- package/dist/test/integration/shared/random.d.ts +1 -0
- package/dist/test/integration/shared/random.js +8 -2
- package/dist/test/integration/shared/random.js.map +1 -1
- package/dist/test/integration/shared/testDb.d.ts +115 -4
- package/dist/test/integration/shared/testDb.js +132 -10
- package/dist/test/integration/shared/testDb.js.map +1 -1
- package/dist/test/integration/shared/utils.d.ts +206 -3
- package/dist/test/integration/shared/utils.js +582 -18
- package/dist/test/integration/shared/utils.js.map +1 -1
- package/dist/test/integration/users.api.test.js +6 -4
- package/dist/test/integration/users.api.test.js.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +22 -15
|
@@ -0,0 +1,948 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const src_1 = require("../../../src");
|
|
27
|
+
const config = require("../../../config");
|
|
28
|
+
const random_1 = require("../shared/random");
|
|
29
|
+
const utils = __importStar(require("../shared/utils"));
|
|
30
|
+
const testDb = __importStar(require("../shared/testDb"));
|
|
31
|
+
let app;
|
|
32
|
+
let testDbName = '';
|
|
33
|
+
let globalOwnerRole;
|
|
34
|
+
let globalMemberRole;
|
|
35
|
+
let workflowOwnerRole;
|
|
36
|
+
let credentialOwnerRole;
|
|
37
|
+
let workflowRunner;
|
|
38
|
+
jest.mock('../../../src/telemetry');
|
|
39
|
+
beforeAll(async () => {
|
|
40
|
+
app = await utils.initTestServer({ endpointGroups: ['publicApi'], applyAuth: false });
|
|
41
|
+
const initResult = await testDb.init();
|
|
42
|
+
testDbName = initResult.testDbName;
|
|
43
|
+
const [fetchedGlobalOwnerRole, fetchedGlobalMemberRole, fetchedWorkflowOwnerRole, fetchedCredentialOwnerRole,] = await testDb.getAllRoles();
|
|
44
|
+
globalOwnerRole = fetchedGlobalOwnerRole;
|
|
45
|
+
globalMemberRole = fetchedGlobalMemberRole;
|
|
46
|
+
workflowOwnerRole = fetchedWorkflowOwnerRole;
|
|
47
|
+
credentialOwnerRole = fetchedCredentialOwnerRole;
|
|
48
|
+
utils.initTestTelemetry();
|
|
49
|
+
utils.initTestLogger();
|
|
50
|
+
await utils.initNodeTypes();
|
|
51
|
+
workflowRunner = await utils.initActiveWorkflowRunner();
|
|
52
|
+
});
|
|
53
|
+
beforeEach(async () => {
|
|
54
|
+
await testDb.truncate(['SharedCredentials', 'SharedWorkflow'], testDbName);
|
|
55
|
+
await testDb.truncate(['User', 'Workflow', 'Credentials'], testDbName);
|
|
56
|
+
config.set('userManagement.disabled', false);
|
|
57
|
+
config.set('userManagement.isInstanceOwnerSetUp', true);
|
|
58
|
+
config.set('userManagement.emails.mode', 'smtp');
|
|
59
|
+
});
|
|
60
|
+
afterEach(async () => {
|
|
61
|
+
await workflowRunner.removeAll();
|
|
62
|
+
});
|
|
63
|
+
afterAll(async () => {
|
|
64
|
+
await testDb.terminate(testDbName);
|
|
65
|
+
});
|
|
66
|
+
test('GET /workflows should fail due to missing API Key', async () => {
|
|
67
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
|
68
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
69
|
+
apiPath: 'public',
|
|
70
|
+
auth: true,
|
|
71
|
+
user: owner,
|
|
72
|
+
version: 1,
|
|
73
|
+
});
|
|
74
|
+
const response = await authOwnerAgent.get('/workflows');
|
|
75
|
+
expect(response.statusCode).toBe(401);
|
|
76
|
+
});
|
|
77
|
+
test('GET /workflows should fail due to invalid API Key', async () => {
|
|
78
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
79
|
+
owner.apiKey = 'abcXYZ';
|
|
80
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
81
|
+
apiPath: 'public',
|
|
82
|
+
auth: true,
|
|
83
|
+
user: owner,
|
|
84
|
+
version: 1,
|
|
85
|
+
});
|
|
86
|
+
const response = await authOwnerAgent.get('/workflows');
|
|
87
|
+
expect(response.statusCode).toBe(401);
|
|
88
|
+
});
|
|
89
|
+
test('GET /workflows should return all owned workflows', async () => {
|
|
90
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: (0, random_1.randomApiKey)() });
|
|
91
|
+
const authAgent = utils.createAgent(app, {
|
|
92
|
+
apiPath: 'public',
|
|
93
|
+
auth: true,
|
|
94
|
+
user: member,
|
|
95
|
+
version: 1,
|
|
96
|
+
});
|
|
97
|
+
await Promise.all([
|
|
98
|
+
testDb.createWorkflow({}, member),
|
|
99
|
+
testDb.createWorkflow({}, member),
|
|
100
|
+
testDb.createWorkflow({}, member),
|
|
101
|
+
]);
|
|
102
|
+
const response = await authAgent.get('/workflows');
|
|
103
|
+
expect(response.statusCode).toBe(200);
|
|
104
|
+
expect(response.body.data.length).toBe(3);
|
|
105
|
+
expect(response.body.nextCursor).toBeNull();
|
|
106
|
+
for (const workflow of response.body.data) {
|
|
107
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt, tags, } = workflow;
|
|
108
|
+
expect(id).toBeDefined();
|
|
109
|
+
expect(name).toBeDefined();
|
|
110
|
+
expect(connections).toBeDefined();
|
|
111
|
+
expect(active).toBe(false);
|
|
112
|
+
expect(staticData).toBeDefined();
|
|
113
|
+
expect(nodes).toBeDefined();
|
|
114
|
+
expect(tags).toBeDefined();
|
|
115
|
+
expect(settings).toBeDefined();
|
|
116
|
+
expect(createdAt).toBeDefined();
|
|
117
|
+
expect(updatedAt).toBeDefined();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
test('GET /workflows should return all owned workflows with pagination', async () => {
|
|
121
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: (0, random_1.randomApiKey)() });
|
|
122
|
+
const authAgent = utils.createAgent(app, {
|
|
123
|
+
apiPath: 'public',
|
|
124
|
+
auth: true,
|
|
125
|
+
user: member,
|
|
126
|
+
version: 1,
|
|
127
|
+
});
|
|
128
|
+
await Promise.all([
|
|
129
|
+
testDb.createWorkflow({}, member),
|
|
130
|
+
testDb.createWorkflow({}, member),
|
|
131
|
+
testDb.createWorkflow({}, member),
|
|
132
|
+
]);
|
|
133
|
+
const response = await authAgent.get('/workflows?limit=1');
|
|
134
|
+
expect(response.statusCode).toBe(200);
|
|
135
|
+
expect(response.body.data.length).toBe(1);
|
|
136
|
+
expect(response.body.nextCursor).not.toBeNull();
|
|
137
|
+
const response2 = await authAgent.get(`/workflows?limit=1&cursor=${response.body.nextCursor}`);
|
|
138
|
+
expect(response2.statusCode).toBe(200);
|
|
139
|
+
expect(response2.body.data.length).toBe(1);
|
|
140
|
+
expect(response2.body.nextCursor).not.toBeNull();
|
|
141
|
+
expect(response2.body.nextCursor).not.toBe(response.body.nextCursor);
|
|
142
|
+
const responses = [...response.body.data, ...response2.body.data];
|
|
143
|
+
for (const workflow of responses) {
|
|
144
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt, tags, } = workflow;
|
|
145
|
+
expect(id).toBeDefined();
|
|
146
|
+
expect(name).toBeDefined();
|
|
147
|
+
expect(connections).toBeDefined();
|
|
148
|
+
expect(active).toBe(false);
|
|
149
|
+
expect(staticData).toBeDefined();
|
|
150
|
+
expect(nodes).toBeDefined();
|
|
151
|
+
expect(tags).toBeDefined();
|
|
152
|
+
expect(settings).toBeDefined();
|
|
153
|
+
expect(createdAt).toBeDefined();
|
|
154
|
+
expect(updatedAt).toBeDefined();
|
|
155
|
+
}
|
|
156
|
+
expect(response.body.data[0].id).toBeLessThan(response2.body.data[0].id);
|
|
157
|
+
});
|
|
158
|
+
test('GET /workflows should return all owned workflows filtered by tag', async () => {
|
|
159
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: (0, random_1.randomApiKey)() });
|
|
160
|
+
const authAgent = utils.createAgent(app, {
|
|
161
|
+
apiPath: 'public',
|
|
162
|
+
auth: true,
|
|
163
|
+
user: member,
|
|
164
|
+
version: 1,
|
|
165
|
+
});
|
|
166
|
+
const tag = await testDb.createTag({});
|
|
167
|
+
const [workflow] = await Promise.all([
|
|
168
|
+
testDb.createWorkflow({ tags: [tag] }, member),
|
|
169
|
+
testDb.createWorkflow({}, member),
|
|
170
|
+
]);
|
|
171
|
+
const response = await authAgent.get(`/workflows?tags=${tag.name}`);
|
|
172
|
+
expect(response.statusCode).toBe(200);
|
|
173
|
+
expect(response.body.data.length).toBe(1);
|
|
174
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt, tags: wfTags, } = response.body.data[0];
|
|
175
|
+
expect(id).toBe(workflow.id);
|
|
176
|
+
expect(name).toBeDefined();
|
|
177
|
+
expect(connections).toBeDefined();
|
|
178
|
+
expect(active).toBe(false);
|
|
179
|
+
expect(staticData).toBeDefined();
|
|
180
|
+
expect(nodes).toBeDefined();
|
|
181
|
+
expect(settings).toBeDefined();
|
|
182
|
+
expect(createdAt).toBeDefined();
|
|
183
|
+
expect(updatedAt).toBeDefined();
|
|
184
|
+
expect(wfTags.length).toBe(1);
|
|
185
|
+
expect(wfTags[0].id).toBe(tag.id);
|
|
186
|
+
});
|
|
187
|
+
test('GET /workflows should return all owned workflows filtered by tags', async () => {
|
|
188
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: (0, random_1.randomApiKey)() });
|
|
189
|
+
const authAgent = utils.createAgent(app, {
|
|
190
|
+
apiPath: 'public',
|
|
191
|
+
auth: true,
|
|
192
|
+
user: member,
|
|
193
|
+
version: 1,
|
|
194
|
+
});
|
|
195
|
+
const tags = await Promise.all([await testDb.createTag({}), await testDb.createTag({})]);
|
|
196
|
+
const tagNames = tags.map((tag) => tag.name).join(',');
|
|
197
|
+
const [workflow1, workflow2] = await Promise.all([
|
|
198
|
+
testDb.createWorkflow({ tags }, member),
|
|
199
|
+
testDb.createWorkflow({ tags }, member),
|
|
200
|
+
testDb.createWorkflow({}, member),
|
|
201
|
+
testDb.createWorkflow({ tags: [tags[0]] }, member),
|
|
202
|
+
testDb.createWorkflow({ tags: [tags[1]] }, member),
|
|
203
|
+
]);
|
|
204
|
+
const response = await authAgent.get(`/workflows?tags=${tagNames}`);
|
|
205
|
+
expect(response.statusCode).toBe(200);
|
|
206
|
+
expect(response.body.data.length).toBe(2);
|
|
207
|
+
for (const workflow of response.body.data) {
|
|
208
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } = workflow;
|
|
209
|
+
expect(id).toBeDefined();
|
|
210
|
+
expect([workflow1.id, workflow2.id].includes(id)).toBe(true);
|
|
211
|
+
expect(name).toBeDefined();
|
|
212
|
+
expect(connections).toBeDefined();
|
|
213
|
+
expect(active).toBe(false);
|
|
214
|
+
expect(staticData).toBeDefined();
|
|
215
|
+
expect(nodes).toBeDefined();
|
|
216
|
+
expect(settings).toBeDefined();
|
|
217
|
+
expect(createdAt).toBeDefined();
|
|
218
|
+
expect(updatedAt).toBeDefined();
|
|
219
|
+
expect(workflow.tags.length).toBe(2);
|
|
220
|
+
workflow.tags.forEach((tag) => {
|
|
221
|
+
expect(tags.some((savedTag) => savedTag.id === tag.id)).toBe(true);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
test('GET /workflows should return all workflows for owner', async () => {
|
|
226
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
227
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole });
|
|
228
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
229
|
+
apiPath: 'public',
|
|
230
|
+
auth: true,
|
|
231
|
+
user: owner,
|
|
232
|
+
version: 1,
|
|
233
|
+
});
|
|
234
|
+
await Promise.all([
|
|
235
|
+
testDb.createWorkflow({}, owner),
|
|
236
|
+
testDb.createWorkflow({}, member),
|
|
237
|
+
testDb.createWorkflow({}, owner),
|
|
238
|
+
testDb.createWorkflow({}, member),
|
|
239
|
+
testDb.createWorkflow({}, owner),
|
|
240
|
+
]);
|
|
241
|
+
const response = await authOwnerAgent.get('/workflows');
|
|
242
|
+
expect(response.statusCode).toBe(200);
|
|
243
|
+
expect(response.body.data.length).toBe(5);
|
|
244
|
+
expect(response.body.nextCursor).toBeNull();
|
|
245
|
+
for (const workflow of response.body.data) {
|
|
246
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt, tags, } = workflow;
|
|
247
|
+
expect(id).toBeDefined();
|
|
248
|
+
expect(name).toBeDefined();
|
|
249
|
+
expect(connections).toBeDefined();
|
|
250
|
+
expect(active).toBe(false);
|
|
251
|
+
expect(staticData).toBeDefined();
|
|
252
|
+
expect(nodes).toBeDefined();
|
|
253
|
+
expect(tags).toBeDefined();
|
|
254
|
+
expect(settings).toBeDefined();
|
|
255
|
+
expect(createdAt).toBeDefined();
|
|
256
|
+
expect(updatedAt).toBeDefined();
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
test('GET /workflows/:workflowId should fail due to missing API Key', async () => {
|
|
260
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
|
261
|
+
owner.apiKey = null;
|
|
262
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
263
|
+
apiPath: 'public',
|
|
264
|
+
auth: true,
|
|
265
|
+
user: owner,
|
|
266
|
+
version: 1,
|
|
267
|
+
});
|
|
268
|
+
const response = await authOwnerAgent.get(`/workflows/2`);
|
|
269
|
+
expect(response.statusCode).toBe(401);
|
|
270
|
+
});
|
|
271
|
+
test('GET /workflows/:workflowId should fail due to invalid API Key', async () => {
|
|
272
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
273
|
+
owner.apiKey = 'abcXYZ';
|
|
274
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
275
|
+
apiPath: 'public',
|
|
276
|
+
auth: true,
|
|
277
|
+
user: owner,
|
|
278
|
+
version: 1,
|
|
279
|
+
});
|
|
280
|
+
const response = await authOwnerAgent.get(`/workflows/2`);
|
|
281
|
+
expect(response.statusCode).toBe(401);
|
|
282
|
+
});
|
|
283
|
+
test('GET /workflows/:workflowId should fail due to non existing workflow', async () => {
|
|
284
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
285
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
286
|
+
apiPath: 'public',
|
|
287
|
+
auth: true,
|
|
288
|
+
user: owner,
|
|
289
|
+
version: 1,
|
|
290
|
+
});
|
|
291
|
+
const response = await authOwnerAgent.get(`/workflows/2`);
|
|
292
|
+
expect(response.statusCode).toBe(404);
|
|
293
|
+
});
|
|
294
|
+
test('GET /workflows/:workflowId should retrieve workflow', async () => {
|
|
295
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: (0, random_1.randomApiKey)() });
|
|
296
|
+
const authAgent = utils.createAgent(app, {
|
|
297
|
+
apiPath: 'public',
|
|
298
|
+
auth: true,
|
|
299
|
+
user: member,
|
|
300
|
+
version: 1,
|
|
301
|
+
});
|
|
302
|
+
const workflow = await testDb.createWorkflow({}, member);
|
|
303
|
+
const response = await authAgent.get(`/workflows/${workflow.id}`);
|
|
304
|
+
expect(response.statusCode).toBe(200);
|
|
305
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } = response.body;
|
|
306
|
+
expect(id).toEqual(workflow.id);
|
|
307
|
+
expect(name).toEqual(workflow.name);
|
|
308
|
+
expect(connections).toEqual(workflow.connections);
|
|
309
|
+
expect(active).toBe(false);
|
|
310
|
+
expect(staticData).toEqual(workflow.staticData);
|
|
311
|
+
expect(nodes).toEqual(workflow.nodes);
|
|
312
|
+
expect(settings).toEqual(workflow.settings);
|
|
313
|
+
expect(createdAt).toEqual(workflow.createdAt.toISOString());
|
|
314
|
+
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
|
315
|
+
});
|
|
316
|
+
test('GET /workflows/:workflowId should retrieve non-owned workflow for owner', async () => {
|
|
317
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
318
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole });
|
|
319
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
320
|
+
apiPath: 'public',
|
|
321
|
+
auth: true,
|
|
322
|
+
user: owner,
|
|
323
|
+
version: 1,
|
|
324
|
+
});
|
|
325
|
+
const workflow = await testDb.createWorkflow({}, member);
|
|
326
|
+
const response = await authOwnerAgent.get(`/workflows/${workflow.id}`);
|
|
327
|
+
expect(response.statusCode).toBe(200);
|
|
328
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } = response.body;
|
|
329
|
+
expect(id).toEqual(workflow.id);
|
|
330
|
+
expect(name).toEqual(workflow.name);
|
|
331
|
+
expect(connections).toEqual(workflow.connections);
|
|
332
|
+
expect(active).toBe(false);
|
|
333
|
+
expect(staticData).toEqual(workflow.staticData);
|
|
334
|
+
expect(nodes).toEqual(workflow.nodes);
|
|
335
|
+
expect(settings).toEqual(workflow.settings);
|
|
336
|
+
expect(createdAt).toEqual(workflow.createdAt.toISOString());
|
|
337
|
+
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
|
338
|
+
});
|
|
339
|
+
test('DELETE /workflows/:workflowId should fail due to missing API Key', async () => {
|
|
340
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
|
341
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
342
|
+
apiPath: 'public',
|
|
343
|
+
auth: true,
|
|
344
|
+
user: owner,
|
|
345
|
+
version: 1,
|
|
346
|
+
});
|
|
347
|
+
const response = await authOwnerAgent.delete(`/workflows/2`);
|
|
348
|
+
expect(response.statusCode).toBe(401);
|
|
349
|
+
});
|
|
350
|
+
test('DELETE /workflows/:workflowId should fail due to invalid API Key', async () => {
|
|
351
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
352
|
+
owner.apiKey = 'abcXYZ';
|
|
353
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
354
|
+
apiPath: 'public',
|
|
355
|
+
auth: true,
|
|
356
|
+
user: owner,
|
|
357
|
+
version: 1,
|
|
358
|
+
});
|
|
359
|
+
const response = await authOwnerAgent.delete(`/workflows/2`);
|
|
360
|
+
expect(response.statusCode).toBe(401);
|
|
361
|
+
});
|
|
362
|
+
test('DELETE /workflows/:workflowId should fail due to non existing workflow', async () => {
|
|
363
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
364
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
365
|
+
apiPath: 'public',
|
|
366
|
+
auth: true,
|
|
367
|
+
user: owner,
|
|
368
|
+
version: 1,
|
|
369
|
+
});
|
|
370
|
+
const response = await authOwnerAgent.delete(`/workflows/2`);
|
|
371
|
+
expect(response.statusCode).toBe(404);
|
|
372
|
+
});
|
|
373
|
+
test('DELETE /workflows/:workflowId should delete the workflow', async () => {
|
|
374
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: (0, random_1.randomApiKey)() });
|
|
375
|
+
const authAgent = utils.createAgent(app, {
|
|
376
|
+
apiPath: 'public',
|
|
377
|
+
auth: true,
|
|
378
|
+
user: member,
|
|
379
|
+
version: 1,
|
|
380
|
+
});
|
|
381
|
+
const workflow = await testDb.createWorkflow({}, member);
|
|
382
|
+
const response = await authAgent.delete(`/workflows/${workflow.id}`);
|
|
383
|
+
expect(response.statusCode).toBe(200);
|
|
384
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } = response.body;
|
|
385
|
+
expect(id).toEqual(workflow.id);
|
|
386
|
+
expect(name).toEqual(workflow.name);
|
|
387
|
+
expect(connections).toEqual(workflow.connections);
|
|
388
|
+
expect(active).toBe(false);
|
|
389
|
+
expect(staticData).toEqual(workflow.staticData);
|
|
390
|
+
expect(nodes).toEqual(workflow.nodes);
|
|
391
|
+
expect(settings).toEqual(workflow.settings);
|
|
392
|
+
expect(createdAt).toEqual(workflow.createdAt.toISOString());
|
|
393
|
+
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
|
394
|
+
const sharedWorkflow = await src_1.Db.collections.SharedWorkflow.findOne({
|
|
395
|
+
workflow,
|
|
396
|
+
});
|
|
397
|
+
expect(sharedWorkflow).toBeUndefined();
|
|
398
|
+
});
|
|
399
|
+
test('DELETE /workflows/:workflowId should delete non-owned workflow when owner', async () => {
|
|
400
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
401
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole });
|
|
402
|
+
const authAgent = utils.createAgent(app, {
|
|
403
|
+
apiPath: 'public',
|
|
404
|
+
auth: true,
|
|
405
|
+
user: owner,
|
|
406
|
+
version: 1,
|
|
407
|
+
});
|
|
408
|
+
const workflow = await testDb.createWorkflow({}, member);
|
|
409
|
+
const response = await authAgent.delete(`/workflows/${workflow.id}`);
|
|
410
|
+
expect(response.statusCode).toBe(200);
|
|
411
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } = response.body;
|
|
412
|
+
expect(id).toEqual(workflow.id);
|
|
413
|
+
expect(name).toEqual(workflow.name);
|
|
414
|
+
expect(connections).toEqual(workflow.connections);
|
|
415
|
+
expect(active).toBe(false);
|
|
416
|
+
expect(staticData).toEqual(workflow.staticData);
|
|
417
|
+
expect(nodes).toEqual(workflow.nodes);
|
|
418
|
+
expect(settings).toEqual(workflow.settings);
|
|
419
|
+
expect(createdAt).toEqual(workflow.createdAt.toISOString());
|
|
420
|
+
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
|
421
|
+
const sharedWorkflow = await src_1.Db.collections.SharedWorkflow.findOne({
|
|
422
|
+
workflow,
|
|
423
|
+
});
|
|
424
|
+
expect(sharedWorkflow).toBeUndefined();
|
|
425
|
+
});
|
|
426
|
+
test('POST /workflows/:workflowId/activate should fail due to missing API Key', async () => {
|
|
427
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
|
428
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
429
|
+
apiPath: 'public',
|
|
430
|
+
auth: true,
|
|
431
|
+
user: owner,
|
|
432
|
+
version: 1,
|
|
433
|
+
});
|
|
434
|
+
const response = await authOwnerAgent.post(`/workflows/2/activate`);
|
|
435
|
+
expect(response.statusCode).toBe(401);
|
|
436
|
+
});
|
|
437
|
+
test('POST /workflows/:workflowId/activate should fail due to invalid API Key', async () => {
|
|
438
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
439
|
+
owner.apiKey = 'abcXYZ';
|
|
440
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
441
|
+
apiPath: 'public',
|
|
442
|
+
auth: true,
|
|
443
|
+
user: owner,
|
|
444
|
+
version: 1,
|
|
445
|
+
});
|
|
446
|
+
const response = await authOwnerAgent.post(`/workflows/2/activate`);
|
|
447
|
+
expect(response.statusCode).toBe(401);
|
|
448
|
+
});
|
|
449
|
+
test('POST /workflows/:workflowId/activate should fail due to non existing workflow', async () => {
|
|
450
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
451
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
452
|
+
apiPath: 'public',
|
|
453
|
+
auth: true,
|
|
454
|
+
user: owner,
|
|
455
|
+
version: 1,
|
|
456
|
+
});
|
|
457
|
+
const response = await authOwnerAgent.post(`/workflows/2/activate`);
|
|
458
|
+
expect(response.statusCode).toBe(404);
|
|
459
|
+
});
|
|
460
|
+
test('POST /workflows/:workflowId/activate should fail due to trying to activate a workflow without a trigger', async () => {
|
|
461
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
462
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
463
|
+
apiPath: 'public',
|
|
464
|
+
auth: true,
|
|
465
|
+
user: owner,
|
|
466
|
+
version: 1,
|
|
467
|
+
});
|
|
468
|
+
const workflow = await testDb.createWorkflow({}, owner);
|
|
469
|
+
const response = await authOwnerAgent.post(`/workflows/${workflow.id}/activate`);
|
|
470
|
+
expect(response.statusCode).toBe(400);
|
|
471
|
+
});
|
|
472
|
+
test.skip('POST /workflows/:workflowId/activate should set workflow as active', async () => {
|
|
473
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: (0, random_1.randomApiKey)() });
|
|
474
|
+
const authAgent = utils.createAgent(app, {
|
|
475
|
+
apiPath: 'public',
|
|
476
|
+
auth: true,
|
|
477
|
+
user: member,
|
|
478
|
+
version: 1,
|
|
479
|
+
});
|
|
480
|
+
const workflow = await testDb.createWorkflowWithTrigger({}, member);
|
|
481
|
+
const response = await authAgent.post(`/workflows/${workflow.id}/activate`);
|
|
482
|
+
expect(response.statusCode).toBe(200);
|
|
483
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } = response.body;
|
|
484
|
+
expect(id).toEqual(workflow.id);
|
|
485
|
+
expect(name).toEqual(workflow.name);
|
|
486
|
+
expect(connections).toEqual(workflow.connections);
|
|
487
|
+
expect(active).toBe(true);
|
|
488
|
+
expect(staticData).toEqual(workflow.staticData);
|
|
489
|
+
expect(nodes).toEqual(workflow.nodes);
|
|
490
|
+
expect(settings).toEqual(workflow.settings);
|
|
491
|
+
expect(createdAt).toEqual(workflow.createdAt.toISOString());
|
|
492
|
+
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
|
493
|
+
const sharedWorkflow = await src_1.Db.collections.SharedWorkflow.findOne({
|
|
494
|
+
where: {
|
|
495
|
+
user: member,
|
|
496
|
+
workflow,
|
|
497
|
+
},
|
|
498
|
+
relations: ['workflow'],
|
|
499
|
+
});
|
|
500
|
+
expect(sharedWorkflow === null || sharedWorkflow === void 0 ? void 0 : sharedWorkflow.workflow.active).toBe(true);
|
|
501
|
+
expect(await workflowRunner.isActive(workflow.id.toString())).toBe(true);
|
|
502
|
+
});
|
|
503
|
+
test.skip('POST /workflows/:workflowId/activate should set non-owned workflow as active when owner', async () => {
|
|
504
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
505
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole });
|
|
506
|
+
const authAgent = utils.createAgent(app, {
|
|
507
|
+
apiPath: 'public',
|
|
508
|
+
auth: true,
|
|
509
|
+
user: owner,
|
|
510
|
+
version: 1,
|
|
511
|
+
});
|
|
512
|
+
const workflow = await testDb.createWorkflowWithTrigger({}, member);
|
|
513
|
+
const response = await authAgent.post(`/workflows/${workflow.id}/activate`);
|
|
514
|
+
expect(response.statusCode).toBe(200);
|
|
515
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } = response.body;
|
|
516
|
+
expect(id).toEqual(workflow.id);
|
|
517
|
+
expect(name).toEqual(workflow.name);
|
|
518
|
+
expect(connections).toEqual(workflow.connections);
|
|
519
|
+
expect(active).toBe(true);
|
|
520
|
+
expect(staticData).toEqual(workflow.staticData);
|
|
521
|
+
expect(nodes).toEqual(workflow.nodes);
|
|
522
|
+
expect(settings).toEqual(workflow.settings);
|
|
523
|
+
expect(createdAt).toEqual(workflow.createdAt.toISOString());
|
|
524
|
+
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
|
525
|
+
const sharedOwnerWorkflow = await src_1.Db.collections.SharedWorkflow.findOne({
|
|
526
|
+
where: {
|
|
527
|
+
user: owner,
|
|
528
|
+
workflow,
|
|
529
|
+
},
|
|
530
|
+
});
|
|
531
|
+
expect(sharedOwnerWorkflow).toBeUndefined();
|
|
532
|
+
const sharedWorkflow = await src_1.Db.collections.SharedWorkflow.findOne({
|
|
533
|
+
where: {
|
|
534
|
+
user: member,
|
|
535
|
+
workflow,
|
|
536
|
+
},
|
|
537
|
+
relations: ['workflow'],
|
|
538
|
+
});
|
|
539
|
+
expect(sharedWorkflow === null || sharedWorkflow === void 0 ? void 0 : sharedWorkflow.workflow.active).toBe(true);
|
|
540
|
+
expect(await workflowRunner.isActive(workflow.id.toString())).toBe(true);
|
|
541
|
+
});
|
|
542
|
+
test('POST /workflows/:workflowId/deactivate should fail due to missing API Key', async () => {
|
|
543
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
|
544
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
545
|
+
apiPath: 'public',
|
|
546
|
+
auth: true,
|
|
547
|
+
user: owner,
|
|
548
|
+
version: 1,
|
|
549
|
+
});
|
|
550
|
+
const response = await authOwnerAgent.post(`/workflows/2/deactivate`);
|
|
551
|
+
expect(response.statusCode).toBe(401);
|
|
552
|
+
});
|
|
553
|
+
test('POST /workflows/:workflowId/deactivate should fail due to invalid API Key', async () => {
|
|
554
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
555
|
+
owner.apiKey = 'abcXYZ';
|
|
556
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
557
|
+
apiPath: 'public',
|
|
558
|
+
auth: true,
|
|
559
|
+
user: owner,
|
|
560
|
+
version: 1,
|
|
561
|
+
});
|
|
562
|
+
const response = await authOwnerAgent.post(`/workflows/2/deactivate`);
|
|
563
|
+
expect(response.statusCode).toBe(401);
|
|
564
|
+
});
|
|
565
|
+
test('POST /workflows/:workflowId/deactivate should fail due to non existing workflow', async () => {
|
|
566
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
567
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
568
|
+
apiPath: 'public',
|
|
569
|
+
auth: true,
|
|
570
|
+
user: owner,
|
|
571
|
+
version: 1,
|
|
572
|
+
});
|
|
573
|
+
const response = await authOwnerAgent.post(`/workflows/2/deactivate`);
|
|
574
|
+
expect(response.statusCode).toBe(404);
|
|
575
|
+
});
|
|
576
|
+
test('POST /workflows/:workflowId/deactivate should deactive workflow', async () => {
|
|
577
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: (0, random_1.randomApiKey)() });
|
|
578
|
+
const authAgent = utils.createAgent(app, {
|
|
579
|
+
apiPath: 'public',
|
|
580
|
+
auth: true,
|
|
581
|
+
user: member,
|
|
582
|
+
version: 1,
|
|
583
|
+
});
|
|
584
|
+
const workflow = await testDb.createWorkflowWithTrigger({}, member);
|
|
585
|
+
await authAgent.post(`/workflows/${workflow.id}/activate`);
|
|
586
|
+
const workflowDeactivationResponse = await authAgent.post(`/workflows/${workflow.id}/deactivate`);
|
|
587
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } = workflowDeactivationResponse.body;
|
|
588
|
+
expect(id).toEqual(workflow.id);
|
|
589
|
+
expect(name).toEqual(workflow.name);
|
|
590
|
+
expect(connections).toEqual(workflow.connections);
|
|
591
|
+
expect(active).toBe(false);
|
|
592
|
+
expect(staticData).toEqual(workflow.staticData);
|
|
593
|
+
expect(nodes).toEqual(workflow.nodes);
|
|
594
|
+
expect(settings).toEqual(workflow.settings);
|
|
595
|
+
expect(createdAt).toBeDefined();
|
|
596
|
+
expect(updatedAt).toBeDefined();
|
|
597
|
+
const sharedWorkflow = await src_1.Db.collections.SharedWorkflow.findOne({
|
|
598
|
+
where: {
|
|
599
|
+
user: member,
|
|
600
|
+
workflow,
|
|
601
|
+
},
|
|
602
|
+
relations: ['workflow'],
|
|
603
|
+
});
|
|
604
|
+
expect(sharedWorkflow === null || sharedWorkflow === void 0 ? void 0 : sharedWorkflow.workflow.active).toBe(false);
|
|
605
|
+
expect(await workflowRunner.isActive(workflow.id.toString())).toBe(false);
|
|
606
|
+
});
|
|
607
|
+
test('POST /workflows/:workflowId/deactivate should deactive non-owned workflow when owner', async () => {
|
|
608
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
609
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole });
|
|
610
|
+
const authAgent = utils.createAgent(app, {
|
|
611
|
+
apiPath: 'public',
|
|
612
|
+
auth: true,
|
|
613
|
+
user: owner,
|
|
614
|
+
version: 1,
|
|
615
|
+
});
|
|
616
|
+
const workflow = await testDb.createWorkflowWithTrigger({}, member);
|
|
617
|
+
await authAgent.post(`/workflows/${workflow.id}/activate`);
|
|
618
|
+
const workflowDeactivationResponse = await authAgent.post(`/workflows/${workflow.id}/deactivate`);
|
|
619
|
+
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } = workflowDeactivationResponse.body;
|
|
620
|
+
expect(id).toEqual(workflow.id);
|
|
621
|
+
expect(name).toEqual(workflow.name);
|
|
622
|
+
expect(connections).toEqual(workflow.connections);
|
|
623
|
+
expect(active).toBe(false);
|
|
624
|
+
expect(staticData).toEqual(workflow.staticData);
|
|
625
|
+
expect(nodes).toEqual(workflow.nodes);
|
|
626
|
+
expect(settings).toEqual(workflow.settings);
|
|
627
|
+
expect(createdAt).toBeDefined();
|
|
628
|
+
expect(updatedAt).toBeDefined();
|
|
629
|
+
const sharedOwnerWorkflow = await src_1.Db.collections.SharedWorkflow.findOne({
|
|
630
|
+
where: {
|
|
631
|
+
user: owner,
|
|
632
|
+
workflow,
|
|
633
|
+
},
|
|
634
|
+
});
|
|
635
|
+
expect(sharedOwnerWorkflow).toBeUndefined();
|
|
636
|
+
const sharedWorkflow = await src_1.Db.collections.SharedWorkflow.findOne({
|
|
637
|
+
where: {
|
|
638
|
+
user: member,
|
|
639
|
+
workflow,
|
|
640
|
+
},
|
|
641
|
+
relations: ['workflow'],
|
|
642
|
+
});
|
|
643
|
+
expect(sharedWorkflow === null || sharedWorkflow === void 0 ? void 0 : sharedWorkflow.workflow.active).toBe(false);
|
|
644
|
+
expect(await workflowRunner.isActive(workflow.id.toString())).toBe(false);
|
|
645
|
+
});
|
|
646
|
+
test('POST /workflows should fail due to missing API Key', async () => {
|
|
647
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
|
648
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
649
|
+
apiPath: 'public',
|
|
650
|
+
auth: true,
|
|
651
|
+
user: owner,
|
|
652
|
+
version: 1,
|
|
653
|
+
});
|
|
654
|
+
const response = await authOwnerAgent.post(`/workflows`);
|
|
655
|
+
expect(response.statusCode).toBe(401);
|
|
656
|
+
});
|
|
657
|
+
test('POST /workflows should fail due to invalid API Key', async () => {
|
|
658
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
659
|
+
owner.apiKey = 'abcXYZ';
|
|
660
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
661
|
+
apiPath: 'public',
|
|
662
|
+
auth: true,
|
|
663
|
+
user: owner,
|
|
664
|
+
version: 1,
|
|
665
|
+
});
|
|
666
|
+
const response = await authOwnerAgent.post(`/workflows`);
|
|
667
|
+
expect(response.statusCode).toBe(401);
|
|
668
|
+
});
|
|
669
|
+
test('POST /workflows should fail due to invalid body', async () => {
|
|
670
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
671
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
672
|
+
apiPath: 'public',
|
|
673
|
+
auth: true,
|
|
674
|
+
user: owner,
|
|
675
|
+
version: 1,
|
|
676
|
+
});
|
|
677
|
+
const response = await authOwnerAgent.post(`/workflows`).send({});
|
|
678
|
+
expect(response.statusCode).toBe(400);
|
|
679
|
+
});
|
|
680
|
+
test('POST /workflows should create workflow', async () => {
|
|
681
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole, apiKey: (0, random_1.randomApiKey)() });
|
|
682
|
+
const authAgent = utils.createAgent(app, {
|
|
683
|
+
apiPath: 'public',
|
|
684
|
+
auth: true,
|
|
685
|
+
user: member,
|
|
686
|
+
version: 1,
|
|
687
|
+
});
|
|
688
|
+
const payload = {
|
|
689
|
+
name: 'testing',
|
|
690
|
+
nodes: [
|
|
691
|
+
{
|
|
692
|
+
parameters: {},
|
|
693
|
+
name: 'Start',
|
|
694
|
+
type: 'n8n-nodes-base.start',
|
|
695
|
+
typeVersion: 1,
|
|
696
|
+
position: [240, 300],
|
|
697
|
+
},
|
|
698
|
+
],
|
|
699
|
+
connections: {},
|
|
700
|
+
staticData: null,
|
|
701
|
+
settings: {
|
|
702
|
+
saveExecutionProgress: true,
|
|
703
|
+
saveManualExecutions: true,
|
|
704
|
+
saveDataErrorExecution: 'all',
|
|
705
|
+
saveDataSuccessExecution: 'all',
|
|
706
|
+
executionTimeout: 3600,
|
|
707
|
+
timezone: 'America/New_York',
|
|
708
|
+
},
|
|
709
|
+
};
|
|
710
|
+
const response = await authAgent.post(`/workflows`).send(payload);
|
|
711
|
+
expect(response.statusCode).toBe(200);
|
|
712
|
+
const { id, name, nodes, connections, staticData, active, settings, createdAt, updatedAt } = response.body;
|
|
713
|
+
expect(id).toBeDefined();
|
|
714
|
+
expect(name).toBe(payload.name);
|
|
715
|
+
expect(connections).toEqual(payload.connections);
|
|
716
|
+
expect(settings).toEqual(payload.settings);
|
|
717
|
+
expect(staticData).toEqual(payload.staticData);
|
|
718
|
+
expect(nodes).toEqual(payload.nodes);
|
|
719
|
+
expect(active).toBe(false);
|
|
720
|
+
expect(createdAt).toBeDefined();
|
|
721
|
+
expect(updatedAt).toEqual(createdAt);
|
|
722
|
+
const sharedWorkflow = await src_1.Db.collections.SharedWorkflow.findOne({
|
|
723
|
+
where: {
|
|
724
|
+
user: member,
|
|
725
|
+
workflow: response.body,
|
|
726
|
+
},
|
|
727
|
+
relations: ['workflow', 'role'],
|
|
728
|
+
});
|
|
729
|
+
expect(sharedWorkflow === null || sharedWorkflow === void 0 ? void 0 : sharedWorkflow.workflow.name).toBe(name);
|
|
730
|
+
expect(sharedWorkflow === null || sharedWorkflow === void 0 ? void 0 : sharedWorkflow.workflow.createdAt.toISOString()).toBe(createdAt);
|
|
731
|
+
expect(sharedWorkflow === null || sharedWorkflow === void 0 ? void 0 : sharedWorkflow.role).toEqual(workflowOwnerRole);
|
|
732
|
+
});
|
|
733
|
+
test('PUT /workflows/:workflowId should fail due to missing API Key', async () => {
|
|
734
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
|
735
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
736
|
+
apiPath: 'public',
|
|
737
|
+
auth: true,
|
|
738
|
+
user: owner,
|
|
739
|
+
version: 1,
|
|
740
|
+
});
|
|
741
|
+
const response = await authOwnerAgent.put(`/workflows/1`);
|
|
742
|
+
expect(response.statusCode).toBe(401);
|
|
743
|
+
});
|
|
744
|
+
test('PUT /workflows/:workflowId should fail due to invalid API Key', async () => {
|
|
745
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
746
|
+
owner.apiKey = 'abcXYZ';
|
|
747
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
748
|
+
apiPath: 'public',
|
|
749
|
+
auth: true,
|
|
750
|
+
user: owner,
|
|
751
|
+
version: 1,
|
|
752
|
+
});
|
|
753
|
+
const response = await authOwnerAgent.put(`/workflows/1`).send({});
|
|
754
|
+
expect(response.statusCode).toBe(401);
|
|
755
|
+
});
|
|
756
|
+
test('PUT /workflows/:workflowId should fail due to non existing workflow', async () => {
|
|
757
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
758
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
759
|
+
apiPath: 'public',
|
|
760
|
+
auth: true,
|
|
761
|
+
user: owner,
|
|
762
|
+
version: 1,
|
|
763
|
+
});
|
|
764
|
+
const response = await authOwnerAgent.put(`/workflows/1`).send({
|
|
765
|
+
name: 'testing',
|
|
766
|
+
nodes: [
|
|
767
|
+
{
|
|
768
|
+
parameters: {},
|
|
769
|
+
name: 'Start',
|
|
770
|
+
type: 'n8n-nodes-base.start',
|
|
771
|
+
typeVersion: 1,
|
|
772
|
+
position: [240, 300],
|
|
773
|
+
},
|
|
774
|
+
],
|
|
775
|
+
connections: {},
|
|
776
|
+
staticData: null,
|
|
777
|
+
settings: {
|
|
778
|
+
saveExecutionProgress: true,
|
|
779
|
+
saveManualExecutions: true,
|
|
780
|
+
saveDataErrorExecution: 'all',
|
|
781
|
+
saveDataSuccessExecution: 'all',
|
|
782
|
+
executionTimeout: 3600,
|
|
783
|
+
timezone: 'America/New_York',
|
|
784
|
+
},
|
|
785
|
+
});
|
|
786
|
+
expect(response.statusCode).toBe(404);
|
|
787
|
+
});
|
|
788
|
+
test('PUT /workflows/:workflowId should fail due to invalid body', async () => {
|
|
789
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
790
|
+
const authOwnerAgent = utils.createAgent(app, {
|
|
791
|
+
apiPath: 'public',
|
|
792
|
+
auth: true,
|
|
793
|
+
user: owner,
|
|
794
|
+
version: 1,
|
|
795
|
+
});
|
|
796
|
+
const response = await authOwnerAgent.put(`/workflows/1`).send({
|
|
797
|
+
nodes: [
|
|
798
|
+
{
|
|
799
|
+
parameters: {},
|
|
800
|
+
name: 'Start',
|
|
801
|
+
type: 'n8n-nodes-base.start',
|
|
802
|
+
typeVersion: 1,
|
|
803
|
+
position: [240, 300],
|
|
804
|
+
},
|
|
805
|
+
],
|
|
806
|
+
connections: {},
|
|
807
|
+
staticData: null,
|
|
808
|
+
settings: {
|
|
809
|
+
saveExecutionProgress: true,
|
|
810
|
+
saveManualExecutions: true,
|
|
811
|
+
saveDataErrorExecution: 'all',
|
|
812
|
+
saveDataSuccessExecution: 'all',
|
|
813
|
+
executionTimeout: 3600,
|
|
814
|
+
timezone: 'America/New_York',
|
|
815
|
+
},
|
|
816
|
+
});
|
|
817
|
+
expect(response.statusCode).toBe(400);
|
|
818
|
+
});
|
|
819
|
+
test('PUT /workflows/:workflowId should update workflow', async () => {
|
|
820
|
+
const member = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
821
|
+
const workflow = await testDb.createWorkflow({}, member);
|
|
822
|
+
const authAgent = utils.createAgent(app, {
|
|
823
|
+
apiPath: 'public',
|
|
824
|
+
auth: true,
|
|
825
|
+
user: member,
|
|
826
|
+
version: 1,
|
|
827
|
+
});
|
|
828
|
+
const payload = {
|
|
829
|
+
name: 'name updated',
|
|
830
|
+
nodes: [
|
|
831
|
+
{
|
|
832
|
+
parameters: {},
|
|
833
|
+
name: 'Start',
|
|
834
|
+
type: 'n8n-nodes-base.start',
|
|
835
|
+
typeVersion: 1,
|
|
836
|
+
position: [240, 300],
|
|
837
|
+
},
|
|
838
|
+
{
|
|
839
|
+
parameters: {},
|
|
840
|
+
name: 'Cron',
|
|
841
|
+
type: 'n8n-nodes-base.cron',
|
|
842
|
+
typeVersion: 1,
|
|
843
|
+
position: [400, 300],
|
|
844
|
+
},
|
|
845
|
+
],
|
|
846
|
+
connections: {},
|
|
847
|
+
staticData: '{"id":1}',
|
|
848
|
+
settings: {
|
|
849
|
+
saveExecutionProgress: false,
|
|
850
|
+
saveManualExecutions: false,
|
|
851
|
+
saveDataErrorExecution: 'all',
|
|
852
|
+
saveDataSuccessExecution: 'all',
|
|
853
|
+
executionTimeout: 3600,
|
|
854
|
+
timezone: 'America/New_York',
|
|
855
|
+
},
|
|
856
|
+
};
|
|
857
|
+
const response = await authAgent.put(`/workflows/${workflow.id}`).send(payload);
|
|
858
|
+
const { id, name, nodes, connections, staticData, active, settings, createdAt, updatedAt } = response.body;
|
|
859
|
+
expect(response.statusCode).toBe(200);
|
|
860
|
+
expect(id).toBe(workflow.id);
|
|
861
|
+
expect(name).toBe(payload.name);
|
|
862
|
+
expect(connections).toEqual(payload.connections);
|
|
863
|
+
expect(settings).toEqual(payload.settings);
|
|
864
|
+
expect(staticData).toEqual(payload.staticData);
|
|
865
|
+
expect(nodes).toEqual(payload.nodes);
|
|
866
|
+
expect(active).toBe(false);
|
|
867
|
+
expect(createdAt).toBe(workflow.createdAt.toISOString());
|
|
868
|
+
expect(updatedAt).not.toBe(workflow.updatedAt.toISOString());
|
|
869
|
+
const sharedWorkflow = await src_1.Db.collections.SharedWorkflow.findOne({
|
|
870
|
+
where: {
|
|
871
|
+
user: member,
|
|
872
|
+
workflow: response.body,
|
|
873
|
+
},
|
|
874
|
+
relations: ['workflow'],
|
|
875
|
+
});
|
|
876
|
+
expect(sharedWorkflow === null || sharedWorkflow === void 0 ? void 0 : sharedWorkflow.workflow.name).toBe(payload.name);
|
|
877
|
+
expect(sharedWorkflow === null || sharedWorkflow === void 0 ? void 0 : sharedWorkflow.workflow.updatedAt.getTime()).toBeGreaterThan(workflow.updatedAt.getTime());
|
|
878
|
+
});
|
|
879
|
+
test('PUT /workflows/:workflowId should update non-owned workflow if owner', async () => {
|
|
880
|
+
const owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: (0, random_1.randomApiKey)() });
|
|
881
|
+
const member = await testDb.createUser({ globalRole: globalMemberRole });
|
|
882
|
+
const workflow = await testDb.createWorkflow({}, member);
|
|
883
|
+
const authAgent = utils.createAgent(app, {
|
|
884
|
+
apiPath: 'public',
|
|
885
|
+
auth: true,
|
|
886
|
+
user: owner,
|
|
887
|
+
version: 1,
|
|
888
|
+
});
|
|
889
|
+
const payload = {
|
|
890
|
+
name: 'name owner updated',
|
|
891
|
+
nodes: [
|
|
892
|
+
{
|
|
893
|
+
parameters: {},
|
|
894
|
+
name: 'Start',
|
|
895
|
+
type: 'n8n-nodes-base.start',
|
|
896
|
+
typeVersion: 1,
|
|
897
|
+
position: [240, 300],
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
parameters: {},
|
|
901
|
+
name: 'Cron',
|
|
902
|
+
type: 'n8n-nodes-base.cron',
|
|
903
|
+
typeVersion: 1,
|
|
904
|
+
position: [400, 300],
|
|
905
|
+
},
|
|
906
|
+
],
|
|
907
|
+
connections: {},
|
|
908
|
+
staticData: '{"id":1}',
|
|
909
|
+
settings: {
|
|
910
|
+
saveExecutionProgress: false,
|
|
911
|
+
saveManualExecutions: false,
|
|
912
|
+
saveDataErrorExecution: 'all',
|
|
913
|
+
saveDataSuccessExecution: 'all',
|
|
914
|
+
executionTimeout: 3600,
|
|
915
|
+
timezone: 'America/New_York',
|
|
916
|
+
},
|
|
917
|
+
};
|
|
918
|
+
const response = await authAgent.put(`/workflows/${workflow.id}`).send(payload);
|
|
919
|
+
const { id, name, nodes, connections, staticData, active, settings, createdAt, updatedAt } = response.body;
|
|
920
|
+
expect(response.statusCode).toBe(200);
|
|
921
|
+
expect(id).toBe(workflow.id);
|
|
922
|
+
expect(name).toBe(payload.name);
|
|
923
|
+
expect(connections).toEqual(payload.connections);
|
|
924
|
+
expect(settings).toEqual(payload.settings);
|
|
925
|
+
expect(staticData).toEqual(payload.staticData);
|
|
926
|
+
expect(nodes).toEqual(payload.nodes);
|
|
927
|
+
expect(active).toBe(false);
|
|
928
|
+
expect(createdAt).toBe(workflow.createdAt.toISOString());
|
|
929
|
+
expect(updatedAt).not.toBe(workflow.updatedAt.toISOString());
|
|
930
|
+
const sharedOwnerWorkflow = await src_1.Db.collections.SharedWorkflow.findOne({
|
|
931
|
+
where: {
|
|
932
|
+
user: owner,
|
|
933
|
+
workflow: response.body,
|
|
934
|
+
},
|
|
935
|
+
});
|
|
936
|
+
expect(sharedOwnerWorkflow).toBeUndefined();
|
|
937
|
+
const sharedWorkflow = await src_1.Db.collections.SharedWorkflow.findOne({
|
|
938
|
+
where: {
|
|
939
|
+
user: member,
|
|
940
|
+
workflow: response.body,
|
|
941
|
+
},
|
|
942
|
+
relations: ['workflow', 'role'],
|
|
943
|
+
});
|
|
944
|
+
expect(sharedWorkflow === null || sharedWorkflow === void 0 ? void 0 : sharedWorkflow.workflow.name).toBe(payload.name);
|
|
945
|
+
expect(sharedWorkflow === null || sharedWorkflow === void 0 ? void 0 : sharedWorkflow.workflow.updatedAt.getTime()).toBeGreaterThan(workflow.updatedAt.getTime());
|
|
946
|
+
expect(sharedWorkflow === null || sharedWorkflow === void 0 ? void 0 : sharedWorkflow.role).toEqual(workflowOwnerRole);
|
|
947
|
+
});
|
|
948
|
+
//# sourceMappingURL=workflows.test.js.map
|