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/auth-methods/auth-method/accounts/account/index',
);
assert.ok(controller);
assert.ok(controller.accounts);
});
},
);
@@ -5,17 +5,77 @@
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 { authenticateSession } from 'ember-simple-auth/test-support';
import { TYPE_AUTH_METHOD_PASSWORD } from 'api/models/auth-method';
module(
'Unit | Controller | scopes/scope/auth-methods/auth-method/accounts/account/set-password',
function (hooks) {
setupTest(hooks);
setupMirage(hooks);
test('it exists', function (assert) {
let controller = this.owner.lookup(
let controller;
let store;
const instances = {
scopes: {
global: null,
},
authMethod: null,
account: null,
};
const urls = {
globalScope: null,
accounts: null,
};
hooks.beforeEach(async function () {
authenticateSession({});
controller = this.owner.lookup(
'controller:scopes/scope/auth-methods/auth-method/accounts/account/set-password',
);
store = this.owner.lookup('service:store');
instances.scopes.global = this.server.create('scope', {
id: 'global',
type: 'global',
});
instances.authMethod = this.server.create('auth-method', {
scope: instances.scopes.global,
type: TYPE_AUTH_METHOD_PASSWORD,
});
instances.account = this.server.create('account', {
scope: instances.scopes.global,
authMethod: instances.authMethod,
});
urls.globalScope = `/scopes/global`;
});
test('it exists', function (assert) {
assert.ok(controller);
assert.ok(controller.accounts);
});
test('setPassword action makes the correct API call with correct values', async function (assert) {
assert.expect(1);
const password = 'current password';
this.server.post(
'/accounts/:idMethod',
(_, { params: { idMethod }, requestBody }) => {
const attrs = JSON.parse(requestBody);
assert.strictEqual(attrs.password, password);
const id = idMethod.split(':')[0];
return { id };
},
);
await visit(urls.globalScope);
const account = await store.findRecord('account', instances.account.id);
await controller.setPassword(account, password);
});
},
);
@@ -5,17 +5,94 @@
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 { authenticateSession } from 'ember-simple-auth/test-support';
import { TYPE_AUTH_METHOD_PASSWORD } from 'api/models/auth-method';
module(
'Unit | Controller | scopes/scope/auth-methods/auth-method/accounts/index',
function (hooks) {
setupTest(hooks);
setupMirage(hooks);
setupIntl(hooks, 'en-us');
test('it exists', function (assert) {
let controller = this.owner.lookup(
let controller;
let store;
let getAccountCount;
const instances = {
scopes: {
global: null,
},
authMethod: null,
account: null,
};
const urls = {
accounts: null,
};
hooks.beforeEach(async function () {
authenticateSession({});
controller = this.owner.lookup(
'controller:scopes/scope/auth-methods/auth-method/accounts/index',
);
store = this.owner.lookup('service:store');
instances.scopes.global = this.server.create('scope', {
id: 'global',
type: 'global',
});
instances.authMethod = this.server.create('auth-method', {
scope: instances.scopes.global,
type: TYPE_AUTH_METHOD_PASSWORD,
});
instances.account = this.server.create('account', {
scope: instances.scopes.global,
authMethod: instances.authMethod,
});
getAccountCount = () => this.server.schema.accounts.all().models.length;
urls.accounts = `/scopes/global/auth-methods/${instances.authMethod.id}/accounts`;
});
test('it exists', function (assert) {
assert.ok(controller);
assert.ok(controller.authMethods);
});
test('cancel action rolls-back changes on the specified model', async function (assert) {
await visit(urls.accounts);
const account = await store.findRecord('account', instances.account.id);
account.name = 'test';
assert.strictEqual(account.name, 'test');
await controller.cancel(account);
assert.notEqual(account.name, 'test');
});
test('save action saves changes on the specified model', async function (assert) {
await visit(urls.accounts);
const account = await store.findRecord('account', instances.account.id);
account.name = 'test';
await controller.save(account);
assert.strictEqual(account.name, 'test');
});
test('delete action destroys specified model', async function (assert) {
const account = await store.findRecord('account', instances.account.id);
const accountCount = getAccountCount();
await controller.delete(account);
assert.strictEqual(getAccountCount(), accountCount - 1);
});
},
);
@@ -16,6 +16,7 @@ module(
'controller:scopes/scope/auth-methods/auth-method/accounts/new',
);
assert.ok(controller);
assert.ok(controller.accounts);
});
},
);
@@ -16,6 +16,7 @@ module(
'controller:scopes/scope/auth-methods/auth-method/index',
);
assert.ok(controller);
assert.ok(controller.authMethods);
});
},
);
@@ -5,17 +5,117 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { setupIntl } from 'ember-intl/test-support';
import { visit } from '@ember/test-helpers';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { TYPE_AUTH_METHOD_LDAP } from 'api/models/auth-method';
module(
'Unit | Controller | scopes/scope/auth-methods/auth-method/managed-groups/index',
function (hooks) {
setupTest(hooks);
setupMirage(hooks);
setupIntl(hooks, 'en-us');
test('it exists', function (assert) {
let controller = this.owner.lookup(
let controller;
let store;
let getManagedGroupCount;
const instances = {
scopes: {
global: null,
},
authMethod: null,
managedGroup: null,
};
const urls = {
managedGroups: null,
};
hooks.beforeEach(async function () {
authenticateSession({});
controller = this.owner.lookup(
'controller:scopes/scope/auth-methods/auth-method/managed-groups/index',
);
store = this.owner.lookup('service:store');
instances.scopes.global = this.server.create('scope', {
id: 'global',
type: 'global',
});
instances.authMethod = this.server.create('auth-method', {
scope: instances.scopes.global,
type: TYPE_AUTH_METHOD_LDAP,
});
instances.managedGroup = this.server.create('managed-group', {
scope: instances.scopes.global,
authMethod: instances.authMethod,
});
getManagedGroupCount = () =>
this.server.schema.managedGroups.all().models.length;
urls.managedGroups = `/scopes/global/auth-methods/${instances.authMethod.id}/managed-groups`;
});
test('it exists', function (assert) {
assert.ok(controller);
assert.ok(controller.authMethods);
});
test('cancel action rolls-back changes on the specified model', async function (assert) {
await visit(urls.managedGroups);
const managedGroup = await store.findRecord(
'managed-group',
instances.managedGroup.id,
);
managedGroup.name = 'test';
assert.strictEqual(managedGroup.name, 'test');
await controller.cancel(managedGroup);
assert.notEqual(managedGroup.name, 'test');
});
test('save action saves changes on the specified model', async function (assert) {
await visit(urls.managedGroups);
const managedGroup = await store.findRecord(
'managed-group',
instances.managedGroup.id,
);
managedGroup.name = 'test';
await controller.save(managedGroup);
assert.strictEqual(managedGroup.name, 'test');
});
test('delete action destroys specified model', async function (assert) {
const managedGroup = await store.findRecord(
'managed-group',
instances.managedGroup.id,
);
const managedGroupCount = getManagedGroupCount();
await controller.delete(managedGroup);
assert.strictEqual(getManagedGroupCount(), managedGroupCount - 1);
});
test('edit action updates to a dirty state', async function (assert) {
const managedGroup = await store.findRecord(
'managed-group',
instances.managedGroup.id,
);
assert.false(managedGroup.hasDirtyAttributes);
controller.edit(managedGroup);
assert.true(managedGroup.hasDirtyAttributes);
});
},
);
@@ -16,6 +16,8 @@ module(
'controller:scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index',
);
assert.ok(controller);
assert.ok(controller.authMethods);
assert.ok(controller.managedGroups);
});
},
);
@@ -16,6 +16,7 @@ module(
'controller:scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members',
);
assert.ok(controller);
assert.ok(controller.managedGroups);
});
},
);
@@ -16,6 +16,8 @@ module(
'controller:scopes/scope/auth-methods/auth-method/managed-groups/new',
);
assert.ok(controller);
assert.ok(controller.authMethods);
assert.ok(controller.managedGroups);
});
},
);