test: Update getFlows test for user model
This commit is contained in:
@@ -1181,14 +1181,24 @@ describe('User model', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getFlows', () => {
|
describe.only('getFlows', () => {
|
||||||
let currentUser, currentUserRole, folder, flowOne, flowTwo;
|
let currentUser,
|
||||||
|
currentUserRole,
|
||||||
|
anotherUser,
|
||||||
|
folder,
|
||||||
|
anotherUserFolder,
|
||||||
|
flowOne,
|
||||||
|
flowTwo,
|
||||||
|
flowThree;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
currentUser = await createUser();
|
currentUser = await createUser();
|
||||||
currentUserRole = await currentUser.$relatedQuery('role');
|
currentUserRole = await currentUser.$relatedQuery('role');
|
||||||
|
|
||||||
|
anotherUser = await createUser();
|
||||||
|
|
||||||
folder = await createFolder({ userId: currentUser.id });
|
folder = await createFolder({ userId: currentUser.id });
|
||||||
|
anotherUserFolder = await createFolder({ userId: anotherUser.id });
|
||||||
|
|
||||||
flowOne = await createFlow({
|
flowOne = await createFlow({
|
||||||
userId: currentUser.id,
|
userId: currentUser.id,
|
||||||
@@ -1201,11 +1211,16 @@ describe('User model', () => {
|
|||||||
name: 'Flow Two',
|
name: 'Flow Two',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
flowThree = await createFlow({
|
||||||
|
userId: anotherUser.id,
|
||||||
|
name: 'Flow Three',
|
||||||
|
});
|
||||||
|
|
||||||
await createPermission({
|
await createPermission({
|
||||||
action: 'read',
|
action: 'read',
|
||||||
subject: 'Flow',
|
subject: 'Flow',
|
||||||
roleId: currentUserRole.id,
|
roleId: currentUserRole.id,
|
||||||
conditions: ['isCreator'],
|
conditions: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
currentUser = await currentUser.$query().withGraphFetched({
|
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 () => {
|
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).toHaveLength(1);
|
||||||
expect(flows[0].id).toBe(flowTwo.id);
|
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 () => {
|
it('should return flows filtered by folderId and name', async () => {
|
||||||
const flows = await currentUser.getFlows({
|
const flows = await currentUser.getFlows(
|
||||||
folderId: folder.id,
|
{
|
||||||
name: 'Flow One',
|
folderId: folder.id,
|
||||||
});
|
name: 'Flow One',
|
||||||
|
},
|
||||||
|
[folder.id]
|
||||||
|
);
|
||||||
|
|
||||||
expect(flows).toHaveLength(1);
|
expect(flows).toHaveLength(1);
|
||||||
expect(flows[0].id).toBe(flowOne.id);
|
expect(flows[0].id).toBe(flowOne.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return all flows if no filters are provided', async () => {
|
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(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 () => {
|
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).toHaveLength(2);
|
||||||
expect(flows[0].id).toBe(flowTwo.id);
|
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])
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user