feat: Complete export flow rest API endpoint

This commit is contained in:
Faruk AYDIN
2025-01-10 17:21:43 +03:00
parent 169c86a748
commit c180b98460
10 changed files with 362 additions and 19 deletions

View File

@@ -10,6 +10,7 @@ import { createFlow } from '../../test/factories/flow.js';
import { createStep } from '../../test/factories/step.js';
import { createExecution } from '../../test/factories/execution.js';
import { createExecutionStep } from '../../test/factories/execution-step.js';
import * as exportFlow from '../helpers/export-flow.js';
describe('Flow model', () => {
it('tableName should return correct name', () => {
@@ -506,6 +507,69 @@ describe('Flow model', () => {
});
});
describe('slugifyNameAsFilename', () => {
it('should generate a slug file name from flow name', async () => {
const flow = await createFlow({
name: 'My Flow Name',
});
const slug = flow.slugifyNameAsFilename();
expect(slug).toBe('my-flow-name.json');
});
});
describe('export', () => {
it('should call slugifyNameAsFilename method', async () => {
const flow = await createFlow({
name: 'My Flow Name',
});
const slugifyNameAsFilenameSpy = vi
.spyOn(flow, 'slugifyNameAsFilename')
.mockImplementation(() => 'my-flow-name.json');
await flow.export();
expect(slugifyNameAsFilenameSpy).toHaveBeenCalledOnce();
});
it('should call exportFlow method', async () => {
const flow = await createFlow();
const exportFlowSpy = vi
.spyOn(exportFlow, 'default')
.mockImplementation(() => {});
await flow.export();
expect(exportFlowSpy).toHaveBeenCalledOnce();
});
it('should return exportedFlowAsString and slug', async () => {
const flow = await createFlow();
const exportedFlowAsString = {
name: 'My Flow Name',
};
const slug = 'slug';
vi.spyOn(exportFlow, 'default').mockReturnValue(exportedFlowAsString);
vi.spyOn(flow, 'slugifyNameAsFilename').mockReturnValue(slug);
const expectedExportedFlowAsString = JSON.stringify(
exportedFlowAsString,
null,
2
);
expect(await flow.export()).toStrictEqual({
exportedFlowAsString: expectedExportedFlowAsString,
slug: 'slug',
});
});
});
describe('throwIfHavingLessThanTwoSteps', () => {
it('should throw validation error with less than two steps', async () => {
const flow = await createFlow();