Skip to content

Commit

Permalink
update rbac tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teofilomonteiro committed Sep 27, 2024
1 parent 7818fc2 commit 441a84b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/tests/e2e/rbac.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ test('Permission check e2e test', async (t) => {

// verify list output
const resources = await permit.api.resources.list();
t.true(Array.isArray(resources));
t.is(resources.length, 1);
t.is(resources[0].id, document.id);
t.is(resources[0].key, document.key);
t.is(resources[0].name, document.name);
t.is(resources[0].description, document.description);
t.is(resources[0].urn, document.urn);

const resourcesWithTotalCount = await permit.api.resources.list({ includeTotalCount: true });
t.not(resourcesWithTotalCount, null);
t.not(resourcesWithTotalCount.data, null);
t.is(resourcesWithTotalCount.data.length, 1);
t.is(resourcesWithTotalCount.total_count, 1);
t.is(resourcesWithTotalCount.page_count, 1);

// create admin role
const admin = await permit.api.roles.create({
key: 'admin',
Expand Down Expand Up @@ -84,6 +92,10 @@ test('Permission check e2e test', async (t) => {
t.not(viewer.permissions, undefined);
t.is(viewer.permissions?.length, 0);

const roles = await permit.api.roles.list();
t.true(Array.isArray(roles));
t.is(roles.length, 2);

// assign permissions to roles
const assignedViewer = await permit.api.roles.assignPermissions('viewer', ['document:read']);

Expand Down Expand Up @@ -234,7 +246,12 @@ test('Permission check e2e test', async (t) => {
await permit.api.roles.delete('viewer');
await permit.api.resources.delete('document');
t.is((await permit.api.resources.list()).length, 0);
t.is((await permit.api.roles.list()).length, 0);

const roles = await permit.api.roles.list();

t.true(Array.isArray(roles));
t.is(roles.length, 0);

t.is((await permit.api.tenants.list()).length, 1); // the default tenant
t.is((await permit.api.users.list()).data.length, 0);
} catch (error) {
Expand Down

0 comments on commit 441a84b

Please sign in to comment.