mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor(core): Refactor cli command tests (no-changelog) (#9731)
This commit is contained in:
committed by
GitHub
parent
fb73ec3994
commit
2d02c73fbd
@@ -1,39 +1,24 @@
|
||||
import { Config } from '@oclif/core';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { ImportWorkflowsCommand } from '@/commands/import/workflow';
|
||||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
||||
|
||||
import { setupTestCommand } from '@test-integration/utils/testCommand';
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
import * as testDb from '../shared/testDb';
|
||||
import { getAllSharedWorkflows, getAllWorkflows } from '../shared/db/workflows';
|
||||
import { createMember, createOwner } from '../shared/db/users';
|
||||
import { getPersonalProject } from '../shared/db/projects';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
const oclifConfig = new Config({ root: __dirname });
|
||||
|
||||
async function importWorkflow(argv: string[]) {
|
||||
const importer = new ImportWorkflowsCommand(argv, oclifConfig);
|
||||
await importer.init();
|
||||
await importer.run();
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
mockInstance(InternalHooks);
|
||||
mockInstance(LoadNodesAndCredentials);
|
||||
await testDb.init();
|
||||
await oclifConfig.load();
|
||||
});
|
||||
mockInstance(InternalHooks);
|
||||
mockInstance(LoadNodesAndCredentials);
|
||||
const command = setupTestCommand(ImportWorkflowsCommand);
|
||||
|
||||
beforeEach(async () => {
|
||||
await testDb.truncate(['Workflow', 'SharedWorkflow', 'User']);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await testDb.terminate();
|
||||
});
|
||||
|
||||
test('import:workflow should import active workflow and deactivate it', async () => {
|
||||
//
|
||||
// ARRANGE
|
||||
@@ -44,10 +29,7 @@ test('import:workflow should import active workflow and deactivate it', async ()
|
||||
//
|
||||
// ACT
|
||||
//
|
||||
await importWorkflow([
|
||||
'--separate',
|
||||
'--input=./test/integration/commands/importWorkflows/separate',
|
||||
]);
|
||||
await command.run(['--separate', '--input=./test/integration/commands/importWorkflows/separate']);
|
||||
|
||||
//
|
||||
// ASSERT
|
||||
@@ -86,9 +68,7 @@ test('import:workflow should import active workflow from combined file and deact
|
||||
//
|
||||
// ACT
|
||||
//
|
||||
await importWorkflow([
|
||||
'--input=./test/integration/commands/importWorkflows/combined/combined.json',
|
||||
]);
|
||||
await command.run(['--input=./test/integration/commands/importWorkflows/combined/combined.json']);
|
||||
|
||||
//
|
||||
// ASSERT
|
||||
@@ -126,7 +106,7 @@ test('`import:workflow --userId ...` should fail if the workflow exists already
|
||||
const member = await createMember();
|
||||
|
||||
// Import workflow the first time, assigning it to a member.
|
||||
await importWorkflow([
|
||||
await command.run([
|
||||
'--input=./test/integration/commands/importWorkflows/combined-with-update/original.json',
|
||||
`--userId=${owner.id}`,
|
||||
]);
|
||||
@@ -153,7 +133,7 @@ test('`import:workflow --userId ...` should fail if the workflow exists already
|
||||
// Import the same workflow again, with another name but the same ID, and try
|
||||
// to assign it to the member.
|
||||
await expect(
|
||||
importWorkflow([
|
||||
command.run([
|
||||
'--input=./test/integration/commands/importWorkflows/combined-with-update/updated.json',
|
||||
`--userId=${member.id}`,
|
||||
]),
|
||||
@@ -190,7 +170,7 @@ test("only update the workflow, don't create or update the owner if `--userId` i
|
||||
const memberProject = await getPersonalProject(member);
|
||||
|
||||
// Import workflow the first time, assigning it to a member.
|
||||
await importWorkflow([
|
||||
await command.run([
|
||||
'--input=./test/integration/commands/importWorkflows/combined-with-update/original.json',
|
||||
`--userId=${member.id}`,
|
||||
]);
|
||||
@@ -215,7 +195,7 @@ test("only update the workflow, don't create or update the owner if `--userId` i
|
||||
// ACT
|
||||
//
|
||||
// Import the same workflow again, with another name but the same ID.
|
||||
await importWorkflow([
|
||||
await command.run([
|
||||
'--input=./test/integration/commands/importWorkflows/combined-with-update/updated.json',
|
||||
]);
|
||||
|
||||
@@ -249,7 +229,7 @@ test('`import:workflow --projectId ...` should fail if the credential already ex
|
||||
const memberProject = await getPersonalProject(member);
|
||||
|
||||
// Import workflow the first time, assigning it to a member.
|
||||
await importWorkflow([
|
||||
await command.run([
|
||||
'--input=./test/integration/commands/importWorkflows/combined-with-update/original.json',
|
||||
`--userId=${owner.id}`,
|
||||
]);
|
||||
@@ -276,7 +256,7 @@ test('`import:workflow --projectId ...` should fail if the credential already ex
|
||||
// Import the same workflow again, with another name but the same ID, and try
|
||||
// to assign it to the member.
|
||||
await expect(
|
||||
importWorkflow([
|
||||
command.run([
|
||||
'--input=./test/integration/commands/importWorkflows/combined-with-update/updated.json',
|
||||
`--projectId=${memberProject.id}`,
|
||||
]),
|
||||
@@ -306,7 +286,7 @@ test('`import:workflow --projectId ...` should fail if the credential already ex
|
||||
|
||||
test('`import:workflow --projectId ... --userId ...` fails explaining that only one of the options can be used at a time', async () => {
|
||||
await expect(
|
||||
importWorkflow([
|
||||
command.run([
|
||||
'--input=./test/integration/commands/importWorkflows/combined-with-update/updated.json',
|
||||
`--userId=${nanoid()}`,
|
||||
`--projectId=${nanoid()}`,
|
||||
|
||||
Reference in New Issue
Block a user