test: Update getFlows test for user model

This commit is contained in:
Faruk AYDIN
2025-03-12 16:12:59 +01:00
parent e13dfe220d
commit f616ec5c8d

View File

@@ -1181,14 +1181,24 @@ describe('User model', () => {
});
});
describe('getFlows', () => {
let currentUser, currentUserRole, folder, flowOne, flowTwo;
describe.only('getFlows', () => {
let currentUser,
currentUserRole,
anotherUser,
folder,
anotherUserFolder,
flowOne,
flowTwo,
flowThree;
beforeEach(async () => {
currentUser = await createUser();
currentUserRole = await currentUser.$relatedQuery('role');
anotherUser = await createUser();
folder = await createFolder({ userId: currentUser.id });
anotherUserFolder = await createFolder({ userId: anotherUser.id });
flowOne = await createFlow({
userId: currentUser.id,
@@ -1201,11 +1211,16 @@ describe('User model', () => {
name: 'Flow Two',
});
flowThree = await createFlow({
userId: anotherUser.id,
name: 'Flow Three',
});
await createPermission({
action: 'read',
subject: 'Flow',
roleId: currentUserRole.id,
conditions: ['isCreator'],
conditions: [],
});
currentUser = await currentUser.$query().withGraphFetched({
@@ -1214,44 +1229,66 @@ describe('User model', () => {
});
});
it('should return flows filtered by folderId', async () => {
const flows = await currentUser.getFlows({ folderId: folder.id });
expect(flows).toHaveLength(1);
expect(flows[0].id).toBe(flowOne.id);
});
it('should return flows filtered by name', async () => {
const flows = await currentUser.getFlows({ name: 'Flow Two' });
const flows = await currentUser.getFlows({ name: 'Flow Two' }, [
folder.id,
]);
expect(flows).toHaveLength(1);
expect(flows[0].id).toBe(flowTwo.id);
});
it('should return flows with specific folder ID', async () => {
const flows = await currentUser.getFlows({ folderId: folder.id }, [
folder.id,
]);
expect(flows.length).toBe(1);
expect(flows[0].id).toBe(flowOne.id);
});
it('should return flows filtered by folderId and name', async () => {
const flows = await currentUser.getFlows({
folderId: folder.id,
name: 'Flow One',
});
const flows = await currentUser.getFlows(
{
folderId: folder.id,
name: 'Flow One',
},
[folder.id]
);
expect(flows).toHaveLength(1);
expect(flows[0].id).toBe(flowOne.id);
});
it('should return all flows if no filters are provided', async () => {
const flows = await currentUser.getFlows({});
const flows = await currentUser.getFlows({}, [folder.id]);
expect(flows).toHaveLength(2);
expect(flows).toHaveLength(3);
expect(flows.map((flow) => flow.id)).toEqual(
expect.arrayContaining([flowOne.id, flowTwo.id])
expect.arrayContaining([flowOne.id, flowTwo.id, flowThree.id])
);
});
it('should return uncategorized flows if the folderId is null', async () => {
const flows = await currentUser.getFlows({ folderId: 'null' });
const flows = await currentUser.getFlows({ folderId: 'null' }, [
folder.id,
]);
expect(flows).toHaveLength(1);
expect(flows[0].id).toBe(flowTwo.id);
expect(flows).toHaveLength(2);
expect(flows.map((flow) => flow.id)).toEqual(
expect.arrayContaining([flowTwo.id, flowThree.id])
);
});
it('should return other users flow as uncategorized flows if the folderId is null', async () => {
const flows = await currentUser.getFlows({ folderId: 'null' }, [
folder.id,
]);
expect(flows).toHaveLength(2);
expect(flows.map((flow) => flow.id)).toEqual(
expect.arrayContaining([flowTwo.id, flowThree.id])
);
});
});