2024-08-22 02:10:37 -07:00
|
|
|
import type { ActiveWorkflowManager } from '@/active-workflow-manager';
|
2024-09-12 09:07:18 -07:00
|
|
|
import type { ExecutionEntity } from '@/databases/entities/execution-entity';
|
|
|
|
import type { User } from '@/databases/entities/user';
|
|
|
|
import { Telemetry } from '@/telemetry';
|
|
|
|
import { mockInstance } from '@test/mocking';
|
|
|
|
import { createTeamProject } from '@test-integration/db/projects';
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
import {
|
|
|
|
createErrorExecution,
|
2024-06-17 04:38:10 -07:00
|
|
|
createExecution,
|
2023-11-08 07:29:39 -08:00
|
|
|
createManyExecutions,
|
|
|
|
createSuccessfulExecution,
|
|
|
|
createWaitingExecution,
|
|
|
|
} from '../shared/db/executions';
|
2024-09-12 09:07:18 -07:00
|
|
|
import { createUser } from '../shared/db/users';
|
|
|
|
import {
|
|
|
|
createManyWorkflows,
|
|
|
|
createWorkflow,
|
|
|
|
shareWorkflowWithUsers,
|
|
|
|
} from '../shared/db/workflows';
|
|
|
|
import { randomApiKey } from '../shared/random';
|
|
|
|
import * as testDb from '../shared/test-db';
|
2024-05-31 00:40:03 -07:00
|
|
|
import type { SuperAgentTest } from '../shared/types';
|
2024-09-12 09:07:18 -07:00
|
|
|
import * as utils from '../shared/utils/';
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
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;
|
2024-05-06 08:54:05 -07:00
|
|
|
let workflowRunner: ActiveWorkflowManager;
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2024-06-12 06:05:43 -07:00
|
|
|
mockInstance(Telemetry);
|
|
|
|
|
2023-07-13 01:14:48 -07:00
|
|
|
const testServer = utils.setupTestServer({ endpointGroups: ['publicApi'] });
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-07-13 01:14:48 -07:00
|
|
|
beforeAll(async () => {
|
2024-01-24 04:38:57 -08:00
|
|
|
owner = await createUser({ role: 'global:owner', apiKey: randomApiKey() });
|
|
|
|
user1 = await createUser({ role: 'global:member', apiKey: randomApiKey() });
|
|
|
|
user2 = await createUser({ role: 'global:member', apiKey: randomApiKey() });
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-09-22 08:22:12 -07:00
|
|
|
// TODO: mock BinaryDataService instead
|
|
|
|
await utils.initBinaryDataService();
|
2022-06-08 11:53:12 -07:00
|
|
|
await utils.initNodeTypes();
|
2022-06-14 09:32:19 -07:00
|
|
|
|
2024-05-06 08:54:05 -07:00
|
|
|
workflowRunner = await utils.initActiveWorkflowManager();
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
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-07-13 01:14:48 -07:00
|
|
|
authOwnerAgent = testServer.publicApiAgentFor(owner);
|
|
|
|
authUser1Agent = testServer.publicApiAgentFor(user1);
|
|
|
|
authUser2Agent = testServer.publicApiAgentFor(user2);
|
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
|
|
|
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-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
const execution = await 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 () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, user1);
|
|
|
|
const execution = await createSuccessfulExecution(workflow);
|
2023-04-14 02:05:42 -07:00
|
|
|
|
|
|
|
const response = await authOwnerAgent.get(`/executions/${execution.id}`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('member should be able to fetch his own executions', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, user1);
|
|
|
|
const execution = await createSuccessfulExecution(workflow);
|
2023-04-14 02:05:42 -07:00
|
|
|
|
|
|
|
const response = await authUser1Agent.get(`/executions/${execution.id}`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
|
2024-06-17 04:38:10 -07:00
|
|
|
test('member should not be able to fetch custom data when includeData is not set', async () => {
|
|
|
|
const workflow = await createWorkflow({}, user1);
|
|
|
|
const execution = await createExecution(
|
|
|
|
{
|
|
|
|
finished: true,
|
|
|
|
status: 'success',
|
|
|
|
metadata: [
|
|
|
|
{ key: 'test1', value: 'value1' },
|
|
|
|
{ key: 'test2', value: 'value2' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
workflow,
|
|
|
|
);
|
|
|
|
|
|
|
|
const response = await authUser1Agent.get(`/executions/${execution.id}`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.customData).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('member should be able to fetch custom data when includeData=true', async () => {
|
|
|
|
const workflow = await createWorkflow({}, user1);
|
|
|
|
const execution = await createExecution(
|
|
|
|
{
|
|
|
|
finished: true,
|
|
|
|
status: 'success',
|
|
|
|
metadata: [
|
|
|
|
{ key: 'test1', value: 'value1' },
|
|
|
|
{ key: 'test2', value: 'value2' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
workflow,
|
|
|
|
);
|
|
|
|
|
|
|
|
const response = await authUser1Agent.get(`/executions/${execution.id}?includeData=true`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.customData).toEqual({
|
|
|
|
test1: 'value1',
|
|
|
|
test2: 'value2',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-04-14 02:05:42 -07:00
|
|
|
test('member should not get an execution of another user without the workflow being shared', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
2023-04-14 02:05:42 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
const execution = await createSuccessfulExecution(workflow);
|
2023-04-14 02:05:42 -07:00
|
|
|
|
|
|
|
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 () => {
|
2024-05-17 01:53:15 -07:00
|
|
|
testServer.license.enable('feat:sharing');
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, user1);
|
2023-04-14 02:05:42 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
const execution = await createSuccessfulExecution(workflow);
|
2023-04-14 02:05:42 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
await shareWorkflowWithUsers(workflow, [user2]);
|
2023-04-14 02:05:42 -07:00
|
|
|
|
|
|
|
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 () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
|
|
|
const execution = await 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();
|
2023-09-20 06:21:42 -07:00
|
|
|
|
|
|
|
await authOwnerAgent.get(`/executions/${execution.id}`).expect(404);
|
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 () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
2022-08-08 13:15:56 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
const successfulExecution = await createSuccessfulExecution(workflow);
|
2022-08-08 13:15:56 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
await 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
|
|
|
});
|
|
|
|
|
2024-06-05 01:14:01 -07:00
|
|
|
test('should paginate two executions', async () => {
|
|
|
|
const workflow = await createWorkflow({}, owner);
|
|
|
|
|
|
|
|
const firstSuccessfulExecution = await createSuccessfulExecution(workflow);
|
|
|
|
const secondSuccessfulExecution = await createSuccessfulExecution(workflow);
|
|
|
|
|
|
|
|
await createErrorExecution(workflow);
|
|
|
|
|
|
|
|
const firstExecutionResponse = await authOwnerAgent.get('/executions').query({
|
|
|
|
status: 'success',
|
|
|
|
limit: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(firstExecutionResponse.statusCode).toBe(200);
|
|
|
|
expect(firstExecutionResponse.body.data.length).toBe(1);
|
|
|
|
expect(firstExecutionResponse.body.nextCursor).toBeDefined();
|
|
|
|
|
|
|
|
const secondExecutionResponse = await authOwnerAgent.get('/executions').query({
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should retrieve all error executions', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
await createSuccessfulExecution(workflow);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
const errorExecution = await 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 () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
await createSuccessfulExecution(workflow);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
await createErrorExecution(workflow);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
const waitingExecution = await 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 () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const [workflow, workflow2] = await createManyWorkflows(2, {}, owner);
|
2023-03-17 09:24:05 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
const savedExecutions = await createManyExecutions(2, workflow, createSuccessfulExecution);
|
|
|
|
await createManyExecutions(2, workflow2, createSuccessfulExecution);
|
2023-03-17 09:24:05 -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
|
|
|
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
|
|
|
|
2024-08-02 05:16:17 -07:00
|
|
|
test('should return executions filtered by project ID', async () => {
|
|
|
|
/**
|
|
|
|
* Arrange
|
|
|
|
*/
|
|
|
|
const [firstProject, secondProject] = await Promise.all([
|
|
|
|
createTeamProject(),
|
|
|
|
createTeamProject(),
|
|
|
|
]);
|
|
|
|
const [firstWorkflow, secondWorkflow] = await Promise.all([
|
|
|
|
createWorkflow({}, firstProject),
|
|
|
|
createWorkflow({}, secondProject),
|
|
|
|
]);
|
|
|
|
const [firstExecution, secondExecution, _] = await Promise.all([
|
|
|
|
createExecution({}, firstWorkflow),
|
|
|
|
createExecution({}, firstWorkflow),
|
|
|
|
createExecution({}, secondWorkflow),
|
|
|
|
]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Act
|
|
|
|
*/
|
|
|
|
const response = await authOwnerAgent.get('/executions').query({
|
|
|
|
projectId: firstProject.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert
|
|
|
|
*/
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.length).toBe(2);
|
|
|
|
expect(response.body.nextCursor).toBeNull();
|
|
|
|
expect(response.body.data.map((execution: ExecutionEntity) => execution.id)).toEqual(
|
|
|
|
expect.arrayContaining([firstExecution.id, secondExecution.id]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-04-14 02:05:42 -07:00
|
|
|
test('owner should retrieve all executions regardless of ownership', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const [firstWorkflowForUser1, secondWorkflowForUser1] = await createManyWorkflows(2, {}, user1);
|
|
|
|
await createManyExecutions(2, firstWorkflowForUser1, createSuccessfulExecution);
|
|
|
|
await createManyExecutions(2, secondWorkflowForUser1, createSuccessfulExecution);
|
|
|
|
|
|
|
|
const [firstWorkflowForUser2, secondWorkflowForUser2] = await createManyWorkflows(2, {}, user2);
|
|
|
|
await createManyExecutions(2, firstWorkflowForUser2, createSuccessfulExecution);
|
|
|
|
await createManyExecutions(2, secondWorkflowForUser2, createSuccessfulExecution);
|
2023-04-14 02:05:42 -07:00
|
|
|
|
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 () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const [firstWorkflowForUser1, secondWorkflowForUser1] = await createManyWorkflows(2, {}, user1);
|
|
|
|
await createManyExecutions(2, firstWorkflowForUser1, createSuccessfulExecution);
|
|
|
|
await createManyExecutions(2, secondWorkflowForUser1, createSuccessfulExecution);
|
|
|
|
|
|
|
|
const [firstWorkflowForUser2, secondWorkflowForUser2] = await createManyWorkflows(2, {}, user2);
|
|
|
|
await createManyExecutions(2, firstWorkflowForUser2, createSuccessfulExecution);
|
|
|
|
await createManyExecutions(2, secondWorkflowForUser2, createSuccessfulExecution);
|
2023-04-14 02:05:42 -07:00
|
|
|
|
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 () => {
|
2024-05-17 01:53:15 -07:00
|
|
|
testServer.license.enable('feat:sharing');
|
2023-11-08 07:29:39 -08:00
|
|
|
const [firstWorkflowForUser1, secondWorkflowForUser1] = await createManyWorkflows(2, {}, user1);
|
|
|
|
await createManyExecutions(2, firstWorkflowForUser1, createSuccessfulExecution);
|
|
|
|
await createManyExecutions(2, secondWorkflowForUser1, createSuccessfulExecution);
|
|
|
|
|
|
|
|
const [firstWorkflowForUser2, secondWorkflowForUser2] = await createManyWorkflows(2, {}, user2);
|
|
|
|
await createManyExecutions(2, firstWorkflowForUser2, createSuccessfulExecution);
|
|
|
|
await createManyExecutions(2, secondWorkflowForUser2, createSuccessfulExecution);
|
|
|
|
|
|
|
|
await shareWorkflowWithUsers(firstWorkflowForUser2, [user1]);
|
2023-04-14 02:05:42 -07:00
|
|
|
|
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
|
|
|
});
|