refactor: Only return JSON for flow export

This commit is contained in:
Faruk AYDIN
2025-01-13 12:14:16 +01:00
parent 51291889cd
commit f15d1ac7b1
4 changed files with 11 additions and 86 deletions

View File

@@ -1,9 +1,11 @@
import { renderObject } from '../../../../helpers/renderer.js';
export default async (request, response) => {
const flow = await request.currentUser.authorizedFlows
.findById(request.params.flowId)
.throwIfNotFound();
const { exportedFlowAsString, slug } = await flow.export();
const exportedFlow = await flow.export();
response.status(201).attachment(slug).send(exportedFlowAsString);
return renderObject(response, exportedFlow, { status: 201 });
};

View File

@@ -67,20 +67,12 @@ describe('POST /api/v1/flows/:flowId/export', () => {
.set('Authorization', token)
.expect(201);
// Test headers for file attachment
expect(response.headers['content-disposition']).toContain(
'attachment; filename="name-your-flow.json"'
);
expect(response.headers['content-type']).toBe(
'application/json; charset=utf-8'
);
const expectedFileStructure = await exportFlowMock(currentUserFlow, [
const expectedPayload = await exportFlowMock(currentUserFlow, [
triggerStep,
actionStep,
]);
expect(response.body).toStrictEqual(expectedFileStructure);
expect(response.body).toStrictEqual(expectedPayload);
});
it('should export the flow data of another user', async () => {
@@ -132,19 +124,12 @@ describe('POST /api/v1/flows/:flowId/export', () => {
.set('Authorization', token)
.expect(201);
expect(response.headers['content-disposition']).toStrictEqual(
'attachment; filename="name-your-flow.json"'
);
expect(response.headers['content-type']).toStrictEqual(
'application/json; charset=utf-8'
);
const expectedFileStructure = await exportFlowMock(anotherUserFlow, [
const expectedPayload = await exportFlowMock(anotherUserFlow, [
triggerStep,
actionStep,
]);
expect(response.body).toStrictEqual(expectedFileStructure);
expect(response.body).toStrictEqual(expectedPayload);
});
it('should return not found response for not existing flow UUID', async () => {