File size: 1,378 Bytes
3206347 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import { describe, it, expect, beforeEach } from 'vitest';
import { createRole } from '../../test/factories/role';
import roleSerializer from './role';
import permissionSerializer from './permission';
import { createPermission } from '../../test/factories/permission';
describe('roleSerializer', () => {
let role, permissionOne, permissionTwo;
beforeEach(async () => {
role = await createRole();
permissionOne = await createPermission({
roleId: role.id,
action: 'read',
subject: 'User',
});
permissionTwo = await createPermission({
roleId: role.id,
action: 'read',
subject: 'Role',
});
});
it('should return role data', async () => {
const expectedPayload = {
id: role.id,
name: role.name,
key: role.key,
description: role.description,
createdAt: role.createdAt.getTime(),
updatedAt: role.updatedAt.getTime(),
isAdmin: role.isAdmin,
};
expect(roleSerializer(role)).toEqual(expectedPayload);
});
it('should return role data with the permissions', async () => {
role.permissions = [permissionOne, permissionTwo];
const expectedPayload = {
permissions: [
permissionSerializer(permissionOne),
permissionSerializer(permissionTwo),
],
};
expect(roleSerializer(role)).toMatchObject(expectedPayload);
});
});
|