Files
threshold-ui/ui/admin/tests/acceptance/users/list-test.js
T

74 lines
2.1 KiB
JavaScript
Raw Normal View History

import { module, test } from 'qunit';
2021-08-26 00:02:57 -07:00
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 | users | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
2021-08-26 00:02:57 -07:00
let orgURL;
const instances = {
scopes: {
global: null,
org: null,
2021-08-31 15:03:40 -04:00
},
};
const urls = {
scopes: {
2021-08-31 15:03:40 -04:00
org: null,
},
2021-08-31 15:03:40 -04:00
users: null,
};
hooks.beforeEach(function () {
instances.scopes.global = this.server.create('scope', { id: 'global' });
2021-08-30 21:49:48 -07:00
instances.orgScope = this.server.create(
'scope',
{
type: 'org',
scope: { id: 'global', type: 'global' },
},
'withChildren'
);
instances.user = this.server.create('user', {
2021-08-30 21:49:48 -07:00
scope: instances.orgScope,
});
2021-08-30 21:49:48 -07:00
orgURL = `/scopes/${instances.orgScope.id}`;
urls.users = `/scopes/${instances.orgScope.id}/users`;
authenticateSession({});
});
2021-09-01 08:48:08 -07:00
test('Users can navigate to users with proper authorization', async function (assert) {
2021-08-26 00:02:57 -07:00
assert.expect(2);
await visit(orgURL);
2021-08-27 08:06:24 -07:00
assert.ok(
2021-08-30 21:49:48 -07:00
instances.orgScope.authorized_collection_actions.users.includes('list')
2021-08-27 08:06:24 -07:00
);
assert.ok(find(`[href="${urls.users}"]`));
});
2021-08-27 08:06:24 -07:00
test('User cannot navigate to index without either list or create actions', async function (assert) {
2021-08-26 00:02:57 -07:00
assert.expect(2);
2021-08-30 21:49:48 -07:00
instances.orgScope.authorized_collection_actions.users = [];
2021-08-26 00:02:57 -07:00
await visit(orgURL);
assert.notOk(
2021-08-30 21:49:48 -07:00
instances.orgScope.authorized_collection_actions.users.includes('list')
2021-08-26 00:02:57 -07:00
);
2021-08-30 21:49:48 -07:00
assert.notOk(find(`[href="${urls.users}"]`));
});
2021-08-27 08:06:24 -07:00
test('User can navigate to index with only create action', async function (assert) {
assert.expect(1);
2021-08-30 21:49:48 -07:00
instances.orgScope.authorized_collection_actions.users = ['create'];
2021-08-27 08:06:24 -07:00
await visit(orgURL);
assert.ok(find(`[href="${urls.users}"]`));
});
});