Merge branch 'main' into feature-scope-capabilities

This commit is contained in:
Randall Morey authored and GitHub committed 2021-09-03 09:36:56 -04:00
commit 4afdc77f4c
12 files changed
+331 -48

No files matched your search

@@ -5,7 +5,7 @@ import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { Response } from 'miragejs';
module('Acceptance | credential-stores', function (hooks) {
module('Acceptance | credential-stores | create', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
@@ -21,7 +21,6 @@ module('Acceptance | credential-stores', function (hooks) {
const urls = {
globalScope: null,
orgScope: null,
projectScope: null,
credentialStores: null,
credentialStore: null,
@@ -45,7 +44,6 @@ module('Acceptance | credential-stores', function (hooks) {
});
// Generate route URLs for resources
urls.globalScope = `/scopes/global/scopes`;
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
urls.credentialStores = `${urls.projectScope}/credential-stores`;
urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`;
@@ -58,7 +56,7 @@ module('Acceptance | credential-stores', function (hooks) {
authenticateSession({});
});
test('can create a new credential stores', async function (assert) {
test('Users can create a new credential stores', async function (assert) {
assert.expect(1);
const count = getCredentialStoresCount();
await visit(urls.newCredentialStore);
@@ -67,7 +65,7 @@ module('Acceptance | credential-stores', function (hooks) {
assert.equal(getCredentialStoresCount(), count + 1);
});
test('can cancel create new credential stores', async function (assert) {
test('Users can cancel create new credential stores', async function (assert) {
assert.expect(2);
const count = getCredentialStoresCount();
await visit(urls.newCredentialStore);
@@ -77,6 +75,20 @@ module('Acceptance | credential-stores', function (hooks) {
assert.equal(getCredentialStoresCount(), count);
});
test('Users cannot navigate to new credential stores route without proper authorization', async function (assert) {
assert.expect(2);
instances.scopes.project.authorized_collection_actions[
'credential-stores'
] = [];
await visit(urls.projectScope);
assert.notOk(
instances.scopes.project.authorized_collection_actions[
'credential-stores'
].includes('create')
);
assert.notOk(find(`[href="${urls.credentialStores}"]`));
});
test('saving a new credential store with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.post('/credential-stores', () => {
@@ -0,0 +1,84 @@
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 | credential-stores | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
};
const urls = {
scopes: {
org: null,
},
projectScope: null,
credentialStores: null,
credentialStore: null,
};
hooks.beforeEach(function () {
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.credentialStore = this.server.create('credential-store', {
scope: instances.scopes.project,
});
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
urls.credentialStores = `${urls.projectScope}/credential-stores`;
authenticateSession({});
});
test('Users can navigate to credential-stores with proper authorization', async function (assert) {
assert.expect(2);
await visit(urls.projectScope);
assert.ok(
instances.scopes.project.authorized_collection_actions[
'credential-stores'
].includes('list')
);
assert.ok(find(`[href="${urls.credentialStores}"]`));
});
test('Users cannot navigate to index without either list or create actions', async function (assert) {
assert.expect(2);
instances.scopes.project.authorized_collection_actions[
'credential-stores'
] = [];
await visit(urls.projectScope);
assert.notOk(
instances.scopes.project.authorized_collection_actions[
'credential-stores'
].includes('list')
);
assert.notOk(find(`[href="${urls.credentialStores}"]`));
});
test('Users can navigate to index with only create action', async function (assert) {
assert.expect(1);
instances.scopes.project.authorized_collection_actions[
'credential-stores'
] = ['create'];
await visit(urls.projectScope);
assert.ok(find(`[href="${urls.credentialStores}"]`));
});
});
@@ -10,7 +10,7 @@ import {
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | targets', function (hooks) {
module('Acceptance | targets | create', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
@@ -33,7 +33,6 @@ module('Acceptance | targets', function (hooks) {
};
hooks.beforeEach(function () {
// Generate resources
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
@@ -68,6 +67,29 @@ module('Acceptance | targets', function (hooks) {
assert.equal(getTargetCount(), count + 1);
});
test('can navigate to new targets route with proper authorization', async function (assert) {
assert.expect(2);
await visit(urls.projectScope);
assert.ok(
instances.scopes.project.authorized_collection_actions.targets.includes(
'create'
)
);
assert.ok(find(`[href="${urls.targets}"]`));
});
test('cannot navigate to new targets route without proper authorization', async function (assert) {
assert.expect(2);
instances.scopes.project.authorized_collection_actions.targets = [];
await visit(urls.projectScope);
assert.notOk(
instances.scopes.project.authorized_collection_actions.targets.includes(
'create'
)
);
assert.notOk(find(`[href="${urls.targets}"]`));
});
test('can cancel create new targets', async function (assert) {
assert.expect(2);
const count = getTargetCount();
@@ -0,0 +1,84 @@
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 | targets | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
},
orgScope: null,
};
const urls = {
scopes: {
org: null,
project: null,
},
targets: null,
projectScope: null,
};
hooks.beforeEach(function () {
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.orgScope = this.server.create(
'scope',
{
type: 'org',
scope: { id: 'global', type: 'global' },
},
'withChildren'
);
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.orgScope.id, type: 'org' },
});
instances.target = this.server.create('target', {
scope: instances.scopes.project,
});
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
urls.targets = `${urls.projectScope}/targets`;
authenticateSession({});
});
test('can navigate to targets with proper authorization', async function (assert) {
assert.expect(2);
await visit(urls.projectScope);
assert.ok(
instances.scopes.project.authorized_collection_actions.targets.includes(
'list'
)
);
assert.ok(find(`[href="${urls.targets}"]`));
});
test('User cannot navigate to index without either list or create actions', async function (assert) {
assert.expect(2);
instances.scopes.project.authorized_collection_actions.targets = [];
await visit(urls.projectScope);
assert.notOk(
instances.scopes.project.authorized_collection_actions.targets.includes(
'list'
)
);
assert.notOk(find(`[href="${urls.targets}"]`));
});
test('User can navigate to index with only create action', async function (assert) {
assert.expect(1);
instances.scopes.project.authorized_collection_actions.targets = ['create'];
await visit(urls.projectScope);
assert.ok(find(`[href="${urls.targets}"]`));
});
});