2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-01 09:39:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2021-08-27 14:43:18 -04:00
|
|
|
import { module, test } from 'qunit';
|
2022-12-07 10:32:08 -08:00
|
|
|
import { visit, click, currentURL } from '@ember/test-helpers';
|
2024-12-02 12:51:24 -06:00
|
|
|
import { setupApplicationTest } from 'admin/tests/helpers';
|
2021-08-27 14:43:18 -04:00
|
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
2024-04-05 10:59:35 -07:00
|
|
|
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
2021-08-27 14:43:18 -04:00
|
|
|
import { Response } from 'miragejs';
|
2024-11-22 11:27:53 -08:00
|
|
|
import { authenticateSession } from 'ember-simple-auth/test-support';
|
2024-12-20 14:16:43 -05:00
|
|
|
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
2025-03-28 15:00:59 -07:00
|
|
|
import * as selectors from './selectors';
|
2025-08-11 11:04:07 -07:00
|
|
|
import { setRunOptions } from 'ember-a11y-testing/test-support';
|
2021-08-27 14:43:18 -04:00
|
|
|
|
|
|
|
|
module('Acceptance | scopes | delete', function (hooks) {
|
|
|
|
|
setupApplicationTest(hooks);
|
|
|
|
|
setupMirage(hooks);
|
2024-04-05 10:59:35 -07:00
|
|
|
setupIndexedDb(hooks);
|
2021-08-27 14:43:18 -04:00
|
|
|
|
|
|
|
|
let getScopeCount;
|
2025-03-28 15:00:59 -07:00
|
|
|
let confirmService;
|
2021-08-27 14:43:18 -04:00
|
|
|
|
|
|
|
|
const instances = {
|
|
|
|
|
scopes: {
|
|
|
|
|
global: null,
|
|
|
|
|
org: null,
|
|
|
|
|
project: null,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
const urls = {
|
|
|
|
|
globalScope: null,
|
|
|
|
|
orgScope: null,
|
|
|
|
|
orgScopeEdit: null,
|
|
|
|
|
projectScope: null,
|
|
|
|
|
projectScopeEdit: null,
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-03 10:27:27 -08:00
|
|
|
hooks.beforeEach(async function () {
|
2021-08-27 14:43:18 -04:00
|
|
|
// Generate resources
|
|
|
|
|
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' },
|
|
|
|
|
});
|
|
|
|
|
// Generate route URLs for resources
|
|
|
|
|
urls.globalScope = `/scopes/global/scopes`;
|
|
|
|
|
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
|
|
|
|
|
urls.orgScopeEdit = `/scopes/${instances.scopes.org.id}/edit`;
|
|
|
|
|
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
|
2022-12-07 10:32:08 -08:00
|
|
|
// Generate resource counter
|
2021-08-27 14:43:18 -04:00
|
|
|
getScopeCount = (type) => this.server.schema.scopes.where({ type }).length;
|
2025-03-28 15:00:59 -07:00
|
|
|
confirmService = this.owner.lookup('service:confirm');
|
2024-12-03 10:27:27 -08:00
|
|
|
await authenticateSession({ isGlobal: true });
|
2021-08-27 14:43:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('can delete scope', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2021-08-27 14:43:18 -04:00
|
|
|
const orgScopeCount = getScopeCount('org');
|
2022-12-07 10:32:08 -08:00
|
|
|
await visit(urls.orgScope);
|
|
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
await click(commonSelectors.HREF(urls.orgScopeEdit));
|
|
|
|
|
await click(selectors.MANAGE_PROJECTS_DROPDOWN);
|
|
|
|
|
await click(selectors.MANAGE_PROJECTS_DROPDOWN_DELETE);
|
2022-12-07 10:32:08 -08:00
|
|
|
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(getScopeCount('org'), orgScopeCount - 1);
|
2021-08-27 14:43:18 -04:00
|
|
|
});
|
|
|
|
|
|
2021-09-02 10:58:06 -04:00
|
|
|
test('cannot delete scope without proper authorization', async function (assert) {
|
2022-12-07 10:32:08 -08:00
|
|
|
instances.scopes.org.update({
|
|
|
|
|
authorized_actions: instances.scopes.org.authorized_actions.filter(
|
2023-11-22 14:07:41 -05:00
|
|
|
(item) => item !== 'delete',
|
2022-12-07 10:32:08 -08:00
|
|
|
),
|
|
|
|
|
});
|
|
|
|
|
await visit(urls.orgScope);
|
|
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
await click(commonSelectors.HREF(urls.orgScopeEdit));
|
2022-12-07 10:32:08 -08:00
|
|
|
|
|
|
|
|
assert.false(instances.scopes.org.authorized_actions.includes('delete'));
|
2025-03-28 15:00:59 -07:00
|
|
|
assert.dom(selectors.MANAGE_PROJECTS_DROPDOWN).doesNotExist();
|
2021-09-02 10:58:06 -04:00
|
|
|
});
|
|
|
|
|
|
2021-08-27 14:43:18 -04:00
|
|
|
test('can accept delete scope via dialog', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2021-08-27 14:43:18 -04:00
|
|
|
confirmService.enabled = true;
|
|
|
|
|
const orgScopeCount = getScopeCount('org');
|
2022-12-07 10:32:08 -08:00
|
|
|
await visit(urls.orgScope);
|
|
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
await click(commonSelectors.HREF(urls.orgScopeEdit));
|
|
|
|
|
await click(selectors.MANAGE_PROJECTS_DROPDOWN);
|
|
|
|
|
await click(selectors.MANAGE_PROJECTS_DROPDOWN_DELETE);
|
2024-12-20 14:16:43 -05:00
|
|
|
await click(commonSelectors.MODAL_WARNING_CONFIRM_BTN);
|
2022-12-07 10:32:08 -08:00
|
|
|
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(getScopeCount('org'), orgScopeCount - 1);
|
2022-12-07 10:32:08 -08:00
|
|
|
assert.strictEqual(currentURL(), urls.globalScope);
|
2021-08-27 14:43:18 -04:00
|
|
|
});
|
|
|
|
|
|
2022-12-07 10:32:08 -08:00
|
|
|
test('can cancel delete scope via dialog', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2021-08-27 14:43:18 -04:00
|
|
|
confirmService.enabled = true;
|
|
|
|
|
const orgScopeCount = getScopeCount('org');
|
2022-12-07 10:32:08 -08:00
|
|
|
await visit(urls.orgScope);
|
|
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
await click(commonSelectors.HREF(urls.orgScopeEdit));
|
|
|
|
|
await click(selectors.MANAGE_PROJECTS_DROPDOWN);
|
|
|
|
|
await click(selectors.MANAGE_PROJECTS_DROPDOWN_DELETE);
|
2024-12-20 14:16:43 -05:00
|
|
|
await click(commonSelectors.MODAL_WARNING_CANCEL_BTN);
|
2022-12-07 10:32:08 -08:00
|
|
|
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(getScopeCount('org'), orgScopeCount);
|
2022-12-07 10:32:08 -08:00
|
|
|
assert.strictEqual(currentURL(), urls.orgScopeEdit);
|
2021-08-27 14:43:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('deleting a scope which errors displays error messages', async function (assert) {
|
2025-08-11 11:04:07 -07:00
|
|
|
setRunOptions({
|
|
|
|
|
rules: {
|
|
|
|
|
'color-contrast': {
|
|
|
|
|
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-07 10:32:08 -08:00
|
|
|
await visit(urls.orgScope);
|
2021-08-27 14:43:18 -04:00
|
|
|
this.server.del('/scopes/:id', () => {
|
|
|
|
|
return new Response(
|
|
|
|
|
490,
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
status: 490,
|
|
|
|
|
code: 'error',
|
|
|
|
|
message: 'Oops.',
|
2023-11-22 14:07:41 -05:00
|
|
|
},
|
2021-08-27 14:43:18 -04:00
|
|
|
);
|
|
|
|
|
});
|
2022-12-07 10:32:08 -08:00
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
await click(commonSelectors.HREF(urls.orgScopeEdit));
|
|
|
|
|
await click(selectors.MANAGE_PROJECTS_DROPDOWN);
|
|
|
|
|
await click(selectors.MANAGE_PROJECTS_DROPDOWN_DELETE);
|
2022-12-07 10:32:08 -08:00
|
|
|
|
2025-02-13 15:54:40 -05:00
|
|
|
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText('Oops.');
|
2021-08-27 14:43:18 -04:00
|
|
|
});
|
|
|
|
|
});
|