test: 💍 add missing controller unit tests in admin-ui (#2553)

* test: 💍 add missing controller unit tests in admin-ui

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-14740
This commit is contained in:
Lisbet Alvarez authored and GitHub committed 2024-11-12 09:27:07 -08:00
1 parent 7c1814118d
commit 57568f9a8c
77 files changed
+946 -81

No files matched your search

@@ -16,6 +16,7 @@ module(
'controller:scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/index',
);
assert.ok(controller);
assert.ok(controller.credentialLibraries);
});
},
);
@@ -5,17 +5,127 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { visit } from '@ember/test-helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { setupIntl } from 'ember-intl/test-support';
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
import { authenticateSession } from 'ember-simple-auth/test-support';
module(
'Unit | Controller | scopes/scope/credential-stores/credential-store/credential-libraries/index',
function (hooks) {
setupTest(hooks);
setupMirage(hooks);
setupIndexedDb(hooks);
setupIntl(hooks, 'en-us');
test('it exists', function (assert) {
let controller = this.owner.lookup(
let store;
let controller;
let getCredentialLibraryCount;
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
credentialStore: null,
credentialLibrary: null,
};
const urls = {
credentialLibraries: null,
};
hooks.beforeEach(function () {
authenticateSession({});
store = this.owner.lookup('service:store');
controller = this.owner.lookup(
'controller:scopes/scope/credential-stores/credential-store/credential-libraries/index',
);
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,
});
instances.credentialLibrary = this.server.create('credential-library', {
credentialStore: instances.credentialStore,
extensions: [{ key: 'foo', value: 'bar' }],
});
urls.credentialLibraries = `/scopes/${instances.scopes.project.id}/credential-stores/${instances.credentialStore.id}/credential-libraries`;
getCredentialLibraryCount = () =>
this.server.schema.credentialLibraries.all().models.length;
});
test('it exists', function (assert) {
assert.ok(controller);
assert.ok(controller.credentialStores);
});
test('cancel action rolls-back changes on the specified model', async function (assert) {
await visit(urls.credentialLibraries);
const credentialLibrary = await store.findRecord(
'credential-library',
instances.credentialLibrary.id,
);
credentialLibrary.name = 'test';
assert.strictEqual(credentialLibrary.name, 'test');
await controller.cancel(credentialLibrary);
assert.notEqual(credentialLibrary.name, 'test');
});
test('save action saves changes on the specified model', async function (assert) {
await visit(urls.credentialLibraries);
const credentialLibrary = await store.findRecord(
'credential-library',
instances.credentialLibrary.id,
);
credentialLibrary.name = 'test';
await controller.save(credentialLibrary);
assert.strictEqual(credentialLibrary.name, 'test');
});
test('delete action destroys specified model', async function (assert) {
const credentialLibrary = await store.findRecord(
'credential-library',
instances.credentialLibrary.id,
);
const credentialLibraryCount = getCredentialLibraryCount();
await controller.delete(credentialLibrary);
assert.strictEqual(
getCredentialLibraryCount(),
credentialLibraryCount - 1,
);
});
test('edit action updates to a dirty state', async function (assert) {
const credentialLibrary = await store.findRecord(
'credential-library',
instances.credentialLibrary.id,
);
assert.false(credentialLibrary.hasDirtyAttributes);
controller.edit(credentialLibrary);
assert.true(credentialLibrary.hasDirtyAttributes);
});
},
);
@@ -11,12 +11,12 @@ module(
function (hooks) {
setupTest(hooks);
// TODO: Replace this with your real tests.
test('it exists', function (assert) {
let controller = this.owner.lookup(
'controller:scopes/scope/credential-stores/credential-store/credential-libraries/new',
);
assert.ok(controller);
assert.ok(controller.credentialLibraries);
});
},
);
@@ -16,6 +16,7 @@ module(
'controller:scopes/scope/credential-stores/credential-store/credentials/credential/index',
);
assert.ok(controller);
assert.ok(controller.credentials);
});
},
);
@@ -5,17 +5,111 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { visit } from '@ember/test-helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { setupIntl } from 'ember-intl/test-support';
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
import { authenticateSession } from 'ember-simple-auth/test-support';
module(
'Unit | Controller | scopes/scope/credential-stores/credential-store/credentials/index',
function (hooks) {
setupTest(hooks);
setupMirage(hooks);
setupIndexedDb(hooks);
setupIntl(hooks, 'en-us');
test('it exists', function (assert) {
let controller = this.owner.lookup(
let store;
let controller;
let getCredentialCount;
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
credentialStore: null,
credential: null,
};
const urls = {
credentials: null,
};
hooks.beforeEach(function () {
authenticateSession({});
store = this.owner.lookup('service:store');
controller = this.owner.lookup(
'controller:scopes/scope/credential-stores/credential-store/credentials/index',
);
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,
});
instances.credential = this.server.create('credential', {
credentialStore: instances.credentialStore,
extensions: [{ key: 'foo', value: 'bar' }],
});
urls.credentials = `/scopes/${instances.scopes.project.id}/credential-stores/${instances.credentialStore.id}/credentials`;
getCredentialCount = () =>
this.server.schema.credentials.all().models.length;
});
test('it exists', function (assert) {
assert.ok(controller);
assert.ok(controller.credentialStores);
});
test('cancel action rolls-back changes on the specified model', async function (assert) {
await visit(urls.credentials);
const credential = await store.findRecord(
'credential',
instances.credential.id,
);
credential.name = 'test';
assert.strictEqual(credential.name, 'test');
await controller.cancel(credential);
assert.notEqual(credential.name, 'test');
});
test('save action saves changes on the specified model', async function (assert) {
await visit(urls.credentials);
const credential = await store.findRecord(
'credential',
instances.credential.id,
);
credential.name = 'test';
await controller.save(credential);
assert.strictEqual(credential.name, 'test');
});
test('delete action destroys specified model', async function (assert) {
const credential = await store.findRecord(
'credential',
instances.credential.id,
);
const credentialCount = getCredentialCount();
await controller.delete(credential);
assert.strictEqual(getCredentialCount(), credentialCount - 1);
});
},
);
@@ -16,6 +16,7 @@ module(
'controller:scopes/scope/credential-stores/credential-store/credentials/new',
);
assert.ok(controller);
assert.ok(controller.credentials);
});
},
);
@@ -16,6 +16,7 @@ module(
'controller:scopes/scope/credential-stores/credential-store/index',
);
assert.ok(controller);
assert.ok(controller.credentialStores);
});
},
);
@@ -6,7 +6,10 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { setupIntl } from 'ember-intl/test-support';
import { waitUntil } from '@ember/test-helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
import { waitUntil, visit } from '@ember/test-helpers';
import { authenticateSession } from 'ember-simple-auth/test-support';
import {
TYPE_CREDENTIAL_STORE_STATIC,
TYPE_CREDENTIAL_STORE_VAULT,
@@ -16,20 +19,97 @@ module(
'Unit | Controller | scopes/scope/credential-stores/index',
function (hooks) {
setupTest(hooks);
setupMirage(hooks);
setupIndexedDb(hooks);
setupIntl(hooks, 'en-us');
let controller;
let store;
let getCredentialStoreCount;
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
credentialStore: null,
};
const urls = {
credentialStores: null,
};
hooks.beforeEach(function () {
authenticateSession({});
controller = this.owner.lookup(
'controller:scopes/scope/credential-stores/index',
);
store = this.owner.lookup('service:store');
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.credentialStores = `scopes/${instances.scopes.project.id}/credential-stores`;
getCredentialStoreCount = () =>
this.server.schema.credentialStores.all().models.length;
});
test('it exists', function (assert) {
assert.ok(controller);
});
test('cancel action rolls-back changes on the specified model', async function (assert) {
await visit(urls.credentialStores);
const credentialStore = await store.findRecord(
'credential-store',
instances.credentialStore.id,
);
credentialStore.name = 'test';
assert.strictEqual(credentialStore.name, 'test');
await controller.cancel(credentialStore);
assert.notEqual(credentialStore.name, 'test');
});
test('save action saves changes on the specified model', async function (assert) {
await visit(urls.credentialStores);
const credentialStore = await store.findRecord(
'credential-store',
instances.credentialStore.id,
);
credentialStore.name = 'test';
await controller.save(credentialStore);
assert.strictEqual(credentialStore.name, 'test');
});
test('delete action destroys specified model', async function (assert) {
const credentialStore = await store.findRecord(
'credential-store',
instances.credentialStore.id,
);
const credentialStoreCount = getCredentialStoreCount();
await controller.delete(credentialStore);
assert.strictEqual(getCredentialStoreCount(), credentialStoreCount - 1);
});
test('credStoreTypeOptions returns expected object', function (assert) {
assert.deepEqual(controller.credStoreTypeOptions, [
{ id: TYPE_CREDENTIAL_STORE_STATIC, name: 'Static' },
@@ -16,6 +16,7 @@ module(
'controller:scopes/scope/credential-stores/new',
);
assert.ok(controller);
assert.ok(controller.credentialStores);
});
},
);