test(api): cover user filter in get flows endpoint

This commit is contained in:
Ali BARIN
2025-04-27 12:30:41 +00:00
parent 6d3a97c4e4
commit c851125ee4
2 changed files with 50 additions and 62 deletions

View File

@@ -15,6 +15,6 @@ const flowParams = (request) => {
folderId: request.query.folderId, folderId: request.query.folderId,
name: request.query.name, name: request.query.name,
status: request.query.status, status: request.query.status,
onlyOwnedFlows: request.query.onlyOwnedFlows, userId: request.query.userId,
}; };
}; };

View File

@@ -10,12 +10,12 @@ import app from '../../../../app.js';
import * as license from '../../../../helpers/license.ee.js'; import * as license from '../../../../helpers/license.ee.js';
describe('GET /api/v1/flows', () => { describe('GET /api/v1/flows', () => {
let currentUser, token; let user, token;
beforeEach(async () => { beforeEach(async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true); vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
currentUser = await createUser(); user = await createUser();
token = (await createApiToken()).token; token = (await createApiToken()).token;
}); });
@@ -61,65 +61,53 @@ describe('GET /api/v1/flows', () => {
}); });
it('should return all flows data of the given user', async () => { it('should return all flows data of the given user', async () => {
const folderOne = await createFolder({ userId: currentUser.id }); const folderOne = await createFolder({ userId: user.id });
const currentUserFlowOne = await createFlow({ const userFlowOne = await createFlow({
userId: currentUser.id, userId: user.id,
folderId: folderOne.id, folderId: folderOne.id,
}); });
const triggerStepFlowOne = await createStep({ const triggerStepFlowOne = await createStep({
flowId: currentUserFlowOne.id, flowId: userFlowOne.id,
type: 'trigger', type: 'trigger',
}); });
const actionStepFlowOne = await createStep({ const actionStepFlowOne = await createStep({
flowId: currentUserFlowOne.id, flowId: userFlowOne.id,
type: 'action', type: 'action',
}); });
const folderTwo = await createFolder({ userId: currentUser.id }); const folderTwo = await createFolder({ userId: user.id });
const currentUserFlowTwo = await createFlow({ const userFlowTwo = await createFlow({
userId: currentUser.id, userId: user.id,
folderId: folderTwo.id, folderId: folderTwo.id,
}); });
const triggerStepFlowTwo = await createStep({ const triggerStepFlowTwo = await createStep({
flowId: currentUserFlowTwo.id, flowId: userFlowTwo.id,
type: 'trigger', type: 'trigger',
}); });
const actionStepFlowTwo = await createStep({ const actionStepFlowTwo = await createStep({
flowId: currentUserFlowTwo.id, flowId: userFlowTwo.id,
type: 'action', type: 'action',
}); });
const currentUserFlowThree = await createFlow({ userId: currentUser.id }); await createFlow();
const triggerStepFlowThree = await createStep({
flowId: currentUserFlowThree.id,
type: 'trigger',
});
const actionStepFlowThree = await createStep({
flowId: currentUserFlowThree.id,
type: 'action',
});
const response = await request(app) const response = await request(app)
.get('/api/v1/flows?userId=' + currentUser.id) .get(`/api/v1/flows?userId=${user.id}`)
.set('x-api-token', token) .set('x-api-token', token)
.expect(200); .expect(200);
const expectedPayload = await getFlowsMock( const expectedPayload = await getFlowsMock(
[currentUserFlowThree, currentUserFlowTwo, currentUserFlowOne], [userFlowTwo, userFlowOne],
[ [
triggerStepFlowOne, triggerStepFlowOne,
actionStepFlowOne, actionStepFlowOne,
triggerStepFlowTwo, triggerStepFlowTwo,
actionStepFlowTwo, actionStepFlowTwo,
triggerStepFlowThree,
actionStepFlowThree,
] ]
); );
@@ -129,59 +117,59 @@ describe('GET /api/v1/flows', () => {
it('should return all uncategorized flows data', async () => { it('should return all uncategorized flows data', async () => {
const folderOne = await createFolder(); const folderOne = await createFolder();
const currentUserFlowOne = await createFlow({ const userFlowOne = await createFlow({
userId: currentUser.id, userId: user.id,
folderId: folderOne.id, folderId: folderOne.id,
}); });
await createStep({ await createStep({
flowId: currentUserFlowOne.id, flowId: userFlowOne.id,
type: 'trigger', type: 'trigger',
}); });
await createStep({ await createStep({
flowId: currentUserFlowOne.id, flowId: userFlowOne.id,
type: 'action', type: 'action',
}); });
const folderTwo = await createFolder(); const folderTwo = await createFolder();
const currentUserFlowTwo = await createFlow({ const userFlowTwo = await createFlow({
userId: currentUser.id, userId: user.id,
folderId: folderTwo.id, folderId: folderTwo.id,
}); });
await createStep({ await createStep({
flowId: currentUserFlowTwo.id, flowId: userFlowTwo.id,
type: 'trigger', type: 'trigger',
}); });
await createStep({ await createStep({
flowId: currentUserFlowTwo.id, flowId: userFlowTwo.id,
type: 'action', type: 'action',
}); });
const currentUserFlowThree = await createFlow(); const userFlowThree = await createFlow();
const triggerStepFlowThree = await createStep({ const triggerStepFlowThree = await createStep({
flowId: currentUserFlowThree.id, flowId: userFlowThree.id,
type: 'trigger', type: 'trigger',
}); });
const actionStepFlowThree = await createStep({ const actionStepFlowThree = await createStep({
flowId: currentUserFlowThree.id, flowId: userFlowThree.id,
type: 'action', type: 'action',
}); });
const currentUserFlowFour = await createFlow(); const userFlowFour = await createFlow();
const triggerStepFlowFour = await createStep({ const triggerStepFlowFour = await createStep({
flowId: currentUserFlowFour.id, flowId: userFlowFour.id,
type: 'trigger', type: 'trigger',
}); });
const actionStepFlowFour = await createStep({ const actionStepFlowFour = await createStep({
flowId: currentUserFlowFour.id, flowId: userFlowFour.id,
type: 'action', type: 'action',
}); });
@@ -191,7 +179,7 @@ describe('GET /api/v1/flows', () => {
.expect(200); .expect(200);
const expectedPayload = await getFlowsMock( const expectedPayload = await getFlowsMock(
[currentUserFlowFour, currentUserFlowThree], [userFlowFour, userFlowThree],
[ [
triggerStepFlowThree, triggerStepFlowThree,
actionStepFlowThree, actionStepFlowThree,
@@ -204,73 +192,73 @@ describe('GET /api/v1/flows', () => {
}); });
it('should return all flows data of the given user for specified folder', async () => { it('should return all flows data of the given user for specified folder', async () => {
const folderOne = await createFolder({ userId: currentUser.id }); const folderOne = await createFolder({ userId: user.id });
const currentUserFlowOne = await createFlow({ const userFlowOne = await createFlow({
userId: currentUser.id, userId: user.id,
folderId: folderOne.id, folderId: folderOne.id,
}); });
const triggerStepFlowOne = await createStep({ const triggerStepFlowOne = await createStep({
flowId: currentUserFlowOne.id, flowId: userFlowOne.id,
type: 'trigger', type: 'trigger',
}); });
const actionStepFlowOne = await createStep({ const actionStepFlowOne = await createStep({
flowId: currentUserFlowOne.id, flowId: userFlowOne.id,
type: 'action', type: 'action',
}); });
const currentUserFlowTwo = await createFlow({ const userFlowTwo = await createFlow({
userId: currentUser.id, userId: user.id,
folderId: folderOne.id, folderId: folderOne.id,
}); });
const triggerStepFlowTwo = await createStep({ const triggerStepFlowTwo = await createStep({
flowId: currentUserFlowTwo.id, flowId: userFlowTwo.id,
type: 'trigger', type: 'trigger',
}); });
const actionStepFlowTwo = await createStep({ const actionStepFlowTwo = await createStep({
flowId: currentUserFlowTwo.id, flowId: userFlowTwo.id,
type: 'action', type: 'action',
}); });
const folderTwo = await createFolder({ userId: currentUser.id }); const folderTwo = await createFolder({ userId: user.id });
const currentUserFlowThree = await createFlow({ const userFlowThree = await createFlow({
userId: currentUser.id, userId: user.id,
folderId: folderTwo.id, folderId: folderTwo.id,
}); });
await createStep({ await createStep({
flowId: currentUserFlowThree.id, flowId: userFlowThree.id,
type: 'trigger', type: 'trigger',
}); });
await createStep({ await createStep({
flowId: currentUserFlowThree.id, flowId: userFlowThree.id,
type: 'action', type: 'action',
}); });
const currentUserFlowFour = await createFlow({ userId: currentUser.id }); const userFlowFour = await createFlow({ userId: user.id });
await createStep({ await createStep({
flowId: currentUserFlowFour.id, flowId: userFlowFour.id,
type: 'trigger', type: 'trigger',
}); });
await createStep({ await createStep({
flowId: currentUserFlowFour.id, flowId: userFlowFour.id,
type: 'action', type: 'action',
}); });
const response = await request(app) const response = await request(app)
.get(`/api/v1/flows?userId=${currentUser.id}&folderId=${folderOne.id}`) .get(`/api/v1/flows?userId=${user.id}&folderId=${folderOne.id}`)
.set('x-api-token', token) .set('x-api-token', token)
.expect(200); .expect(200);
const expectedPayload = await getFlowsMock( const expectedPayload = await getFlowsMock(
[currentUserFlowTwo, currentUserFlowOne], [userFlowTwo, userFlowOne],
[ [
triggerStepFlowOne, triggerStepFlowOne,
actionStepFlowOne, actionStepFlowOne,