import { describe, expect, it } from 'vitest'; import { createAdminClient, createRandomString } from './config'; describe('RoleService', () => { it('should register a new role', async () => { const client = await createAdminClient(); const code = `ROLE_TEST_${createRandomString(4).toUpperCase()}`; const result = await client.roles.register({ code, name: `Test Role (${code})`, permissions: ['read', 'write'] }); expect(result).toBeDefined(); expect(result.responseCode).toBe('ok'); expect(result.role).toBeDefined(); expect(result.role.code).toBe(code); }); it('should get role by id', async () => { const client = await createAdminClient(); const code = `ROLE_TEST_${createRandomString(4).toUpperCase()}`; const registerResult = await client.roles.register({ code, name: `Test Role (${code})`, permissions: ['read'] }); const roleId = registerResult.role.id; const getResult = await client.roles.getById(roleId); expect(getResult).toBeDefined(); expect(getResult.responseCode).toBe('ok'); expect(getResult.role.id).toBe(roleId); expect(getResult.role.code).toBe(code); }); it('should get role by code', async () => { const client = await createAdminClient(); const code = `ROLE_TEST_${createRandomString(4).toUpperCase()}`; await client.roles.register({ code, name: `Test Role (${code})`, permissions: ['read'] }); const getResult = await client.roles.getByCode(code); expect(getResult).toBeDefined(); expect(getResult.responseCode).toBe('ok'); expect(getResult.role.code).toBe(code); }); it('should update a role', async () => { const client = await createAdminClient(); const code = `ROLE_TEST_${createRandomString(4).toUpperCase()}`; const registerResult = await client.roles.register({ code, name: 'Original Name', permissions: ['read'] }); const roleId = registerResult.role.id; const updateResult = await client.roles.update({ id: roleId, name: 'Updated Name', permissions: ['read', 'write', 'delete'] }); expect(updateResult).toBeDefined(); expect(updateResult.responseCode).toBe('ok'); expect(updateResult.role.name).toBe('Updated Name'); }); it('should delete a role', async () => { const client = await createAdminClient(); const code = `ROLE_TEST_${createRandomString(4).toUpperCase()}`; const registerResult = await client.roles.register({ code, name: `Test Role (${code})`, permissions: ['read'] }); const roleId = registerResult.role.id; const deleteResult = await client.roles.delete(roleId); expect(deleteResult).toBeDefined(); expect(deleteResult.responseCode).toBe('ok'); }); });