test: 💍 Add tests specific to SSH target creation
* test: 💍 Add tests specific to SSH target creation * test: 💍 creating new SSH target when enabled or disabled Verifying the link to create new SSH targets is not present when ssh-targets is not enabled * refactor: update create targets acceptance test names
This commit is contained in:
1 parent
9fae8f2a9f
commit
f4535c8307
2 files changed
+80
-5
No files matched your search
@@ -157,6 +157,7 @@ module.exports = function (environment) {
|
||||
ENV.enableConfirmService = false;
|
||||
|
||||
// Enable tests for development features
|
||||
ENV.featureFlags['ssh-target'] = true;
|
||||
}
|
||||
|
||||
if (environment === 'production') {
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, find, click, fillIn } from '@ember/test-helpers';
|
||||
import {
|
||||
visit,
|
||||
currentURL,
|
||||
find,
|
||||
click,
|
||||
fillIn,
|
||||
getContext,
|
||||
} from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { Response } from 'miragejs';
|
||||
@@ -15,6 +22,7 @@ module('Acceptance | targets | create', function (hooks) {
|
||||
setupMirage(hooks);
|
||||
|
||||
let getTargetCount;
|
||||
let featuresService;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
@@ -34,6 +42,8 @@ module('Acceptance | targets | create', function (hooks) {
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
const { owner } = getContext();
|
||||
featuresService = owner.lookup('service:features');
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
@@ -53,6 +63,7 @@ module('Acceptance | targets | create', function (hooks) {
|
||||
urls.targets = `${urls.projectScope}/targets`;
|
||||
urls.target = `${urls.targets}/${instances.target.id}`;
|
||||
urls.unknownTarget = `${urls.targets}/foo`;
|
||||
urls.newTarget = `${urls.targets}/new`;
|
||||
urls.newTCPTarget = `${urls.targets}/new?type=tcp`;
|
||||
urls.newSSHTarget = `${urls.targets}/new?type=ssh`;
|
||||
// Generate resource couner
|
||||
@@ -60,6 +71,12 @@ module('Acceptance | targets | create', function (hooks) {
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('defaults to a new TCP target when no query param provided', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.newTarget);
|
||||
assert.equal(find('input[disabled]').value, 'tcp');
|
||||
});
|
||||
|
||||
test('can create new targets of type TCP', async function (assert) {
|
||||
assert.expect(1);
|
||||
const count = getTargetCount();
|
||||
@@ -79,7 +96,7 @@ module('Acceptance | targets | create', function (hooks) {
|
||||
});
|
||||
|
||||
test('can navigate to new targets route with proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
assert.expect(3);
|
||||
await visit(urls.targets);
|
||||
assert.ok(
|
||||
instances.scopes.project.authorized_collection_actions.targets.includes(
|
||||
@@ -87,10 +104,11 @@ module('Acceptance | targets | create', function (hooks) {
|
||||
)
|
||||
);
|
||||
assert.ok(find(`[href="${urls.newTCPTarget}"]`));
|
||||
assert.ok(find(`[href="${urls.newSSHTarget}"]`));
|
||||
});
|
||||
|
||||
test('cannot navigate to new targets route without proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
assert.expect(3);
|
||||
instances.scopes.project.authorized_collection_actions.targets = [];
|
||||
await visit(urls.targets);
|
||||
assert.notOk(
|
||||
@@ -99,9 +117,22 @@ module('Acceptance | targets | create', function (hooks) {
|
||||
)
|
||||
);
|
||||
assert.notOk(find(`[href="${urls.newTCPTarget}"]`));
|
||||
assert.notOk(find(`[href="${urls.newSSHTarget}"]`));
|
||||
});
|
||||
|
||||
test('can cancel create new targets', async function (assert) {
|
||||
test('cannot navigate to new SSH targets route when ssh feature is disabled', async function (assert) {
|
||||
featuresService.disable('ssh-target');
|
||||
assert.expect(2);
|
||||
await visit(urls.targets);
|
||||
assert.ok(
|
||||
instances.scopes.project.authorized_collection_actions.targets.includes(
|
||||
'create'
|
||||
)
|
||||
);
|
||||
assert.notOk(find(`[href="${urls.newSSHTarget}"]`));
|
||||
});
|
||||
|
||||
test('can cancel create new TCP target', async function (assert) {
|
||||
assert.expect(2);
|
||||
const count = getTargetCount();
|
||||
await visit(urls.newTCPTarget);
|
||||
@@ -111,7 +142,17 @@ module('Acceptance | targets | create', function (hooks) {
|
||||
assert.equal(getTargetCount(), count);
|
||||
});
|
||||
|
||||
test('saving a new target with invalid fields displays error messages', async function (assert) {
|
||||
test('can cancel create new SSH target', async function (assert) {
|
||||
assert.expect(2);
|
||||
const count = getTargetCount();
|
||||
await visit(urls.newSSHTarget);
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('.rose-form-actions [type="button"]');
|
||||
assert.equal(currentURL(), urls.targets);
|
||||
assert.equal(getTargetCount(), count);
|
||||
});
|
||||
|
||||
test('saving a new TCP target with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('/targets', () => {
|
||||
return new Response(
|
||||
@@ -143,4 +184,37 @@ module('Acceptance | targets | create', function (hooks) {
|
||||
'Name is required.'
|
||||
);
|
||||
});
|
||||
|
||||
test('saving a new SSH target with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('/targets', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
{
|
||||
status: 400,
|
||||
code: 'invalid_argument',
|
||||
message: 'The request was invalid.',
|
||||
details: {
|
||||
request_fields: [
|
||||
{
|
||||
name: 'name',
|
||||
description: 'Name is required.',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(urls.newSSHTarget);
|
||||
await click('[type="submit"]');
|
||||
assert.ok(
|
||||
find('[role="alert"]').textContent.trim(),
|
||||
'The request was invalid.'
|
||||
);
|
||||
assert.ok(
|
||||
find('.rose-form-error-message').textContent.trim(),
|
||||
'Name is required.'
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user