Merge branch 'main' into auth-create-list

This commit is contained in:
Susmitha Girumala authored and GitHub committed 2021-09-02 11:38:49 -04:00
commit eac0ee6b53
7 files changed
+162 -27

No files matched your search

@@ -11,7 +11,7 @@ import {
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | roles', function (hooks) {
module('Acceptance | roles | create', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
@@ -22,38 +22,44 @@ module('Acceptance | roles', function (hooks) {
project: null,
},
role: null,
orgScope: null,
};
const urls = {
orgScope: null,
roles: null,
role: null,
newRole: null,
orgScope: null,
};
hooks.beforeEach(function () {
authenticateSession({});
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.orgScope = this.server.create(
'scope',
{
type: 'org',
scope: { id: 'global', type: 'global' },
},
'withChildren'
);
// The project scope is not yet used for role tests (though it will be
// in the future). This is created simply to test the grant scope loading
// mechanism.
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: instances.scopes.org.type },
scope: { id: instances.orgScope.id, type: instances.orgScope.type },
});
instances.role = this.server.create(
'role',
{
scope: instances.scopes.org,
scope: instances.orgScope,
},
'withPrincipals'
);
urls.roles = `/scopes/${instances.scopes.org.id}/roles`;
urls.roles = `/scopes/${instances.orgScope.id}/roles`;
urls.role = `${urls.roles}/${instances.role.id}`;
urls.newRole = `${urls.roles}/new`;
urls.orgScope = `/scopes/${instances.orgScope.id}`;
});
test('can create new role', async function (assert) {
@@ -65,6 +71,25 @@ module('Acceptance | roles', function (hooks) {
assert.equal(this.server.db.roles.length, rolesCount + 1);
});
test('Users can navigate to new roles route with proper authorization', async function (assert) {
assert.expect(2);
await visit(urls.orgScope);
assert.ok(
instances.orgScope.authorized_collection_actions.roles.includes('create')
);
assert.ok(find(`[href="${urls.roles}"]`));
});
test('Users cannot navigate to new roles route without proper authorization', async function (assert) {
assert.expect(2);
instances.orgScope.authorized_collection_actions.roles = [];
await visit(urls.orgScope);
assert.notOk(
instances.orgScope.authorized_collection_actions.roles.includes('create')
);
assert.notOk(find(`[href="${urls.roles}"]`));
});
test('can cancel new role creation', async function (assert) {
assert.expect(2);
const rolesCount = this.server.db.roles.length;
@@ -0,0 +1,75 @@
import { module, test } from 'qunit';
import { visit, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import {
authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | roles | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
},
orgScope: null,
};
const urls = {
scopes: {
org: null,
},
roles: null,
orgScope: null,
};
hooks.beforeEach(function () {
instances.orgScope = this.server.create(
'scope',
{
type: 'org',
scope: { id: 'global', type: 'global' },
},
'withChildren'
);
instances.role = this.server.create('role', {
scope: instances.orgScope,
});
urls.orgScope = `/scopes/${instances.orgScope.id}`;
urls.roles = `/scopes/${instances.orgScope.id}/roles`;
authenticateSession({});
});
test('Users can navigate to roles with proper authorization', async function (assert) {
assert.expect(2);
await visit(urls.orgScope);
assert.ok(
instances.orgScope.authorized_collection_actions.roles.includes('list')
);
assert.ok(find(`[href="${urls.roles}"]`));
});
test('Users cannot navigate to index without either list or create actions', async function (assert) {
assert.expect(2);
instances.orgScope.authorized_collection_actions.roles = [];
await visit(urls.orgScope);
assert.notOk(
instances.orgScope.authorized_collection_actions.roles.includes('list')
);
assert.notOk(find(`[href="${urls.roles}"]`));
});
test('Users can navigate to index with only create action', async function (assert) {
assert.expect(1);
instances.orgScope.authorized_collection_actions.roles = ['create'];
await visit(urls.orgScope);
assert.ok(find(`[href="${urls.roles}"]`));
});
});