mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor(core): Reduce boilterplate code in between tests 🧹, and fix the tests in node.js 20 (no-changelog) (#6654)
refactor(core): Reduce boilterplate code in between tests also cleaned up some imports, and fixed the tests in node.js 20
This commit is contained in:
committed by
GitHub
parent
3e07ffa73e
commit
b895ba438a
@@ -1,57 +1,41 @@
|
||||
import type { SuperAgentTest } from 'supertest';
|
||||
import type { IPinData } from 'n8n-workflow';
|
||||
|
||||
import type { User } from '@db/entities/User';
|
||||
import * as UserManagementHelpers from '@/UserManagement/UserManagementHelper';
|
||||
|
||||
import * as utils from './shared/utils';
|
||||
import * as utils from './shared/utils/';
|
||||
import * as testDb from './shared/testDb';
|
||||
import { makeWorkflow, MOCK_PINDATA } from './shared/utils';
|
||||
import * as Db from '@/Db';
|
||||
import { makeWorkflow, MOCK_PINDATA } from './shared/utils/';
|
||||
|
||||
let ownerShell: User;
|
||||
let authOwnerAgent: SuperAgentTest;
|
||||
|
||||
beforeAll(async () => {
|
||||
const app = await utils.initTestServer({ endpointGroups: ['workflows'] });
|
||||
const globalOwnerRole = await testDb.getGlobalOwnerRole();
|
||||
ownerShell = await testDb.createUserShell(globalOwnerRole);
|
||||
authOwnerAgent = utils.createAgent(app, { auth: true, user: ownerShell });
|
||||
jest.spyOn(UserManagementHelpers, 'isSharingEnabled').mockReturnValue(false);
|
||||
const testServer = utils.setupTestServer({ endpointGroups: ['workflows'] });
|
||||
|
||||
// mock whether sharing is enabled or not
|
||||
jest.spyOn(UserManagementHelpers, 'isSharingEnabled').mockReturnValue(false);
|
||||
beforeAll(async () => {
|
||||
const globalOwnerRole = await testDb.getGlobalOwnerRole();
|
||||
const ownerShell = await testDb.createUserShell(globalOwnerRole);
|
||||
authOwnerAgent = testServer.authAgentFor(ownerShell);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await testDb.truncate(['Workflow', 'SharedWorkflow']);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await testDb.terminate();
|
||||
});
|
||||
|
||||
describe('POST /workflows', () => {
|
||||
test('should store pin data for node in workflow', async () => {
|
||||
const workflow = makeWorkflow({ withPinData: true });
|
||||
|
||||
const testWithPinData = async (withPinData: boolean) => {
|
||||
const workflow = makeWorkflow({ withPinData });
|
||||
const response = await authOwnerAgent.post('/workflows').send(workflow);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
return (response.body.data as { pinData: IPinData }).pinData;
|
||||
};
|
||||
|
||||
const { pinData } = response.body.data as { pinData: IPinData };
|
||||
|
||||
test('should store pin data for node in workflow', async () => {
|
||||
const pinData = await testWithPinData(true);
|
||||
expect(pinData).toMatchObject(MOCK_PINDATA);
|
||||
});
|
||||
|
||||
test('should set pin data to null if no pin data', async () => {
|
||||
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 };
|
||||
|
||||
const pinData = await testWithPinData(false);
|
||||
expect(pinData).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -59,19 +43,13 @@ describe('POST /workflows', () => {
|
||||
describe('GET /workflows/:id', () => {
|
||||
test('should return pin data', async () => {
|
||||
const workflow = makeWorkflow({ withPinData: true });
|
||||
|
||||
const workflowCreationResponse = await authOwnerAgent.post('/workflows').send(workflow);
|
||||
|
||||
const { id } = workflowCreationResponse.body.data as { id: string };
|
||||
|
||||
const sw = await Db.collections.SharedWorkflow.find();
|
||||
|
||||
const workflowRetrievalResponse = await authOwnerAgent.get(`/workflows/${id}`);
|
||||
|
||||
expect(workflowRetrievalResponse.statusCode).toBe(200);
|
||||
|
||||
const { pinData } = workflowRetrievalResponse.body.data as { pinData: IPinData };
|
||||
|
||||
expect(pinData).toMatchObject(MOCK_PINDATA);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user