2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2021-08-11 17:33:54 -07:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
import { visit, currentURL, click, find, fillIn } from '@ember/test-helpers';
|
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
|
|
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
|
|
|
|
import { Response } from 'miragejs';
|
|
|
|
|
import {
|
|
|
|
|
authenticateSession,
|
|
|
|
|
// These are left here intentionally for future reference.
|
|
|
|
|
//currentSession,
|
|
|
|
|
//invalidateSession,
|
|
|
|
|
} from 'ember-simple-auth/test-support';
|
|
|
|
|
|
2021-08-16 17:07:00 -07:00
|
|
|
module('Acceptance | groups | update', function (hooks) {
|
2021-08-11 17:33:54 -07:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
|
|
|
|
|
const instances = {
|
|
|
|
|
scopes: {
|
|
|
|
|
global: null,
|
|
|
|
|
org: null,
|
|
|
|
|
},
|
|
|
|
|
group: null,
|
|
|
|
|
};
|
|
|
|
|
const urls = {
|
|
|
|
|
orgScope: null,
|
|
|
|
|
groups: null,
|
|
|
|
|
group: null,
|
|
|
|
|
newGroup: 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.group = this.server.create('group', {
|
|
|
|
|
scope: instances.scopes.org,
|
|
|
|
|
});
|
|
|
|
|
urls.groups = `/scopes/${instances.scopes.org.id}/groups`;
|
|
|
|
|
urls.group = `${urls.groups}/${instances.group.id}`;
|
|
|
|
|
urls.newGroup = `${urls.groups}/new`;
|
|
|
|
|
});
|
2021-08-12 13:29:33 -07:00
|
|
|
|
2021-08-11 17:33:54 -07:00
|
|
|
test('can save changes to an existing group', async function (assert) {
|
|
|
|
|
await visit(urls.group);
|
|
|
|
|
await click('form [type="button"]', 'Activate edit mode');
|
|
|
|
|
await fillIn('[name="name"]', 'Updated admin group');
|
|
|
|
|
await click('.rose-form-actions [type="submit"]');
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(currentURL(), urls.group);
|
|
|
|
|
assert.strictEqual(this.server.db.groups[0].name, 'Updated admin group');
|
2021-08-11 17:33:54 -07:00
|
|
|
});
|
|
|
|
|
|
2021-08-12 13:47:07 -07:00
|
|
|
test('cannot make changes to an existing group without proper authorization', async function (assert) {
|
2021-08-12 13:29:33 -07:00
|
|
|
instances.group.authorized_actions =
|
|
|
|
|
instances.group.authorized_actions.filter((item) => item !== 'update');
|
|
|
|
|
await visit(urls.group);
|
|
|
|
|
assert.notOk(find('.rose-layout-page-actions .rose-button-secondary'));
|
|
|
|
|
});
|
|
|
|
|
|
2021-08-11 17:33:54 -07:00
|
|
|
test('can cancel changes to an existing group', async function (assert) {
|
|
|
|
|
await visit(urls.group);
|
|
|
|
|
await click('form [type="button"]', 'Activate edit mode');
|
|
|
|
|
await fillIn('[name="name"]', 'Updated admin group');
|
|
|
|
|
await click('.rose-form-actions [type="button"]');
|
|
|
|
|
assert.notEqual(find('[name="name"]').value, 'Updated admin group');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('saving an existing group with invalid fields displays error messages', async function (assert) {
|
|
|
|
|
this.server.patch('/groups/:id', () => {
|
|
|
|
|
return new Response(
|
|
|
|
|
400,
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
status: 400,
|
|
|
|
|
code: 'invalid_argument',
|
|
|
|
|
message: 'The request was invalid.',
|
|
|
|
|
details: {
|
|
|
|
|
request_fields: [
|
|
|
|
|
{
|
|
|
|
|
name: 'name',
|
|
|
|
|
description: 'Name is required.',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2023-11-22 14:07:41 -05:00
|
|
|
},
|
2021-08-11 17:33:54 -07:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
await visit(urls.group);
|
|
|
|
|
await click('form [type="button"]', 'Activate edit mode');
|
|
|
|
|
await fillIn('[name="name"]', 'random string');
|
|
|
|
|
await click('[type="submit"]');
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(
|
2021-10-23 11:48:10 -04:00
|
|
|
find('.rose-notification-body').textContent.trim(),
|
2021-08-11 17:33:54 -07:00
|
|
|
'The request was invalid.',
|
2023-11-22 14:07:41 -05:00
|
|
|
'Displays primary error message.',
|
2021-08-11 17:33:54 -07:00
|
|
|
);
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(
|
2024-02-27 13:52:50 -05:00
|
|
|
find('[data-test-error-message-name]').textContent.trim(),
|
2021-08-11 17:33:54 -07:00
|
|
|
'Name is required.',
|
2023-11-22 14:07:41 -05:00
|
|
|
'Displays field-level errors.',
|
2021-08-11 17:33:54 -07:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|