add unit test

Signed-off-by: Pierre Noël <petersg83@gmail.com>
This commit is contained in:
Pierre Noël 2020-05-18 18:33:56 +02:00 committed by Alexandre Bodin
parent dd3bc76948
commit 89f408c67e

View File

@ -76,5 +76,24 @@ describe('Role', () => {
expect(dbFind).toHaveBeenCalledWith({ _limit: -1 }); expect(dbFind).toHaveBeenCalledWith({ _limit: -1 });
expect(foundRoles).toStrictEqual(roles); expect(foundRoles).toStrictEqual(roles);
}); });
test('Fetches all roles', async () => {
const roles = [
{
id: 1,
name: 'super_admin',
description: "Have all permissions. Can't be delete",
},
];
const dbFind = jest.fn(() => Promise.resolve(roles));
global.strapi = {
query: () => ({ find: dbFind }),
};
const fetchedRole = await roleService.fetchAll();
expect(dbFind).toHaveBeenCalled();
expect(fetchedRole).toStrictEqual(roles);
});
}); });
}); });