Files
threshold-ui/ui/admin/tests/acceptance/workers/create-test.js
T
Devon Anderson c09efbae10 chore: 🤖 Migrate form.inut to Hds::TextInput::Field (#2151)
* chore: 🤖 Migrate `form.inut` to `Hds::TextInput::Field`

Migrate `form/create-worker-led` form to use `Hds:Text::InputField`
instead of `form.input`

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12477

* refactor: 💡 Added `optional` and `requred` arguments for fields

Added `optional` and `require` arguments for all needed fields.

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12477

* refactor: 💡 fix failing test

fix failing test

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12477
2024-02-28 13:02:02 -05:00

163 lines
5.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import {
visit,
fillIn,
click,
find,
findAll,
currentURL,
} 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';
module('Acceptance | workers | create', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let globalScope;
let workersURL;
let newWorkerURL;
let getWorkersCount;
hooks.beforeEach(function () {
globalScope = this.server.create('scope', { id: 'global' });
workersURL = `/scopes/global/workers`;
newWorkerURL = `${workersURL}/new`;
getWorkersCount = () => this.server.schema.workers.all().length;
authenticateSession({});
});
test('can create new workers', async function (assert) {
const workersCount = getWorkersCount();
await visit(newWorkerURL);
await fillIn('[name="worker_auth_registration_request"]', 'token');
await click('[type="submit"]');
assert.strictEqual(getWorkersCount(), workersCount + 1);
});
test('cluster id input field is visible for `hcp` binary', async function (assert) {
const featuresService = this.owner.lookup('service:features');
featuresService.enable('byow-pki-hcp-cluster-id');
await visit(newWorkerURL);
const labels = findAll('label.hds-form-label');
assert.dom(labels[0]).hasText('Boundary Cluster ID (Optional)');
assert.dom(labels[2]).doesNotIncludeText('Initial Upstreams');
});
test('initial upstreams input field is visible for `oss` binary', async function (assert) {
const featuresService = this.owner.lookup('service:features');
await visit(newWorkerURL);
const labels = findAll('label.hds-form-label');
assert.false(featuresService.isEnabled('byow-pki-hcp-cluster-id'));
assert.dom(labels[0]).doesNotIncludeText('Boundary Cluster ID');
assert.dom(labels[2]).hasText('Initial Upstreams (Optional)');
});
test('download and install step shows correct oss instructions', async function (assert) {
const featuresService = this.owner.lookup('service:features');
await visit(newWorkerURL);
const createSection = findAll('.worker-create-section');
assert.false(featuresService.isEnabled('byow-pki-hcp-cluster-id'));
assert
.dom(createSection[1])
.includesText(
'curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - ;',
);
assert
.dom(createSection[1])
.doesNotIncludeText(
'wget -q "$(curl -fsSL "https://api.releases.hashicorp.com/v1/releases/boundary/latest?license_class=enterprise"',
);
});
test('download and install step shows correct hcp instructions', async function (assert) {
const featuresService = this.owner.lookup('service:features');
featuresService.enable('byow-pki-hcp-cluster-id');
await visit(newWorkerURL);
const createSection = findAll('.worker-create-section');
assert
.dom(createSection[1])
.includesText(
'wget -q "$(curl -fsSL "https://api.releases.hashicorp.com/v1/releases/boundary/latest?license_class=enterprise"',
);
assert
.dom(createSection[1])
.doesNotIncludeText(
'curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - ;',
);
});
test('Users can navigate to new workers route with proper authorization', async function (assert) {
await visit(workersURL);
assert.ok(
globalScope.authorized_collection_actions.workers.includes(
'create:worker-led',
),
);
assert.dom(`[href="${newWorkerURL}"]`).isVisible();
});
test('Users cannot navigate to new workers route without proper authorization', async function (assert) {
globalScope.authorized_collection_actions.workers = [];
await visit(workersURL);
assert.notOk(
globalScope.authorized_collection_actions.users.includes(
'create:worker-led',
),
);
assert.dom(`[href="${newWorkerURL}"]`).isNotVisible();
});
test('saving a new user with invalid fields displays error messages', async function (assert) {
this.server.post('/workers:create:worker-led', () => {
return new Response(
500,
{},
{
status: 500,
code: 'api_error',
message: 'rpc error: code = Unknown',
},
);
});
await visit(newWorkerURL);
await fillIn('[name="worker_auth_registration_request"]', 'token');
await click('[type="submit"]');
assert.strictEqual(
find('.rose-notification-body').textContent.trim(),
'rpc error: code = Unknown',
'Displays primary error message.',
);
});
test('users cannot directly navigate to new worker route without proper authorization', async function (assert) {
globalScope.authorized_collection_actions.workers =
globalScope.authorized_collection_actions.workers.filter(
(item) => item !== 'create:worker-led',
);
await visit(newWorkerURL);
assert.false(
globalScope.authorized_collection_actions.workers.includes(
'create:worker-led',
),
);
assert.strictEqual(currentURL(), workersURL);
});
});