import { createOneRole } from 'test/integration/metadata/suites/role/utils/create-one-role.util'; import { deleteOneRole } from 'test/integration/metadata/suites/role/utils/delete-one-role.util'; import { findOneRoleByLabel } from 'test/integration/metadata/suites/role/utils/find-one-role-by-label.util'; describe('Role deletion should succeed', () => { it('should successfully delete a custom editable role', async () => { const { data: createData, errors: createErrors } = await createOneRole({ expectToFail: false, input: { label: 'Deletable Custom Role', description: 'A custom role that can be deleted', canUpdateAllSettings: false, canAccessAllTools: false, canReadAllObjectRecords: true, canUpdateAllObjectRecords: false, canSoftDeleteAllObjectRecords: false, canDestroyAllObjectRecords: false, }, }); expect(createErrors).toBeUndefined(); expect(createData.createOneRole.id).toBeDefined(); const customRoleId = createData.createOneRole.id; const { data, errors } = await deleteOneRole({ expectToFail: false, input: { idToDelete: customRoleId, }, }); expect(errors).toBeUndefined(); expect(data).toBeDefined(); expect(data.deleteOneRole).toBe(customRoleId); }); it('should delete a custom role and verify it can no longer be found', async () => { const testLabel = 'Role To Be Deleted And Verified'; const { data: createData } = await createOneRole({ expectToFail: false, input: { label: testLabel, canUpdateAllSettings: false, canAccessAllTools: false, canReadAllObjectRecords: true, canUpdateAllObjectRecords: false, canSoftDeleteAllObjectRecords: false, canDestroyAllObjectRecords: false, }, }); const roleId = createData.createOneRole.id; const roleBefore = await findOneRoleByLabel({ label: testLabel }); expect(roleBefore).toBeDefined(); expect(roleBefore.id).toBe(roleId); const { data, errors } = await deleteOneRole({ expectToFail: false, input: { idToDelete: roleId, }, }); expect(errors).toBeUndefined(); expect(data.deleteOneRole).toBe(roleId); await expect(findOneRoleByLabel({ label: testLabel })).rejects.toThrow( `Role with label "${testLabel}" not found`, ); }); });