mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 00:24:07 -08:00
679a443a0c
* update type * add id to new nodes * update paste/import behavior * update duplicate/copy * update duplicate workflow * update import functions + templates * add instance id on copy * on download add instance id * simplify for testing * update telemetry events * add ids to nodegraph * not if same instance * update spacing * fix tests * update tests * add uuid * fix tests update tests add uuid fix ts issue * fix telemetry event * update workflow import * update public api * add sqlit migration * on workflow update * add psql migration * add mysql migration * revert to title * fix telemetry bug * remove console log * remove migration logs * fix copy/paste bug * replace node index with node id * remove console log * address PR feedback * address comment * fix type issue * fix select * update schema * fix ts issue * update tel helpers * fix eslint issues
109 lines
3.1 KiB
TypeScript
109 lines
3.1 KiB
TypeScript
import express from 'express';
|
|
|
|
import * as utils from './shared/utils';
|
|
import * as testDb from './shared/testDb';
|
|
import { WorkflowEntity } from '../../src/databases/entities/WorkflowEntity';
|
|
import type { Role } from '../../src/databases/entities/Role';
|
|
import { IPinData } from 'n8n-workflow';
|
|
|
|
jest.mock('../../src/telemetry');
|
|
|
|
let app: express.Application;
|
|
let testDbName = '';
|
|
let globalOwnerRole: Role;
|
|
|
|
beforeAll(async () => {
|
|
app = await utils.initTestServer({
|
|
endpointGroups: ['workflows'],
|
|
applyAuth: true,
|
|
});
|
|
const initResult = await testDb.init();
|
|
testDbName = initResult.testDbName;
|
|
|
|
globalOwnerRole = await testDb.getGlobalOwnerRole();
|
|
|
|
utils.initTestLogger();
|
|
utils.initTestTelemetry();
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
await testDb.truncate(['User', 'Workflow', 'SharedWorkflow'], testDbName);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await testDb.terminate(testDbName);
|
|
});
|
|
|
|
test('POST /workflows should store pin data for node in workflow', async () => {
|
|
const ownerShell = await testDb.createUserShell(globalOwnerRole);
|
|
const authOwnerAgent = utils.createAgent(app, { auth: true, user: ownerShell });
|
|
|
|
const workflow = makeWorkflow({ withPinData: true });
|
|
|
|
const response = await authOwnerAgent.post('/workflows').send(workflow);
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
const { pinData } = response.body.data as { pinData: IPinData };
|
|
|
|
expect(pinData).toMatchObject({ Spotify: [{ myKey: 'myValue' }] });
|
|
});
|
|
|
|
test('POST /workflows should set pin data to null if no pin data', async () => {
|
|
const ownerShell = await testDb.createUserShell(globalOwnerRole);
|
|
const authOwnerAgent = utils.createAgent(app, { auth: true, user: ownerShell });
|
|
|
|
const workflow = makeWorkflow({ withPinData: false });
|
|
|
|
const response = await authOwnerAgent.post('/workflows').send(workflow);
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
const { pinData } = response.body.data as { pinData: IPinData };
|
|
|
|
expect(pinData).toBeNull();
|
|
});
|
|
|
|
test('GET /workflows/:id should return pin data', async () => {
|
|
const ownerShell = await testDb.createUserShell(globalOwnerRole);
|
|
const authOwnerAgent = utils.createAgent(app, { auth: true, user: ownerShell });
|
|
|
|
const workflow = makeWorkflow({ withPinData: true });
|
|
|
|
const workflowCreationResponse = await authOwnerAgent.post('/workflows').send(workflow);
|
|
|
|
const { id } = workflowCreationResponse.body.data as { id: string };
|
|
|
|
const workflowRetrievalResponse = await authOwnerAgent.get(`/workflows/${id}`);
|
|
|
|
expect(workflowRetrievalResponse.statusCode).toBe(200);
|
|
|
|
const { pinData } = workflowRetrievalResponse.body.data as { pinData: IPinData };
|
|
|
|
expect(pinData).toMatchObject({ Spotify: [{ myKey: 'myValue' }] });
|
|
});
|
|
|
|
function makeWorkflow({ withPinData }: { withPinData: boolean }) {
|
|
const workflow = new WorkflowEntity();
|
|
|
|
workflow.name = 'My Workflow';
|
|
workflow.active = false;
|
|
workflow.connections = {};
|
|
workflow.nodes = [
|
|
{
|
|
id: 'uuid-1234',
|
|
name: 'Spotify',
|
|
type: 'n8n-nodes-base.spotify',
|
|
parameters: { resource: 'track', operation: 'get', id: '123' },
|
|
typeVersion: 1,
|
|
position: [740, 240],
|
|
},
|
|
];
|
|
|
|
if (withPinData) {
|
|
workflow.pinData = { Spotify: [{ myKey: 'myValue' }] };
|
|
}
|
|
|
|
return workflow;
|
|
}
|