2024-05-31 00:40:03 -07:00
|
|
|
import { Container } from 'typedi';
|
2023-11-10 06:04:26 -08:00
|
|
|
import type { INode } from 'n8n-workflow';
|
2024-05-31 00:40:03 -07:00
|
|
|
|
|
|
|
import config from '@/config';
|
2023-11-10 06:04:26 -08:00
|
|
|
import { STARTING_NODES } from '@/constants';
|
2024-08-27 07:44:32 -07:00
|
|
|
import type { TagEntity } from '@/databases/entities/tag-entity';
|
|
|
|
import type { User } from '@/databases/entities/User';
|
|
|
|
import type { Project } from '@/databases/entities/project';
|
2024-05-31 00:40:03 -07:00
|
|
|
import { ProjectRepository } from '@db/repositories/project.repository';
|
2024-08-27 07:44:32 -07:00
|
|
|
import { SharedWorkflowRepository } from '@/databases/repositories/shared-workflow.repository';
|
|
|
|
import { WorkflowHistoryRepository } from '@db/repositories/workflow-history.repository';
|
2024-08-22 02:10:37 -07:00
|
|
|
import { ActiveWorkflowManager } from '@/active-workflow-manager';
|
2024-01-24 04:38:57 -08:00
|
|
|
import { ExecutionService } from '@/executions/execution.service';
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2022-11-09 06:25:00 -08:00
|
|
|
import { randomApiKey } from '../shared/random';
|
2023-07-13 01:14:48 -07:00
|
|
|
import * as utils from '../shared/utils/';
|
2022-06-08 11:53:12 -07:00
|
|
|
import * as testDb from '../shared/testDb';
|
2023-11-08 07:29:39 -08:00
|
|
|
import { createUser } from '../shared/db/users';
|
|
|
|
import { createWorkflow, createWorkflowWithTrigger } from '../shared/db/workflows';
|
|
|
|
import { createTag } from '../shared/db/tags';
|
2023-12-18 07:10:30 -08:00
|
|
|
import { mockInstance } from '../../shared/mocking';
|
2024-05-31 00:40:03 -07:00
|
|
|
import type { SuperAgentTest } from '../shared/types';
|
2024-06-12 06:05:43 -07:00
|
|
|
import { Telemetry } from '@/telemetry';
|
2024-07-30 08:05:48 -07:00
|
|
|
import { ProjectService } from '@/services/project.service';
|
|
|
|
import { createTeamProject } from '@test-integration/db/projects';
|
2024-06-12 06:05:43 -07:00
|
|
|
|
|
|
|
mockInstance(Telemetry);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
let owner: User;
|
2024-05-17 01:53:15 -07:00
|
|
|
let ownerPersonalProject: Project;
|
2023-03-17 09:24:05 -07:00
|
|
|
let member: User;
|
2024-05-17 01:53:15 -07:00
|
|
|
let memberPersonalProject: Project;
|
2023-03-17 09:24:05 -07:00
|
|
|
let authOwnerAgent: SuperAgentTest;
|
|
|
|
let authMemberAgent: SuperAgentTest;
|
2024-05-06 08:54:05 -07:00
|
|
|
let activeWorkflowManager: ActiveWorkflowManager;
|
2023-03-17 09:24:05 -07:00
|
|
|
|
2023-07-13 01:14:48 -07:00
|
|
|
const testServer = utils.setupTestServer({ endpointGroups: ['publicApi'] });
|
2023-11-30 00:23:09 -08:00
|
|
|
const license = testServer.license;
|
2023-10-23 07:30:36 -07:00
|
|
|
|
2024-01-17 06:42:19 -08:00
|
|
|
mockInstance(ExecutionService);
|
2023-12-18 07:10:30 -08:00
|
|
|
|
2023-07-13 01:14:48 -07:00
|
|
|
beforeAll(async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
owner = await createUser({
|
2024-01-24 04:38:57 -08:00
|
|
|
role: 'global:owner',
|
2023-03-17 09:24:05 -07:00
|
|
|
apiKey: randomApiKey(),
|
2023-03-15 06:24:09 -07:00
|
|
|
});
|
2024-05-17 01:53:15 -07:00
|
|
|
ownerPersonalProject = await Container.get(ProjectRepository).getPersonalProjectForUserOrFail(
|
|
|
|
owner.id,
|
|
|
|
);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
member = await createUser({
|
2024-01-24 04:38:57 -08:00
|
|
|
role: 'global:member',
|
2023-03-17 09:24:05 -07:00
|
|
|
apiKey: randomApiKey(),
|
|
|
|
});
|
2024-05-17 01:53:15 -07:00
|
|
|
memberPersonalProject = await Container.get(ProjectRepository).getPersonalProjectForUserOrFail(
|
|
|
|
member.id,
|
|
|
|
);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
await utils.initNodeTypes();
|
2023-12-15 03:59:56 -08:00
|
|
|
|
2024-05-06 08:54:05 -07:00
|
|
|
activeWorkflowManager = Container.get(ActiveWorkflowManager);
|
2023-12-15 03:59:56 -08:00
|
|
|
|
2024-05-06 08:54:05 -07:00
|
|
|
await activeWorkflowManager.init();
|
2023-03-17 09:24:05 -07:00
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
beforeEach(async () => {
|
2023-10-23 07:30:36 -07:00
|
|
|
await testDb.truncate([
|
|
|
|
'SharedCredentials',
|
|
|
|
'SharedWorkflow',
|
|
|
|
'Tag',
|
|
|
|
'Workflow',
|
|
|
|
'Credentials',
|
2023-11-10 06:04:26 -08:00
|
|
|
'WorkflowHistory',
|
2023-10-23 07:30:36 -07:00
|
|
|
]);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-07-13 01:14:48 -07:00
|
|
|
authOwnerAgent = testServer.publicApiAgentFor(owner);
|
|
|
|
authMemberAgent = testServer.publicApiAgentFor(member);
|
2023-03-17 09:24:05 -07:00
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
afterEach(async () => {
|
2024-05-06 08:54:05 -07:00
|
|
|
await activeWorkflowManager?.removeAll();
|
2023-03-17 09:24:05 -07:00
|
|
|
});
|
2023-03-15 06:24:09 -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);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('GET /workflows', () => {
|
|
|
|
test('should fail due to missing API Key', testWithAPIKey('get', '/workflows', 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', '/workflows', 'abcXYZ'));
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should return all owned workflows', async () => {
|
|
|
|
await Promise.all([
|
2023-11-08 07:29:39 -08:00
|
|
|
createWorkflow({}, member),
|
|
|
|
createWorkflow({}, member),
|
|
|
|
createWorkflow({}, member),
|
2023-03-17 09:24:05 -07:00
|
|
|
]);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authMemberAgent.get('/workflows');
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.length).toBe(3);
|
|
|
|
expect(response.body.nextCursor).toBeNull();
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
for (const workflow of response.body.data) {
|
2023-03-15 06:24:09 -07:00
|
|
|
const {
|
|
|
|
id,
|
|
|
|
connections,
|
|
|
|
active,
|
|
|
|
staticData,
|
|
|
|
nodes,
|
|
|
|
settings,
|
|
|
|
name,
|
|
|
|
createdAt,
|
|
|
|
updatedAt,
|
2023-03-17 09:24:05 -07:00
|
|
|
tags,
|
|
|
|
} = workflow;
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(id).toBeDefined();
|
2023-03-15 06:24:09 -07:00
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(connections).toBeDefined();
|
|
|
|
expect(active).toBe(false);
|
|
|
|
expect(staticData).toBeDefined();
|
|
|
|
expect(nodes).toBeDefined();
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(tags).toBeDefined();
|
2023-03-15 06:24:09 -07:00
|
|
|
expect(settings).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
2023-03-17 09:24:05 -07:00
|
|
|
}
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should return all owned workflows with pagination', async () => {
|
|
|
|
await Promise.all([
|
2023-11-08 07:29:39 -08:00
|
|
|
createWorkflow({}, member),
|
|
|
|
createWorkflow({}, member),
|
|
|
|
createWorkflow({}, member),
|
2023-03-17 09:24:05 -07:00
|
|
|
]);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authMemberAgent.get('/workflows?limit=1');
|
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).not.toBeNull();
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response2 = await authMemberAgent.get(
|
|
|
|
`/workflows?limit=1&cursor=${response.body.nextCursor}`,
|
|
|
|
);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response2.statusCode).toBe(200);
|
|
|
|
expect(response2.body.data.length).toBe(1);
|
|
|
|
expect(response2.body.nextCursor).not.toBeNull();
|
|
|
|
expect(response2.body.nextCursor).not.toBe(response.body.nextCursor);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const responses = [...response.body.data, ...response2.body.data];
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
for (const workflow of responses) {
|
2023-03-15 06:24:09 -07:00
|
|
|
const {
|
|
|
|
id,
|
|
|
|
connections,
|
|
|
|
active,
|
|
|
|
staticData,
|
|
|
|
nodes,
|
|
|
|
settings,
|
|
|
|
name,
|
|
|
|
createdAt,
|
|
|
|
updatedAt,
|
|
|
|
tags,
|
2023-03-17 09:24:05 -07:00
|
|
|
} = workflow;
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(connections).toBeDefined();
|
2023-03-15 06:24:09 -07:00
|
|
|
expect(active).toBe(false);
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(staticData).toBeDefined();
|
|
|
|
expect(nodes).toBeDefined();
|
|
|
|
expect(tags).toBeDefined();
|
|
|
|
expect(settings).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
}
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
// check that we really received a different result
|
2023-06-20 10:13:18 -07:00
|
|
|
expect(response.body.data[0].id).not.toEqual(response2.body.data[0].id);
|
2023-03-17 09:24:05 -07:00
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should return all owned workflows filtered by tag', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const tag = await createTag({});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const [workflow] = await Promise.all([
|
2023-11-08 07:29:39 -08:00
|
|
|
createWorkflow({ tags: [tag] }, member),
|
|
|
|
createWorkflow({}, member),
|
2023-03-17 09:24:05 -07:00
|
|
|
]);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authMemberAgent.get(`/workflows?tags=${tag.name}`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.length).toBe(1);
|
|
|
|
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
connections,
|
|
|
|
active,
|
|
|
|
staticData,
|
|
|
|
nodes,
|
|
|
|
settings,
|
|
|
|
name,
|
|
|
|
createdAt,
|
|
|
|
updatedAt,
|
|
|
|
tags: wfTags,
|
|
|
|
} = response.body.data[0];
|
|
|
|
|
|
|
|
expect(id).toBe(workflow.id);
|
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(connections).toBeDefined();
|
|
|
|
expect(active).toBe(false);
|
|
|
|
expect(staticData).toBeDefined();
|
|
|
|
expect(nodes).toBeDefined();
|
|
|
|
expect(settings).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
|
|
|
|
expect(wfTags.length).toBe(1);
|
|
|
|
expect(wfTags[0].id).toBe(tag.id);
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should return all owned workflows filtered by tags', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const tags = await Promise.all([await createTag({}), await createTag({})]);
|
2023-03-17 09:24:05 -07:00
|
|
|
const tagNames = tags.map((tag) => tag.name).join(',');
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const [workflow1, workflow2] = await Promise.all([
|
2023-11-08 07:29:39 -08:00
|
|
|
createWorkflow({ tags }, member),
|
|
|
|
createWorkflow({ tags }, member),
|
|
|
|
createWorkflow({}, member),
|
|
|
|
createWorkflow({ tags: [tags[0]] }, member),
|
|
|
|
createWorkflow({ tags: [tags[1]] }, member),
|
2023-03-17 09:24:05 -07:00
|
|
|
]);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authMemberAgent.get(`/workflows?tags=${tagNames}`);
|
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(2);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
for (const workflow of response.body.data) {
|
2023-03-15 06:24:09 -07:00
|
|
|
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } =
|
2023-03-17 09:24:05 -07:00
|
|
|
workflow;
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect([workflow1.id, workflow2.id].includes(id)).toBe(true);
|
|
|
|
|
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(connections).toBeDefined();
|
2023-03-15 06:24:09 -07:00
|
|
|
expect(active).toBe(false);
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(staticData).toBeDefined();
|
|
|
|
expect(nodes).toBeDefined();
|
|
|
|
expect(settings).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(workflow.tags.length).toBe(2);
|
|
|
|
workflow.tags.forEach((tag: TagEntity) => {
|
|
|
|
expect(tags.some((savedTag) => savedTag.id === tag.id)).toBe(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2024-08-13 06:05:40 -07:00
|
|
|
test('for owner, should return all workflows filtered by `projectId`', async () => {
|
|
|
|
license.setQuota('quota:maxTeamProjects', -1);
|
|
|
|
const firstProject = await Container.get(ProjectService).createTeamProject('First', owner);
|
|
|
|
const secondProject = await Container.get(ProjectService).createTeamProject('Second', member);
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
createWorkflow({ name: 'First workflow' }, firstProject),
|
|
|
|
createWorkflow({ name: 'Second workflow' }, secondProject),
|
|
|
|
]);
|
|
|
|
|
|
|
|
const firstResponse = await authOwnerAgent.get(`/workflows?projectId=${firstProject.id}`);
|
|
|
|
const secondResponse = await authOwnerAgent.get(`/workflows?projectId=${secondProject.id}`);
|
|
|
|
|
|
|
|
expect(firstResponse.statusCode).toBe(200);
|
|
|
|
expect(firstResponse.body.data.length).toBe(1);
|
|
|
|
expect(firstResponse.body.data[0].name).toBe('First workflow');
|
|
|
|
|
|
|
|
expect(secondResponse.statusCode).toBe(200);
|
|
|
|
expect(secondResponse.body.data.length).toBe(1);
|
|
|
|
expect(secondResponse.body.data[0].name).toBe('Second workflow');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('for member, should return all member-accessible workflows filtered by `projectId`', async () => {
|
|
|
|
license.setQuota('quota:maxTeamProjects', -1);
|
2024-07-30 08:05:48 -07:00
|
|
|
const otherProject = await Container.get(ProjectService).createTeamProject(
|
|
|
|
'Other project',
|
|
|
|
member,
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
createWorkflow({}, member),
|
|
|
|
createWorkflow({ name: 'Other workflow' }, otherProject),
|
|
|
|
]);
|
|
|
|
|
|
|
|
const response = await authMemberAgent.get(`/workflows?projectId=${otherProject.id}`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.length).toBe(1);
|
|
|
|
expect(response.body.data[0].name).toBe('Other workflow');
|
|
|
|
});
|
|
|
|
|
2024-02-09 07:10:03 -08:00
|
|
|
test('should return all owned workflows filtered by name', async () => {
|
|
|
|
const workflowName = 'Workflow 1';
|
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
await Promise.all([createWorkflow({ name: workflowName }, member), createWorkflow({}, member)]);
|
2024-02-09 07:10:03 -08:00
|
|
|
|
|
|
|
const response = await authMemberAgent.get(`/workflows?name=${workflowName}`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.length).toBe(1);
|
|
|
|
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
connections,
|
|
|
|
active,
|
|
|
|
staticData,
|
|
|
|
nodes,
|
|
|
|
settings,
|
|
|
|
name,
|
|
|
|
createdAt,
|
|
|
|
updatedAt,
|
2024-05-17 01:53:15 -07:00
|
|
|
tags,
|
2024-02-09 07:10:03 -08:00
|
|
|
} = response.body.data[0];
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(name).toBe(workflowName);
|
|
|
|
expect(connections).toBeDefined();
|
|
|
|
expect(active).toBe(false);
|
|
|
|
expect(staticData).toBeDefined();
|
|
|
|
expect(nodes).toBeDefined();
|
|
|
|
expect(settings).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(tags).toEqual([]);
|
2024-02-09 07:10:03 -08:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should return all workflows for owner', async () => {
|
|
|
|
await Promise.all([
|
2023-11-08 07:29:39 -08:00
|
|
|
createWorkflow({}, owner),
|
|
|
|
createWorkflow({}, member),
|
|
|
|
createWorkflow({}, owner),
|
|
|
|
createWorkflow({}, member),
|
|
|
|
createWorkflow({}, owner),
|
2023-03-17 09:24:05 -07:00
|
|
|
]);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent.get('/workflows');
|
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(5);
|
|
|
|
expect(response.body.nextCursor).toBeNull();
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
for (const workflow of response.body.data) {
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
connections,
|
|
|
|
active,
|
|
|
|
staticData,
|
|
|
|
nodes,
|
|
|
|
settings,
|
|
|
|
name,
|
|
|
|
createdAt,
|
|
|
|
updatedAt,
|
|
|
|
tags,
|
|
|
|
} = workflow;
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(connections).toBeDefined();
|
2023-03-15 06:24:09 -07:00
|
|
|
expect(active).toBe(false);
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(staticData).toBeDefined();
|
|
|
|
expect(nodes).toBeDefined();
|
|
|
|
expect(tags).toBeDefined();
|
|
|
|
expect(settings).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
}
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
2023-03-17 09:24:05 -07:00
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
describe('GET /workflows/:id', () => {
|
|
|
|
test('should fail due to missing API Key', testWithAPIKey('get', '/workflows/2', 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', '/workflows/2', 'abcXYZ'));
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should fail due to non-existing workflow', async () => {
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authOwnerAgent.get('/workflows/2');
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response.statusCode).toBe(404);
|
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should retrieve workflow', async () => {
|
|
|
|
// create and assign workflow to owner
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
2023-03-17 09:24:05 -07:00
|
|
|
|
|
|
|
const response = await authMemberAgent.get(`/workflows/${workflow.id}`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
connections,
|
|
|
|
active,
|
|
|
|
staticData,
|
|
|
|
nodes,
|
|
|
|
settings,
|
|
|
|
name,
|
|
|
|
createdAt,
|
|
|
|
updatedAt,
|
|
|
|
tags,
|
|
|
|
} = response.body;
|
|
|
|
|
|
|
|
expect(id).toEqual(workflow.id);
|
|
|
|
expect(name).toEqual(workflow.name);
|
|
|
|
expect(connections).toEqual(workflow.connections);
|
|
|
|
expect(active).toBe(false);
|
|
|
|
expect(staticData).toEqual(workflow.staticData);
|
|
|
|
expect(nodes).toEqual(workflow.nodes);
|
|
|
|
expect(tags).toEqual([]);
|
|
|
|
expect(settings).toEqual(workflow.settings);
|
|
|
|
expect(createdAt).toEqual(workflow.createdAt.toISOString());
|
|
|
|
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should retrieve non-owned workflow for owner', async () => {
|
|
|
|
// create and assign workflow to owner
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent.get(`/workflows/${workflow.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, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } =
|
|
|
|
response.body;
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(id).toEqual(workflow.id);
|
|
|
|
expect(name).toEqual(workflow.name);
|
|
|
|
expect(connections).toEqual(workflow.connections);
|
|
|
|
expect(active).toBe(false);
|
|
|
|
expect(staticData).toEqual(workflow.staticData);
|
|
|
|
expect(nodes).toEqual(workflow.nodes);
|
|
|
|
expect(settings).toEqual(workflow.settings);
|
|
|
|
expect(createdAt).toEqual(workflow.createdAt.toISOString());
|
|
|
|
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
|
|
|
});
|
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
describe('DELETE /workflows/:id', () => {
|
|
|
|
test('should fail due to missing API Key', testWithAPIKey('delete', '/workflows/2', 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', '/workflows/2', 'abcXYZ'));
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should fail due to non-existing workflow', async () => {
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authOwnerAgent.delete('/workflows/2');
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response.statusCode).toBe(404);
|
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should delete the workflow', async () => {
|
|
|
|
// create and assign workflow to owner
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authMemberAgent.delete(`/workflows/${workflow.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, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } =
|
|
|
|
response.body;
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(id).toEqual(workflow.id);
|
|
|
|
expect(name).toEqual(workflow.name);
|
|
|
|
expect(connections).toEqual(workflow.connections);
|
|
|
|
expect(active).toBe(false);
|
|
|
|
expect(staticData).toEqual(workflow.staticData);
|
|
|
|
expect(nodes).toEqual(workflow.nodes);
|
|
|
|
expect(settings).toEqual(workflow.settings);
|
|
|
|
expect(createdAt).toEqual(workflow.createdAt.toISOString());
|
|
|
|
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
// make sure the workflow actually deleted from the db
|
2023-11-10 06:04:26 -08:00
|
|
|
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOneBy({
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: workflow.id,
|
2023-03-15 06:24:09 -07:00
|
|
|
});
|
2023-03-17 09:24:05 -07:00
|
|
|
|
|
|
|
expect(sharedWorkflow).toBeNull();
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should delete non-owned workflow when owner', async () => {
|
|
|
|
// create and assign workflow to owner
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authMemberAgent.delete(`/workflows/${workflow.id}`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } =
|
|
|
|
response.body;
|
|
|
|
|
|
|
|
expect(id).toEqual(workflow.id);
|
|
|
|
expect(name).toEqual(workflow.name);
|
|
|
|
expect(connections).toEqual(workflow.connections);
|
|
|
|
expect(active).toBe(false);
|
|
|
|
expect(staticData).toEqual(workflow.staticData);
|
|
|
|
expect(nodes).toEqual(workflow.nodes);
|
|
|
|
expect(settings).toEqual(workflow.settings);
|
|
|
|
expect(createdAt).toEqual(workflow.createdAt.toISOString());
|
|
|
|
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
|
|
|
|
|
|
|
// make sure the workflow actually deleted from the db
|
2023-11-10 06:04:26 -08:00
|
|
|
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOneBy({
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: workflow.id,
|
2023-03-15 06:24:09 -07:00
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(sharedWorkflow).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
describe('POST /workflows/:id/activate', () => {
|
|
|
|
test('should fail due to missing API Key', testWithAPIKey('post', '/workflows/2/activate', null));
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test(
|
|
|
|
'should fail due to invalid API Key',
|
|
|
|
testWithAPIKey('post', '/workflows/2/activate', 'abcXYZ'),
|
|
|
|
);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should fail due to non-existing workflow', async () => {
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authOwnerAgent.post('/workflows/2/activate');
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response.statusCode).toBe(404);
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should fail due to trying to activate a workflow without a trigger', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent.post(`/workflows/${workflow.id}/activate`);
|
|
|
|
expect(response.statusCode).toBe(400);
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should set workflow as active', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflowWithTrigger({}, member);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authMemberAgent.post(`/workflows/${workflow.id}/activate`);
|
2023-03-15 06:24:09 -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, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } =
|
|
|
|
response.body;
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(id).toEqual(workflow.id);
|
|
|
|
expect(name).toEqual(workflow.name);
|
|
|
|
expect(connections).toEqual(workflow.connections);
|
|
|
|
expect(active).toBe(true);
|
|
|
|
expect(staticData).toEqual(workflow.staticData);
|
|
|
|
expect(nodes).toEqual(workflow.nodes);
|
|
|
|
expect(settings).toEqual(workflow.settings);
|
|
|
|
expect(createdAt).toEqual(workflow.createdAt.toISOString());
|
|
|
|
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
// check whether the workflow is on the database
|
2023-11-10 06:04:26 -08:00
|
|
|
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
2023-03-17 09:24:05 -07:00
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: memberPersonalProject.id,
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: workflow.id,
|
|
|
|
},
|
|
|
|
relations: ['workflow'],
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(sharedWorkflow?.workflow.active).toBe(true);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
// check whether the workflow is on the active workflow runner
|
2024-05-06 08:54:05 -07:00
|
|
|
expect(await activeWorkflowManager.isActive(workflow.id)).toBe(true);
|
2023-03-17 09:24:05 -07:00
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should set non-owned workflow as active when owner', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflowWithTrigger({}, member);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
const response = await authMemberAgent.post(`/workflows/${workflow.id}/activate`).expect(200);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } =
|
|
|
|
response.body;
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(id).toEqual(workflow.id);
|
|
|
|
expect(name).toEqual(workflow.name);
|
|
|
|
expect(connections).toEqual(workflow.connections);
|
|
|
|
expect(active).toBe(true);
|
|
|
|
expect(staticData).toEqual(workflow.staticData);
|
|
|
|
expect(nodes).toEqual(workflow.nodes);
|
|
|
|
expect(settings).toEqual(workflow.settings);
|
|
|
|
expect(createdAt).toEqual(workflow.createdAt.toISOString());
|
|
|
|
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
// check whether the workflow is on the database
|
2023-11-10 06:04:26 -08:00
|
|
|
const sharedOwnerWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
2023-03-17 09:24:05 -07:00
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: ownerPersonalProject.id,
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: workflow.id,
|
|
|
|
},
|
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(sharedOwnerWorkflow).toBeNull();
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-11-10 06:04:26 -08:00
|
|
|
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
2023-03-17 09:24:05 -07:00
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: memberPersonalProject.id,
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: workflow.id,
|
|
|
|
},
|
|
|
|
relations: ['workflow'],
|
2023-03-15 06:24:09 -07:00
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(sharedWorkflow?.workflow.active).toBe(true);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
// check whether the workflow is on the active workflow runner
|
2024-05-06 08:54:05 -07:00
|
|
|
expect(await activeWorkflowManager.isActive(workflow.id)).toBe(true);
|
2023-03-17 09:24:05 -07:00
|
|
|
});
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
describe('POST /workflows/:id/deactivate', () => {
|
|
|
|
test(
|
|
|
|
'should fail due to missing API Key',
|
|
|
|
testWithAPIKey('post', '/workflows/2/deactivate', null),
|
|
|
|
);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test(
|
|
|
|
'should fail due to invalid API Key',
|
|
|
|
testWithAPIKey('post', '/workflows/2/deactivate', 'abcXYZ'),
|
|
|
|
);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should fail due to non-existing workflow', async () => {
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authOwnerAgent.post('/workflows/2/deactivate');
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response.statusCode).toBe(404);
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should deactivate workflow', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflowWithTrigger({}, member);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
await authMemberAgent.post(`/workflows/${workflow.id}/activate`);
|
|
|
|
|
|
|
|
const workflowDeactivationResponse = await authMemberAgent.post(
|
|
|
|
`/workflows/${workflow.id}/deactivate`,
|
|
|
|
);
|
|
|
|
|
|
|
|
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } =
|
|
|
|
workflowDeactivationResponse.body;
|
|
|
|
|
|
|
|
expect(id).toEqual(workflow.id);
|
|
|
|
expect(name).toEqual(workflow.name);
|
|
|
|
expect(connections).toEqual(workflow.connections);
|
|
|
|
expect(active).toBe(false);
|
|
|
|
expect(staticData).toEqual(workflow.staticData);
|
|
|
|
expect(nodes).toEqual(workflow.nodes);
|
|
|
|
expect(settings).toEqual(workflow.settings);
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
|
|
|
|
// get the workflow after it was deactivated
|
2023-11-10 06:04:26 -08:00
|
|
|
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
2023-03-17 09:24:05 -07:00
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: memberPersonalProject.id,
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: workflow.id,
|
|
|
|
},
|
|
|
|
relations: ['workflow'],
|
2023-03-15 06:24:09 -07:00
|
|
|
});
|
2023-03-17 09:24:05 -07:00
|
|
|
|
|
|
|
// check whether the workflow is deactivated in the database
|
|
|
|
expect(sharedWorkflow?.workflow.active).toBe(false);
|
|
|
|
|
2024-05-06 08:54:05 -07:00
|
|
|
expect(await activeWorkflowManager.isActive(workflow.id)).toBe(false);
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should deactivate non-owned workflow when owner', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflowWithTrigger({}, member);
|
2023-03-17 09:24:05 -07:00
|
|
|
|
|
|
|
await authMemberAgent.post(`/workflows/${workflow.id}/activate`);
|
|
|
|
|
|
|
|
const workflowDeactivationResponse = await authMemberAgent.post(
|
|
|
|
`/workflows/${workflow.id}/deactivate`,
|
|
|
|
);
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const { id, connections, active, staticData, nodes, settings, name, createdAt, updatedAt } =
|
|
|
|
workflowDeactivationResponse.body;
|
|
|
|
|
|
|
|
expect(id).toEqual(workflow.id);
|
|
|
|
expect(name).toEqual(workflow.name);
|
|
|
|
expect(connections).toEqual(workflow.connections);
|
|
|
|
expect(active).toBe(false);
|
|
|
|
expect(staticData).toEqual(workflow.staticData);
|
|
|
|
expect(nodes).toEqual(workflow.nodes);
|
|
|
|
expect(settings).toEqual(workflow.settings);
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
|
|
|
|
// check whether the workflow is deactivated in the database
|
2023-11-10 06:04:26 -08:00
|
|
|
const sharedOwnerWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
2023-03-17 09:24:05 -07:00
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: ownerPersonalProject.id,
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: workflow.id,
|
|
|
|
},
|
2023-03-15 06:24:09 -07:00
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(sharedOwnerWorkflow).toBeNull();
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-11-10 06:04:26 -08:00
|
|
|
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
2023-03-17 09:24:05 -07:00
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: memberPersonalProject.id,
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: workflow.id,
|
|
|
|
},
|
|
|
|
relations: ['workflow'],
|
2023-03-15 06:24:09 -07:00
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(sharedWorkflow?.workflow.active).toBe(false);
|
|
|
|
|
2024-05-06 08:54:05 -07:00
|
|
|
expect(await activeWorkflowManager.isActive(workflow.id)).toBe(false);
|
2023-03-17 09:24:05 -07:00
|
|
|
});
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
describe('POST /workflows', () => {
|
|
|
|
test('should fail due to missing API Key', testWithAPIKey('post', '/workflows', null));
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should fail due to invalid API Key', testWithAPIKey('post', '/workflows', 'abcXYZ'));
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should fail due to invalid body', async () => {
|
|
|
|
const response = await authOwnerAgent.post('/workflows').send({});
|
|
|
|
expect(response.statusCode).toBe(400);
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should create workflow', async () => {
|
|
|
|
const payload = {
|
|
|
|
name: 'testing',
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
2023-03-15 06:24:09 -07:00
|
|
|
},
|
2023-03-17 09:24:05 -07:00
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: null,
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: true,
|
|
|
|
saveManualExecutions: true,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
2024-04-05 08:49:14 -07:00
|
|
|
executionOrder: 'v1',
|
2023-03-17 09:24:05 -07:00
|
|
|
},
|
|
|
|
};
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authMemberAgent.post('/workflows').send(payload);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
const { id, name, nodes, connections, staticData, active, settings, createdAt, updatedAt } =
|
|
|
|
response.body;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(name).toBe(payload.name);
|
|
|
|
expect(connections).toEqual(payload.connections);
|
|
|
|
expect(settings).toEqual(payload.settings);
|
|
|
|
expect(staticData).toEqual(payload.staticData);
|
|
|
|
expect(nodes).toEqual(payload.nodes);
|
|
|
|
expect(active).toBe(false);
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toEqual(createdAt);
|
|
|
|
|
|
|
|
// check if created workflow in DB
|
2023-11-10 06:04:26 -08:00
|
|
|
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
2023-03-17 09:24:05 -07:00
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: memberPersonalProject.id,
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: response.body.id,
|
|
|
|
},
|
2024-01-24 04:38:57 -08:00
|
|
|
relations: ['workflow'],
|
2023-03-15 06:24:09 -07:00
|
|
|
});
|
2022-06-08 11:53:12 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(sharedWorkflow?.workflow.name).toBe(name);
|
|
|
|
expect(sharedWorkflow?.workflow.createdAt.toISOString()).toBe(createdAt);
|
2024-01-24 04:38:57 -08:00
|
|
|
expect(sharedWorkflow?.role).toEqual('workflow:owner');
|
2023-03-17 09:24:05 -07:00
|
|
|
});
|
2023-07-18 05:03:19 -07:00
|
|
|
|
2023-10-23 07:30:36 -07:00
|
|
|
test('should create workflow history version when licensed', async () => {
|
2023-11-30 00:23:09 -08:00
|
|
|
license.enable('feat:workflowHistory');
|
2023-10-23 07:30:36 -07:00
|
|
|
const payload = {
|
|
|
|
name: 'testing',
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: null,
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: true,
|
|
|
|
saveManualExecutions: true,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await authMemberAgent.post('/workflows').send(payload);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
const { id } = response.body;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(
|
|
|
|
await Container.get(WorkflowHistoryRepository).count({ where: { workflowId: id } }),
|
|
|
|
).toBe(1);
|
|
|
|
const historyVersion = await Container.get(WorkflowHistoryRepository).findOne({
|
|
|
|
where: {
|
|
|
|
workflowId: id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(historyVersion).not.toBeNull();
|
|
|
|
expect(historyVersion!.connections).toEqual(payload.connections);
|
|
|
|
expect(historyVersion!.nodes).toEqual(payload.nodes);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not create workflow history version when not licensed', async () => {
|
2023-11-30 00:23:09 -08:00
|
|
|
license.disable('feat:workflowHistory');
|
2023-10-23 07:30:36 -07:00
|
|
|
const payload = {
|
|
|
|
name: 'testing',
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: null,
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: true,
|
|
|
|
saveManualExecutions: true,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await authMemberAgent.post('/workflows').send(payload);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
const { id } = response.body;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(
|
|
|
|
await Container.get(WorkflowHistoryRepository).count({ where: { workflowId: id } }),
|
|
|
|
).toBe(0);
|
|
|
|
});
|
|
|
|
|
2023-07-18 05:03:19 -07:00
|
|
|
test('should not add a starting node if the payload has no starting nodes', async () => {
|
|
|
|
const response = await authMemberAgent.post('/workflows').send({
|
|
|
|
name: 'testing',
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Hacker News',
|
|
|
|
type: 'n8n-nodes-base.hackerNews',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: true,
|
|
|
|
saveManualExecutions: true,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const found = response.body.nodes.find((node: INode) => STARTING_NODES.includes(node.type));
|
|
|
|
|
|
|
|
expect(found).toBeUndefined();
|
|
|
|
});
|
2023-03-17 09:24:05 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('PUT /workflows/:id', () => {
|
|
|
|
test('should fail due to missing API Key', testWithAPIKey('put', '/workflows/1', null));
|
|
|
|
|
|
|
|
test('should fail due to invalid API Key', testWithAPIKey('put', '/workflows/1', 'abcXYZ'));
|
|
|
|
|
|
|
|
test('should fail due to non-existing workflow', async () => {
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authOwnerAgent.put('/workflows/1').send({
|
2023-03-17 09:24:05 -07:00
|
|
|
name: 'testing',
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
2023-03-15 06:24:09 -07:00
|
|
|
},
|
2023-03-17 09:24:05 -07:00
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: null,
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: true,
|
|
|
|
saveManualExecutions: true,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
|
|
|
},
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response.statusCode).toBe(404);
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should fail due to invalid body', async () => {
|
2023-05-02 01:37:19 -07:00
|
|
|
const response = await authOwnerAgent.put('/workflows/1').send({
|
2023-03-17 09:24:05 -07:00
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: null,
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: true,
|
|
|
|
saveManualExecutions: true,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
|
|
|
},
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(response.statusCode).toBe(400);
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should update workflow', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
2023-03-17 09:24:05 -07:00
|
|
|
const payload = {
|
|
|
|
name: 'name updated',
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
2023-03-15 06:24:09 -07:00
|
|
|
},
|
2023-03-17 09:24:05 -07:00
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Cron',
|
|
|
|
type: 'n8n-nodes-base.cron',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [400, 300],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: '{"id":1}',
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: false,
|
|
|
|
saveManualExecutions: false,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
|
|
|
},
|
|
|
|
};
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authMemberAgent.put(`/workflows/${workflow.id}`).send(payload);
|
|
|
|
|
|
|
|
const { id, name, nodes, connections, staticData, active, settings, createdAt, updatedAt } =
|
|
|
|
response.body;
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
expect(id).toBe(workflow.id);
|
|
|
|
expect(name).toBe(payload.name);
|
|
|
|
expect(connections).toEqual(payload.connections);
|
|
|
|
expect(settings).toEqual(payload.settings);
|
|
|
|
expect(staticData).toMatchObject(JSON.parse(payload.staticData));
|
|
|
|
expect(nodes).toEqual(payload.nodes);
|
|
|
|
expect(active).toBe(false);
|
|
|
|
expect(createdAt).toBe(workflow.createdAt.toISOString());
|
|
|
|
expect(updatedAt).not.toBe(workflow.updatedAt.toISOString());
|
|
|
|
|
|
|
|
// check updated workflow in DB
|
2023-11-10 06:04:26 -08:00
|
|
|
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
2023-03-17 09:24:05 -07:00
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: memberPersonalProject.id,
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: response.body.id,
|
|
|
|
},
|
|
|
|
relations: ['workflow'],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(sharedWorkflow?.workflow.name).toBe(payload.name);
|
|
|
|
expect(sharedWorkflow?.workflow.updatedAt.getTime()).toBeGreaterThan(
|
|
|
|
workflow.updatedAt.getTime(),
|
|
|
|
);
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-10-23 07:30:36 -07:00
|
|
|
test('should create workflow history version when licensed', async () => {
|
2023-11-30 00:23:09 -08:00
|
|
|
license.enable('feat:workflowHistory');
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
2023-10-23 07:30:36 -07:00
|
|
|
const payload = {
|
|
|
|
name: 'name updated',
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Cron',
|
|
|
|
type: 'n8n-nodes-base.cron',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [400, 300],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: '{"id":1}',
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: false,
|
|
|
|
saveManualExecutions: false,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await authMemberAgent.put(`/workflows/${workflow.id}`).send(payload);
|
|
|
|
|
|
|
|
const { id } = response.body;
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
expect(id).toBe(workflow.id);
|
|
|
|
expect(
|
|
|
|
await Container.get(WorkflowHistoryRepository).count({ where: { workflowId: id } }),
|
|
|
|
).toBe(1);
|
|
|
|
const historyVersion = await Container.get(WorkflowHistoryRepository).findOne({
|
|
|
|
where: {
|
|
|
|
workflowId: id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(historyVersion).not.toBeNull();
|
|
|
|
expect(historyVersion!.connections).toEqual(payload.connections);
|
|
|
|
expect(historyVersion!.nodes).toEqual(payload.nodes);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not create workflow history when not licensed', async () => {
|
2023-11-30 00:23:09 -08:00
|
|
|
license.disable('feat:workflowHistory');
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
2023-10-23 07:30:36 -07:00
|
|
|
const payload = {
|
|
|
|
name: 'name updated',
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Cron',
|
|
|
|
type: 'n8n-nodes-base.cron',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [400, 300],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: '{"id":1}',
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: false,
|
|
|
|
saveManualExecutions: false,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await authMemberAgent.put(`/workflows/${workflow.id}`).send(payload);
|
|
|
|
|
|
|
|
const { id } = response.body;
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
expect(id).toBe(workflow.id);
|
|
|
|
expect(
|
|
|
|
await Container.get(WorkflowHistoryRepository).count({ where: { workflowId: id } }),
|
|
|
|
).toBe(0);
|
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('should update non-owned workflow if owner', async () => {
|
2023-11-08 07:29:39 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
2023-03-17 09:24:05 -07:00
|
|
|
|
|
|
|
const payload = {
|
|
|
|
name: 'name owner updated',
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
2023-03-15 06:24:09 -07:00
|
|
|
},
|
2023-03-17 09:24:05 -07:00
|
|
|
{
|
|
|
|
id: 'uuid-2',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Cron',
|
|
|
|
type: 'n8n-nodes-base.cron',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [400, 300],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: '{"id":1}',
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: false,
|
|
|
|
saveManualExecutions: false,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await authMemberAgent.put(`/workflows/${workflow.id}`).send(payload);
|
|
|
|
|
|
|
|
const { id, name, nodes, connections, staticData, active, settings, createdAt, updatedAt } =
|
|
|
|
response.body;
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
expect(id).toBe(workflow.id);
|
|
|
|
expect(name).toBe(payload.name);
|
|
|
|
expect(connections).toEqual(payload.connections);
|
|
|
|
expect(settings).toEqual(payload.settings);
|
|
|
|
expect(staticData).toMatchObject(JSON.parse(payload.staticData));
|
|
|
|
expect(nodes).toEqual(payload.nodes);
|
|
|
|
expect(active).toBe(false);
|
|
|
|
expect(createdAt).toBe(workflow.createdAt.toISOString());
|
|
|
|
expect(updatedAt).not.toBe(workflow.updatedAt.toISOString());
|
|
|
|
|
|
|
|
// check updated workflow in DB
|
2023-11-10 06:04:26 -08:00
|
|
|
const sharedOwnerWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
2023-03-17 09:24:05 -07:00
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: ownerPersonalProject.id,
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: response.body.id,
|
|
|
|
},
|
|
|
|
});
|
2023-03-15 06:24:09 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
expect(sharedOwnerWorkflow).toBeNull();
|
|
|
|
|
2023-11-10 06:04:26 -08:00
|
|
|
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
2023-03-17 09:24:05 -07:00
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: memberPersonalProject.id,
|
2023-03-17 09:24:05 -07:00
|
|
|
workflowId: response.body.id,
|
|
|
|
},
|
2024-01-24 04:38:57 -08:00
|
|
|
relations: ['workflow'],
|
2023-03-15 06:24:09 -07:00
|
|
|
});
|
2023-03-17 09:24:05 -07:00
|
|
|
|
|
|
|
expect(sharedWorkflow?.workflow.name).toBe(payload.name);
|
|
|
|
expect(sharedWorkflow?.workflow.updatedAt.getTime()).toBeGreaterThan(
|
|
|
|
workflow.updatedAt.getTime(),
|
|
|
|
);
|
2024-01-24 04:38:57 -08:00
|
|
|
expect(sharedWorkflow?.role).toEqual('workflow:owner');
|
2022-06-08 11:53:12 -07:00
|
|
|
});
|
|
|
|
});
|
2024-02-09 07:10:03 -08:00
|
|
|
|
|
|
|
describe('GET /workflows/:id/tags', () => {
|
|
|
|
test('should fail due to missing API Key', testWithAPIKey('get', '/workflows/2/tags', null));
|
|
|
|
|
|
|
|
test('should fail due to invalid API Key', testWithAPIKey('get', '/workflows/2/tags', 'abcXYZ'));
|
|
|
|
|
|
|
|
test('should fail if workflowTagsDisabled', async () => {
|
|
|
|
config.set('workflowTagsDisabled', true);
|
|
|
|
|
|
|
|
const response = await authOwnerAgent.get('/workflows/2/tags');
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(400);
|
|
|
|
expect(response.body.message).toBe('Workflow Tags Disabled');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fail due to non-existing workflow', async () => {
|
|
|
|
config.set('workflowTagsDisabled', false);
|
|
|
|
|
|
|
|
const response = await authOwnerAgent.get('/workflows/2/tags');
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(404);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should return all tags of owned workflow', async () => {
|
|
|
|
config.set('workflowTagsDisabled', false);
|
|
|
|
|
|
|
|
const tags = await Promise.all([await createTag({}), await createTag({})]);
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({ tags }, member);
|
|
|
|
|
|
|
|
const response = await authMemberAgent.get(`/workflows/${workflow.id}/tags`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.length).toBe(2);
|
|
|
|
|
|
|
|
for (const tag of response.body) {
|
|
|
|
const { id, name, createdAt, updatedAt } = tag;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
|
|
|
|
tags.forEach((tag: TagEntity) => {
|
|
|
|
expect(tags.some((savedTag) => savedTag.id === tag.id)).toBe(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should return empty array if workflow does not have tags', async () => {
|
|
|
|
config.set('workflowTagsDisabled', false);
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({}, member);
|
|
|
|
|
|
|
|
const response = await authMemberAgent.get(`/workflows/${workflow.id}/tags`);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('PUT /workflows/:id/tags', () => {
|
|
|
|
test('should fail due to missing API Key', testWithAPIKey('put', '/workflows/2/tags', null));
|
|
|
|
|
|
|
|
test('should fail due to invalid API Key', testWithAPIKey('put', '/workflows/2/tags', 'abcXYZ'));
|
|
|
|
|
|
|
|
test('should fail if workflowTagsDisabled', async () => {
|
|
|
|
config.set('workflowTagsDisabled', true);
|
|
|
|
|
|
|
|
const response = await authOwnerAgent.put('/workflows/2/tags').send([]);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(400);
|
|
|
|
expect(response.body.message).toBe('Workflow Tags Disabled');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fail due to non-existing workflow', async () => {
|
|
|
|
config.set('workflowTagsDisabled', false);
|
|
|
|
|
|
|
|
const response = await authOwnerAgent.put('/workflows/2/tags').send([]);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(404);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should add the tags, workflow have not got tags previously', async () => {
|
|
|
|
config.set('workflowTagsDisabled', false);
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({}, member);
|
|
|
|
const tags = await Promise.all([await createTag({}), await createTag({})]);
|
|
|
|
|
|
|
|
const payload = [
|
|
|
|
{
|
|
|
|
id: tags[0].id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: tags[1].id,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const response = await authMemberAgent.put(`/workflows/${workflow.id}/tags`).send(payload);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.length).toBe(2);
|
|
|
|
|
|
|
|
for (const tag of response.body) {
|
|
|
|
const { id, name, createdAt, updatedAt } = tag;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
|
|
|
|
tags.forEach((tag: TagEntity) => {
|
|
|
|
expect(tags.some((savedTag) => savedTag.id === tag.id)).toBe(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the association in DB
|
|
|
|
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: memberPersonalProject.id,
|
2024-02-09 07:10:03 -08:00
|
|
|
workflowId: workflow.id,
|
|
|
|
},
|
|
|
|
relations: ['workflow.tags'],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(sharedWorkflow?.workflow.tags).toBeDefined();
|
|
|
|
expect(sharedWorkflow?.workflow.tags?.length).toBe(2);
|
|
|
|
if (sharedWorkflow?.workflow.tags !== undefined) {
|
|
|
|
for (const tag of sharedWorkflow?.workflow.tags) {
|
|
|
|
const { id, name, createdAt, updatedAt } = tag;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
|
|
|
|
tags.forEach((tag: TagEntity) => {
|
|
|
|
expect(tags.some((savedTag) => savedTag.id === tag.id)).toBe(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should add the tags, workflow have some tags previously', async () => {
|
|
|
|
config.set('workflowTagsDisabled', false);
|
|
|
|
|
|
|
|
const tags = await Promise.all([await createTag({}), await createTag({}), await createTag({})]);
|
|
|
|
const oldTags = [tags[0], tags[1]];
|
|
|
|
const newTags = [tags[0], tags[2]];
|
|
|
|
const workflow = await createWorkflow({ tags: oldTags }, member);
|
|
|
|
|
|
|
|
// Check the association in DB
|
|
|
|
const oldSharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: memberPersonalProject.id,
|
2024-02-09 07:10:03 -08:00
|
|
|
workflowId: workflow.id,
|
|
|
|
},
|
|
|
|
relations: ['workflow.tags'],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(oldSharedWorkflow?.workflow.tags).toBeDefined();
|
|
|
|
expect(oldSharedWorkflow?.workflow.tags?.length).toBe(2);
|
|
|
|
if (oldSharedWorkflow?.workflow.tags !== undefined) {
|
|
|
|
for (const tag of oldSharedWorkflow?.workflow.tags) {
|
|
|
|
const { id, name, createdAt, updatedAt } = tag;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
|
|
|
|
oldTags.forEach((tag: TagEntity) => {
|
|
|
|
expect(oldTags.some((savedTag) => savedTag.id === tag.id)).toBe(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const payload = [
|
|
|
|
{
|
|
|
|
id: newTags[0].id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: newTags[1].id,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const response = await authMemberAgent.put(`/workflows/${workflow.id}/tags`).send(payload);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.length).toBe(2);
|
|
|
|
|
|
|
|
for (const tag of response.body) {
|
|
|
|
const { id, name, createdAt, updatedAt } = tag;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
|
|
|
|
newTags.forEach((tag: TagEntity) => {
|
|
|
|
expect(newTags.some((savedTag) => savedTag.id === tag.id)).toBe(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the association in DB
|
|
|
|
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: memberPersonalProject.id,
|
2024-02-09 07:10:03 -08:00
|
|
|
workflowId: workflow.id,
|
|
|
|
},
|
|
|
|
relations: ['workflow.tags'],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(sharedWorkflow?.workflow.tags).toBeDefined();
|
|
|
|
expect(sharedWorkflow?.workflow.tags?.length).toBe(2);
|
|
|
|
if (sharedWorkflow?.workflow.tags !== undefined) {
|
|
|
|
for (const tag of sharedWorkflow?.workflow.tags) {
|
|
|
|
const { id, name, createdAt, updatedAt } = tag;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
|
|
|
|
newTags.forEach((tag: TagEntity) => {
|
|
|
|
expect(newTags.some((savedTag) => savedTag.id === tag.id)).toBe(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fail to add the tags as one does not exist, workflow should maintain previous tags', async () => {
|
|
|
|
config.set('workflowTagsDisabled', false);
|
|
|
|
|
|
|
|
const tags = await Promise.all([await createTag({}), await createTag({})]);
|
|
|
|
const oldTags = [tags[0], tags[1]];
|
|
|
|
const workflow = await createWorkflow({ tags: oldTags }, member);
|
|
|
|
|
|
|
|
// Check the association in DB
|
|
|
|
const oldSharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: memberPersonalProject.id,
|
2024-02-09 07:10:03 -08:00
|
|
|
workflowId: workflow.id,
|
|
|
|
},
|
|
|
|
relations: ['workflow.tags'],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(oldSharedWorkflow?.workflow.tags).toBeDefined();
|
|
|
|
expect(oldSharedWorkflow?.workflow.tags?.length).toBe(2);
|
|
|
|
if (oldSharedWorkflow?.workflow.tags !== undefined) {
|
|
|
|
for (const tag of oldSharedWorkflow?.workflow.tags) {
|
|
|
|
const { id, name, createdAt, updatedAt } = tag;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
|
|
|
|
oldTags.forEach((tag: TagEntity) => {
|
|
|
|
expect(oldTags.some((savedTag) => savedTag.id === tag.id)).toBe(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const payload = [
|
|
|
|
{
|
|
|
|
id: oldTags[0].id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'TagDoesNotExist',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const response = await authMemberAgent.put(`/workflows/${workflow.id}/tags`).send(payload);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(404);
|
|
|
|
expect(response.body.message).toBe('Some tags not found');
|
|
|
|
|
|
|
|
// Check the association in DB
|
|
|
|
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
|
|
|
where: {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectId: memberPersonalProject.id,
|
2024-02-09 07:10:03 -08:00
|
|
|
workflowId: workflow.id,
|
|
|
|
},
|
|
|
|
relations: ['workflow.tags'],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(sharedWorkflow?.workflow.tags).toBeDefined();
|
|
|
|
expect(sharedWorkflow?.workflow.tags?.length).toBe(2);
|
|
|
|
if (sharedWorkflow?.workflow.tags !== undefined) {
|
|
|
|
for (const tag of sharedWorkflow?.workflow.tags) {
|
|
|
|
const { id, name, createdAt, updatedAt } = tag;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(name).toBeDefined();
|
|
|
|
expect(createdAt).toBeDefined();
|
|
|
|
expect(updatedAt).toBeDefined();
|
|
|
|
|
|
|
|
oldTags.forEach((tag: TagEntity) => {
|
|
|
|
expect(oldTags.some((savedTag) => savedTag.id === tag.id)).toBe(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2024-07-30 08:05:48 -07:00
|
|
|
|
|
|
|
describe('PUT /workflows/:id/transfer', () => {
|
|
|
|
test('should transfer workflow to project', async () => {
|
|
|
|
/**
|
|
|
|
* Arrange
|
|
|
|
*/
|
|
|
|
const firstProject = await createTeamProject('first-project', member);
|
2024-08-02 03:02:38 -07:00
|
|
|
const secondProject = await createTeamProject('second-project', member);
|
2024-07-30 08:05:48 -07:00
|
|
|
const workflow = await createWorkflow({}, firstProject);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Act
|
|
|
|
*/
|
|
|
|
const response = await authMemberAgent.put(`/workflows/${workflow.id}/transfer`).send({
|
|
|
|
destinationProjectId: secondProject.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert
|
|
|
|
*/
|
|
|
|
expect(response.statusCode).toBe(204);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('if no destination project, should reject', async () => {
|
|
|
|
/**
|
|
|
|
* Arrange
|
|
|
|
*/
|
|
|
|
const firstProject = await createTeamProject('first-project', member);
|
|
|
|
const workflow = await createWorkflow({}, firstProject);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Act
|
|
|
|
*/
|
|
|
|
const response = await authMemberAgent.put(`/workflows/${workflow.id}/transfer`).send({});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert
|
|
|
|
*/
|
|
|
|
expect(response.statusCode).toBe(400);
|
|
|
|
});
|
|
|
|
});
|