2023-03-30 06:33:30 -07:00
|
|
|
import * as Config from '@oclif/config';
|
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
import { InternalHooks } from '@/InternalHooks';
|
|
|
|
import { ImportWorkflowsCommand } from '@/commands/import/workflow';
|
|
|
|
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
2023-11-10 06:04:26 -08:00
|
|
|
|
|
|
|
import { mockInstance } from '../../shared/mocking';
|
2023-10-09 07:09:23 -07:00
|
|
|
import * as testDb from '../shared/testDb';
|
2023-11-08 07:29:39 -08:00
|
|
|
import { getAllWorkflows } from '../shared/db/workflows';
|
2023-09-20 06:21:42 -07:00
|
|
|
|
2023-03-30 06:33:30 -07:00
|
|
|
beforeAll(async () => {
|
|
|
|
mockInstance(InternalHooks);
|
2023-10-09 07:09:23 -07:00
|
|
|
mockInstance(LoadNodesAndCredentials);
|
2023-03-30 06:33:30 -07:00
|
|
|
await testDb.init();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
await testDb.truncate(['Workflow']);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await testDb.terminate();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('import:workflow should import active workflow and deactivate it', async () => {
|
|
|
|
const config: Config.IConfig = new Config.Config({ root: __dirname });
|
2023-11-08 07:29:39 -08:00
|
|
|
const before = await getAllWorkflows();
|
2023-03-30 06:33:30 -07:00
|
|
|
expect(before.length).toBe(0);
|
|
|
|
const importer = new ImportWorkflowsCommand(
|
|
|
|
['--separate', '--input=./test/integration/commands/importWorkflows/separate'],
|
|
|
|
config,
|
|
|
|
);
|
2023-05-02 01:37:19 -07:00
|
|
|
const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {
|
2023-03-30 06:33:30 -07:00
|
|
|
throw new Error('process.exit');
|
|
|
|
});
|
|
|
|
|
|
|
|
await importer.init();
|
|
|
|
try {
|
|
|
|
await importer.run();
|
|
|
|
} catch (error) {
|
|
|
|
expect(error.message).toBe('process.exit');
|
|
|
|
}
|
2023-11-08 07:29:39 -08:00
|
|
|
const after = await getAllWorkflows();
|
2023-03-30 06:33:30 -07:00
|
|
|
expect(after.length).toBe(2);
|
|
|
|
expect(after[0].name).toBe('active-workflow');
|
|
|
|
expect(after[0].active).toBe(false);
|
|
|
|
expect(after[1].name).toBe('inactive-workflow');
|
|
|
|
expect(after[1].active).toBe(false);
|
|
|
|
mockExit.mockRestore();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('import:workflow should import active workflow from combined file and deactivate it', async () => {
|
|
|
|
const config: Config.IConfig = new Config.Config({ root: __dirname });
|
2023-11-08 07:29:39 -08:00
|
|
|
const before = await getAllWorkflows();
|
2023-03-30 06:33:30 -07:00
|
|
|
expect(before.length).toBe(0);
|
|
|
|
const importer = new ImportWorkflowsCommand(
|
|
|
|
['--input=./test/integration/commands/importWorkflows/combined/combined.json'],
|
|
|
|
config,
|
|
|
|
);
|
2023-05-02 01:37:19 -07:00
|
|
|
const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {
|
2023-03-30 06:33:30 -07:00
|
|
|
throw new Error('process.exit');
|
|
|
|
});
|
|
|
|
|
|
|
|
await importer.init();
|
|
|
|
try {
|
|
|
|
await importer.run();
|
|
|
|
} catch (error) {
|
|
|
|
expect(error.message).toBe('process.exit');
|
|
|
|
}
|
2023-11-08 07:29:39 -08:00
|
|
|
const after = await getAllWorkflows();
|
2023-03-30 06:33:30 -07:00
|
|
|
expect(after.length).toBe(2);
|
|
|
|
expect(after[0].name).toBe('active-workflow');
|
|
|
|
expect(after[0].active).toBe(false);
|
|
|
|
expect(after[1].name).toBe('inactive-workflow');
|
|
|
|
expect(after[1].active).toBe(false);
|
|
|
|
mockExit.mockRestore();
|
|
|
|
});
|