Merge pull request #2457 from automatisch/aut-1554

feat(api): add delete flow endpoint
This commit is contained in:
Ali BARIN
2025-04-25 10:38:17 +02:00
committed by GitHub
3 changed files with 55 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
import Flow from '../../../../models/flow.js';
export default async (request, response) => {
const flow = await Flow.query()
.findById(request.params.flowId)
.throwIfNotFound();
await flow.delete();
response.status(204).end();
};

View File

@@ -0,0 +1,42 @@
import Crypto from 'node:crypto';
import request from 'supertest';
import { beforeEach, describe, it, vi } from 'vitest';
import { createApiToken } from '../../../../../test/factories/api-token.js';
import { createFlow } from '../../../../../test/factories/flow.js';
import app from '../../../../app.js';
import * as license from '../../../../helpers/license.ee.js';
describe('DELETE /api/v1/flows/:flowId', () => {
let token;
beforeEach(async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
token = (await createApiToken()).token;
});
it('should remove the flow and return no content', async () => {
const flow = await createFlow();
await request(app)
.delete(`/api/v1/flows/${flow.id}`)
.set('x-api-token', token)
.expect(204);
});
it('should return not found response for not existing flow UUID', async () => {
const notExistingFlowUUID = Crypto.randomUUID();
await request(app)
.delete(`/api/v1/flows/${notExistingFlowUUID}`)
.set('x-api-token', token)
.expect(404);
});
it('should return bad request response for invalid UUID', async () => {
await request(app)
.delete('/api/v1/flows/invalidFlowUUID')
.set('x-api-token', token)
.expect(400);
});
});

View File

@@ -1,8 +1,10 @@
import { Router } from 'express';
import getFlowAction from '../../../controllers/api/v1/flows/get-flow.ee.js';
import deleteFlowAction from '../../../controllers/api/v1/flows/delete-flow.ee.js';
const router = Router();
router.get('/:flowId', getFlowAction);
router.delete('/:flowId', deleteFlowAction);
export default router;