2023-03-17 09:24:05 -07:00
|
|
|
import type { Application } from 'express';
|
|
|
|
import type { SuperAgentTest } from 'supertest';
|
2022-11-09 06:25:00 -08:00
|
|
|
import config from '@/config';
|
2023-03-17 09:24:05 -07:00
|
|
|
import type { User } from '@db/entities/User';
|
|
|
|
import type { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2022-11-09 06:25:00 -08:00
|
|
|
import { randomApiKey } from '../shared/random';
|
2022-06-08 11:53:12 -07:00
|
|
|
import * as utils from '../shared/utils';
|
|
|
|
import * as testDb from '../shared/testDb';
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
let app: Application;
|
|
|
|
let owner: User;
|
2023-04-14 02:05:42 -07:00
|
|
|
let user1: User;
|
|
|
|
let user2: User;
|
2023-03-17 09:24:05 -07:00
|
|
|
let authOwnerAgent: SuperAgentTest;
|
2023-04-14 02:05:42 -07:00
|
|
|
let authUser1Agent: SuperAgentTest;
|
|
|
|
let authUser2Agent: SuperAgentTest;
|
2022-11-09 06:25:00 -08:00
|
|
|
let workflowRunner: ActiveWorkflowRunner;
|
2022-06-08 11:53:12 -07:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
2023-01-26 02:44:50 -08:00
|
|
|
app = await utils.initTestServer({
|
|
|
|
endpointGroups: ['publicApi'],
|
|
|
|
applyAuth: false,
|
|
|
|
enablePublicAPI: true,
|
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const globalOwnerRole = await testDb.getGlobalOwnerRole();
|
2023-04-14 02:05:42 -07:00
|
|
|
const globalUserRole = await testDb.getGlobalMemberRole();
|
2023-03-17 09:24:05 -07:00
|
|
|
owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
|
2023-04-14 02:05:42 -07:00
|
|
|
user1 = await testDb.createUser({ globalRole: globalUserRole, apiKey: randomApiKey() });
|
|
|
|
user2 = await testDb.createUser({ globalRole: globalUserRole, apiKey: randomApiKey() });
|
2022-06-08 11:53:12 -07:00
|
|
|
|
|
|
|
await utils.initBinaryManager();
|
|
|
|
await utils.initNodeTypes();
|
2022-06-14 09:32:19 -07:00
|
|
|
|
2022-06-08 11:53:12 -07:00
|
|
|
workflowRunner = await utils.initActiveWorkflowRunner();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2023-01-13 09:12:22 -08:00
|
|
|
await testDb.truncate([
|
|
|
|
'SharedCredentials',
|
|
|
|
'SharedWorkflow',
|
|
|
|
'Workflow',
|
|
|
|
'Credentials',
|
|
|
|
'Execution',
|
|
|
|
'Settings',
|
|
|
|
]);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
authOwnerAgent = utils.createAgent(app, {
|
2022-06-08 11:53:12 -07:00
|
|
|
apiPath: 'public',
|
|
|
|
auth: true,
|
|
|
|
user: owner,
|
|
|
|
version: 1,
|
|
|
|
});
|
|
|
|
|
2023-04-14 02:05:42 -07:00
|
|
|
authUser1Agent = utils.createAgent(app, {
|
|
|
|
apiPath: 'public',
|
|
|
|
auth: true,
|
|
|
|
user: user1,
|
|
|
|
version: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
authUser2Agent = utils.createAgent(app, {
|
|
|
|
apiPath: 'public',
|
|
|
|
auth: true,
|
|
|
|
user: user2,
|
|
|
|
version: 1,
|
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
config.set('userManagement.isInstanceOwnerSetUp', true);
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
afterEach(async () => {
|
|
|
|
await workflowRunner?.removeAll();
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
afterAll(async () => {
|
|
|
|
await testDb.terminate();
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const testWithAPIKey =
|
|
|
|
(method: 'get' | 'post' | 'put' | 'delete', url: string, apiKey: string | null) => async () => {
|
2023-05-23 17:01:45 -07:00
|
|
|
void authOwnerAgent.set({ 'X-N8N-API-KEY': apiKey });
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent[method](url);
|
|
|
|
expect(response.statusCode).toBe(401);
|
|
|
|
};
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
describe('GET /executions/:id', () => {
|
|
|
|
test('should fail due to missing API Key', testWithAPIKey('get', '/executions/1', null));
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should fail due to invalid API Key', testWithAPIKey('get', '/executions/1', 'abcXYZ'));
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-04-14 02:05:42 -07:00
|
|
|
test('owner should be able to get an execution owned by him', async () => {
|
2023-03-17 09:24:05 -07:00
|
|
|
const workflow = await testDb.createWorkflow({}, owner);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const execution = await testDb.createSuccessfulExecution(workflow);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent.get(`/executions/${execution.id}`);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const {
|
|
|
|
id,
|
|
|
|
finished,
|
|
|
|
mode,
|
|
|
|
retryOf,
|
|
|
|
retrySuccessId,
|
|
|
|
startedAt,
|
|
|
|
stoppedAt,
|
|
|
|
workflowId,
|
|
|
|
waitTill,
|
|
|
|
} = response.body;
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(finished).toBe(true);
|
|
|
|
expect(mode).toEqual(execution.mode);
|
|
|
|
expect(retrySuccessId).toBeNull();
|
|
|
|
expect(retryOf).toBeNull();
|
|
|
|
expect(startedAt).not.toBeNull();
|
|
|
|
expect(stoppedAt).not.toBeNull();
|
|
|
|
expect(workflowId).toBe(execution.workflowId);
|
|
|
|
expect(waitTill).toBeNull();
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
2023-04-14 02:05:42 -07:00
|
|
|
|
|
|
|
test('owner should be able to read executions of other users', async () => {
|
|
|
|
const workflow = await testDb.createWorkflow({}, user1);
|
|
|
|
const execution = await testDb.createSuccessfulExecution(workflow);
|
|
|
|
|
|
|
|
const response = await authOwnerAgent.get(`/executions/${execution.id}`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('member should be able to fetch his own executions', async () => {
|
|
|
|
const workflow = await testDb.createWorkflow({}, user1);
|
|
|
|
const execution = await testDb.createSuccessfulExecution(workflow);
|
|
|
|
|
|
|
|
const response = await authUser1Agent.get(`/executions/${execution.id}`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('member should not get an execution of another user without the workflow being shared', async () => {
|
|
|
|
const workflow = await testDb.createWorkflow({}, owner);
|
|
|
|
|
|
|
|
const execution = await testDb.createSuccessfulExecution(workflow);
|
|
|
|
|
|
|
|
const response = await authUser1Agent.get(`/executions/${execution.id}`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(404);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('member should be able to fetch executions of workflows shared with him', async () => {
|
|
|
|
const workflow = await testDb.createWorkflow({}, user1);
|
|
|
|
|
|
|
|
const execution = await testDb.createSuccessfulExecution(workflow);
|
|
|
|
|
|
|
|
await testDb.shareWorkflowWithUsers(workflow, [user2]);
|
|
|
|
|
|
|
|
const response = await authUser2Agent.get(`/executions/${execution.id}`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
describe('DELETE /executions/:id', () => {
|
|
|
|
test('should fail due to missing API Key', testWithAPIKey('delete', '/executions/1', null));
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should fail due to invalid API Key', testWithAPIKey('delete', '/executions/1', 'abcXYZ'));
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should delete an execution', async () => {
|
|
|
|
const workflow = await testDb.createWorkflow({}, owner);
|
|
|
|
const execution = await testDb.createSuccessfulExecution(workflow);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent.delete(`/executions/${execution.id}`);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const {
|
|
|
|
id,
|
|
|
|
finished,
|
|
|
|
mode,
|
|
|
|
retryOf,
|
|
|
|
retrySuccessId,
|
|
|
|
startedAt,
|
|
|
|
stoppedAt,
|
|
|
|
workflowId,
|
|
|
|
waitTill,
|
|
|
|
} = response.body;
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(finished).toBe(true);
|
|
|
|
expect(mode).toEqual(execution.mode);
|
|
|
|
expect(retrySuccessId).toBeNull();
|
|
|
|
expect(retryOf).toBeNull();
|
|
|
|
expect(startedAt).not.toBeNull();
|
|
|
|
expect(stoppedAt).not.toBeNull();
|
|
|
|
expect(workflowId).toBe(execution.workflowId);
|
|
|
|
expect(waitTill).toBeNull();
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
describe('GET /executions', () => {
|
|
|
|
test('should fail due to missing API Key', testWithAPIKey('get', '/executions', null));
|
2022-08-08 13:15:56 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should fail due to invalid API Key', testWithAPIKey('get', '/executions', 'abcXYZ'));
|
2022-08-08 13:15:56 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should retrieve all successful executions', async () => {
|
|
|
|
const workflow = await testDb.createWorkflow({}, owner);
|
2022-08-08 13:15:56 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const successfulExecution = await testDb.createSuccessfulExecution(workflow);
|
2022-08-08 13:15:56 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
await testDb.createErrorExecution(workflow);
|
2022-08-08 13:15:56 -07:00
|
|
|
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authOwnerAgent.get('/executions').query({
|
2023-03-17 09:24:05 -07:00
|
|
|
status: 'success',
|
|
|
|
});
|
2022-08-08 13:15:56 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.length).toBe(1);
|
|
|
|
expect(response.body.nextCursor).toBe(null);
|
2022-08-08 13:15:56 -07:00
|
|
|
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
finished,
|
|
|
|
mode,
|
|
|
|
retryOf,
|
|
|
|
retrySuccessId,
|
|
|
|
startedAt,
|
|
|
|
stoppedAt,
|
|
|
|
workflowId,
|
|
|
|
waitTill,
|
2023-03-17 09:24:05 -07:00
|
|
|
} = response.body.data[0];
|
2022-08-08 13:15:56 -07:00
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(finished).toBe(true);
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(mode).toEqual(successfulExecution.mode);
|
2022-08-08 13:15:56 -07:00
|
|
|
expect(retrySuccessId).toBeNull();
|
|
|
|
expect(retryOf).toBeNull();
|
|
|
|
expect(startedAt).not.toBeNull();
|
|
|
|
expect(stoppedAt).not.toBeNull();
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(workflowId).toBe(successfulExecution.workflowId);
|
2022-08-08 13:15:56 -07:00
|
|
|
expect(waitTill).toBeNull();
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
// failing on Postgres and MySQL - ref: https://github.com/n8n-io/n8n/pull/3834
|
2023-05-24 00:45:37 -07:00
|
|
|
// eslint-disable-next-line n8n-local-rules/no-skipped-tests
|
2023-03-17 09:24:05 -07:00
|
|
|
test.skip('should paginate two executions', async () => {
|
|
|
|
const workflow = await testDb.createWorkflow({}, owner);
|
|
|
|
|
|
|
|
const firstSuccessfulExecution = await testDb.createSuccessfulExecution(workflow);
|
|
|
|
|
|
|
|
const secondSuccessfulExecution = await testDb.createSuccessfulExecution(workflow);
|
|
|
|
|
|
|
|
await testDb.createErrorExecution(workflow);
|
|
|
|
|
2023-05-02 01:37:19 -07:00
|
|
|
const firstExecutionResponse = await authOwnerAgent.get('/executions').query({
|
2023-03-17 09:24:05 -07:00
|
|
|
status: 'success',
|
|
|
|
limit: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(firstExecutionResponse.statusCode).toBe(200);
|
|
|
|
expect(firstExecutionResponse.body.data.length).toBe(1);
|
|
|
|
expect(firstExecutionResponse.body.nextCursor).toBeDefined();
|
|
|
|
|
2023-05-02 01:37:19 -07:00
|
|
|
const secondExecutionResponse = await authOwnerAgent.get('/executions').query({
|
2023-03-17 09:24:05 -07:00
|
|
|
status: 'success',
|
|
|
|
limit: 1,
|
|
|
|
cursor: firstExecutionResponse.body.nextCursor,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(secondExecutionResponse.statusCode).toBe(200);
|
|
|
|
expect(secondExecutionResponse.body.data.length).toBe(1);
|
|
|
|
expect(secondExecutionResponse.body.nextCursor).toBeNull();
|
|
|
|
|
|
|
|
const successfulExecutions = [firstSuccessfulExecution, secondSuccessfulExecution];
|
|
|
|
const executions = [...firstExecutionResponse.body.data, ...secondExecutionResponse.body.data];
|
|
|
|
|
|
|
|
for (let i = 0; i < executions.length; i++) {
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
finished,
|
|
|
|
mode,
|
|
|
|
retryOf,
|
|
|
|
retrySuccessId,
|
|
|
|
startedAt,
|
|
|
|
stoppedAt,
|
|
|
|
workflowId,
|
|
|
|
waitTill,
|
|
|
|
} = executions[i];
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(finished).toBe(true);
|
|
|
|
expect(mode).toEqual(successfulExecutions[i].mode);
|
|
|
|
expect(retrySuccessId).toBeNull();
|
|
|
|
expect(retryOf).toBeNull();
|
|
|
|
expect(startedAt).not.toBeNull();
|
|
|
|
expect(stoppedAt).not.toBeNull();
|
|
|
|
expect(workflowId).toBe(successfulExecutions[i].workflowId);
|
|
|
|
expect(waitTill).toBeNull();
|
|
|
|
}
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should retrieve all error executions', async () => {
|
|
|
|
const workflow = await testDb.createWorkflow({}, owner);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
await testDb.createSuccessfulExecution(workflow);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const errorExecution = await testDb.createErrorExecution(workflow);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authOwnerAgent.get('/executions').query({
|
2023-03-17 09:24:05 -07:00
|
|
|
status: 'error',
|
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.length).toBe(1);
|
|
|
|
expect(response.body.nextCursor).toBe(null);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const {
|
|
|
|
id,
|
|
|
|
finished,
|
|
|
|
mode,
|
|
|
|
retryOf,
|
|
|
|
retrySuccessId,
|
|
|
|
startedAt,
|
|
|
|
stoppedAt,
|
|
|
|
workflowId,
|
|
|
|
waitTill,
|
|
|
|
} = response.body.data[0];
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(finished).toBe(false);
|
|
|
|
expect(mode).toEqual(errorExecution.mode);
|
|
|
|
expect(retrySuccessId).toBeNull();
|
|
|
|
expect(retryOf).toBeNull();
|
|
|
|
expect(startedAt).not.toBeNull();
|
|
|
|
expect(stoppedAt).not.toBeNull();
|
|
|
|
expect(workflowId).toBe(errorExecution.workflowId);
|
|
|
|
expect(waitTill).toBeNull();
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should return all waiting executions', async () => {
|
|
|
|
const workflow = await testDb.createWorkflow({}, owner);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
await testDb.createSuccessfulExecution(workflow);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
await testDb.createErrorExecution(workflow);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const waitingExecution = await testDb.createWaitingExecution(workflow);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authOwnerAgent.get('/executions').query({
|
2023-03-17 09:24:05 -07:00
|
|
|
status: 'waiting',
|
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.length).toBe(1);
|
|
|
|
expect(response.body.nextCursor).toBe(null);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
finished,
|
|
|
|
mode,
|
|
|
|
retryOf,
|
|
|
|
retrySuccessId,
|
|
|
|
startedAt,
|
|
|
|
stoppedAt,
|
|
|
|
workflowId,
|
|
|
|
waitTill,
|
2023-03-17 09:24:05 -07:00
|
|
|
} = response.body.data[0];
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(finished).toBe(false);
|
|
|
|
expect(mode).toEqual(waitingExecution.mode);
|
2022-06-08 11:53:12 -07:00
|
|
|
expect(retrySuccessId).toBeNull();
|
|
|
|
expect(retryOf).toBeNull();
|
|
|
|
expect(startedAt).not.toBeNull();
|
|
|
|
expect(stoppedAt).not.toBeNull();
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(workflowId).toBe(waitingExecution.workflowId);
|
|
|
|
expect(new Date(waitTill).getTime()).toBeGreaterThan(Date.now() - 1000);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should retrieve all executions of specific workflow', async () => {
|
|
|
|
const [workflow, workflow2] = await testDb.createManyWorkflows(2, {}, owner);
|
|
|
|
|
|
|
|
const savedExecutions = await testDb.createManyExecutions(
|
|
|
|
2,
|
|
|
|
workflow,
|
|
|
|
testDb.createSuccessfulExecution,
|
|
|
|
);
|
|
|
|
await testDb.createManyExecutions(2, workflow2, testDb.createSuccessfulExecution);
|
|
|
|
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authOwnerAgent.get('/executions').query({
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: workflow.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.length).toBe(2);
|
|
|
|
expect(response.body.nextCursor).toBe(null);
|
|
|
|
|
|
|
|
for (const execution of response.body.data) {
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
finished,
|
|
|
|
mode,
|
|
|
|
retryOf,
|
|
|
|
retrySuccessId,
|
|
|
|
startedAt,
|
|
|
|
stoppedAt,
|
|
|
|
workflowId,
|
|
|
|
waitTill,
|
|
|
|
} = execution;
|
|
|
|
|
|
|
|
expect(savedExecutions.some((exec) => exec.id === id)).toBe(true);
|
|
|
|
expect(finished).toBe(true);
|
|
|
|
expect(mode).toBeDefined();
|
|
|
|
expect(retrySuccessId).toBeNull();
|
|
|
|
expect(retryOf).toBeNull();
|
|
|
|
expect(startedAt).not.toBeNull();
|
|
|
|
expect(stoppedAt).not.toBeNull();
|
|
|
|
expect(workflowId).toBe(workflow.id);
|
|
|
|
expect(waitTill).toBeNull();
|
|
|
|
}
|
|
|
|
});
|
2023-04-14 02:05:42 -07:00
|
|
|
|
|
|
|
test('owner should retrieve all executions regardless of ownership', async () => {
|
|
|
|
const [firstWorkflowForUser1, secondWorkflowForUser1] = await testDb.createManyWorkflows(
|
|
|
|
2,
|
|
|
|
{},
|
|
|
|
user1,
|
|
|
|
);
|
|
|
|
await testDb.createManyExecutions(2, firstWorkflowForUser1, testDb.createSuccessfulExecution);
|
|
|
|
await testDb.createManyExecutions(2, secondWorkflowForUser1, testDb.createSuccessfulExecution);
|
|
|
|
|
|
|
|
const [firstWorkflowForUser2, secondWorkflowForUser2] = await testDb.createManyWorkflows(
|
|
|
|
2,
|
|
|
|
{},
|
|
|
|
user2,
|
|
|
|
);
|
|
|
|
await testDb.createManyExecutions(2, firstWorkflowForUser2, testDb.createSuccessfulExecution);
|
|
|
|
await testDb.createManyExecutions(2, secondWorkflowForUser2, testDb.createSuccessfulExecution);
|
|
|
|
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authOwnerAgent.get('/executions');
|
2023-04-14 02:05:42 -07:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.length).toBe(8);
|
|
|
|
expect(response.body.nextCursor).toBe(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('member should not see executions of workflows not shared with him', async () => {
|
|
|
|
const [firstWorkflowForUser1, secondWorkflowForUser1] = await testDb.createManyWorkflows(
|
|
|
|
2,
|
|
|
|
{},
|
|
|
|
user1,
|
|
|
|
);
|
|
|
|
await testDb.createManyExecutions(2, firstWorkflowForUser1, testDb.createSuccessfulExecution);
|
|
|
|
await testDb.createManyExecutions(2, secondWorkflowForUser1, testDb.createSuccessfulExecution);
|
|
|
|
|
|
|
|
const [firstWorkflowForUser2, secondWorkflowForUser2] = await testDb.createManyWorkflows(
|
|
|
|
2,
|
|
|
|
{},
|
|
|
|
user2,
|
|
|
|
);
|
|
|
|
await testDb.createManyExecutions(2, firstWorkflowForUser2, testDb.createSuccessfulExecution);
|
|
|
|
await testDb.createManyExecutions(2, secondWorkflowForUser2, testDb.createSuccessfulExecution);
|
|
|
|
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authUser1Agent.get('/executions');
|
2023-04-14 02:05:42 -07:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.length).toBe(4);
|
|
|
|
expect(response.body.nextCursor).toBe(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('member should also see executions of workflows shared with him', async () => {
|
|
|
|
const [firstWorkflowForUser1, secondWorkflowForUser1] = await testDb.createManyWorkflows(
|
|
|
|
2,
|
|
|
|
{},
|
|
|
|
user1,
|
|
|
|
);
|
|
|
|
await testDb.createManyExecutions(2, firstWorkflowForUser1, testDb.createSuccessfulExecution);
|
|
|
|
await testDb.createManyExecutions(2, secondWorkflowForUser1, testDb.createSuccessfulExecution);
|
|
|
|
|
|
|
|
const [firstWorkflowForUser2, secondWorkflowForUser2] = await testDb.createManyWorkflows(
|
|
|
|
2,
|
|
|
|
{},
|
|
|
|
user2,
|
|
|
|
);
|
|
|
|
await testDb.createManyExecutions(2, firstWorkflowForUser2, testDb.createSuccessfulExecution);
|
|
|
|
await testDb.createManyExecutions(2, secondWorkflowForUser2, testDb.createSuccessfulExecution);
|
|
|
|
|
|
|
|
await testDb.shareWorkflowWithUsers(firstWorkflowForUser2, [user1]);
|
|
|
|
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authUser1Agent.get('/executions');
|
2023-04-14 02:05:42 -07:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.length).toBe(6);
|
|
|
|
expect(response.body.nextCursor).toBe(null);
|
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|