Modular logistics and supply chain operating system (LSOS)
JavaScript driver-appfleet-managementfreight-managementinfrastructureinventory-managementlast-mile-deliverylogisticsondemandopen-sourceorder-managementroute-optimizationsupply-chain-managementtracking-and-monitoringtransport-management-systemtransportationwarehouse-management
test(console): unit tests for 2FA + notification settings controllers
Ronald A. Richardson3e14148703a2
diff --git a/console/tests/unit/controllers/console/admin/two-fa-settings-test.js b/console/tests/unit/controllers/console/admin/two-fa-settings-test.jsindex e4a95070..75db0213 100644--- a/console/tests/unit/controllers/console/admin/two-fa-settings-test.js+++ b/console/tests/unit/controllers/console/admin/two-fa-settings-test.js@@ -1,12 +1,33 @@import { module, test } from 'qunit';import { setupTest } from '@fleetbase/console/tests/helpers';+import { settled } from '@ember/test-helpers';+import Service from '@ember/service';module('Unit | Controller | console/admin/two-fa-settings', function (hooks) {setupTest(hooks);- // TODO: Replace this with your real tests.- test('it exists', function (assert) {- let controller = this.owner.lookup('controller:console/admin/two-fa-settings');- assert.ok(controller);+ hooks.beforeEach(function () {+ // Constructor auto-loads the system config; stub fetch so lookup settles deterministically.+ class FetchStub extends Service {+ get() {+ return Promise.resolve({});+ }+ }+ this.owner.register('service:fetch', FetchStub);+ });++ test('the toggle actions immutably patch twoFaSettings', async function (assert) {+ const controller = this.owner.lookup('controller:console/admin/two-fa-settings');+ await settled();++ controller.onTwoFaToggled(true);+ assert.true(controller.twoFaSettings.enabled);++ controller.onTwoFaMethodSelected('authenticator');+ assert.strictEqual(controller.twoFaSettings.method, 'authenticator');+ assert.true(controller.twoFaSettings.enabled, 'previous keys are preserved');++ controller.onTwoFaEnforceToggled(true);+ assert.true(controller.twoFaSettings.enforced);});});diff --git a/console/tests/unit/controllers/console/settings/notifications-test.js b/console/tests/unit/controllers/console/settings/notifications-test.jsindex c2942b5e..a271cdb2 100644--- a/console/tests/unit/controllers/console/settings/notifications-test.js+++ b/console/tests/unit/controllers/console/settings/notifications-test.js@@ -1,12 +1,44 @@import { module, test } from 'qunit';import { setupTest } from '@fleetbase/console/tests/helpers';+import { settled } from '@ember/test-helpers';+import Service from '@ember/service';module('Unit | Controller | console/settings/notifications', function (hooks) {setupTest(hooks);- // TODO: Replace this with your real tests.- test('it exists', function (assert) {- let controller = this.owner.lookup('controller:console/settings/notifications');- assert.ok(controller);+ hooks.beforeEach(function () {+ // Constructor auto-performs getSettings; stub fetch so lookup settles deterministically.+ class FetchStub extends Service {+ get() {+ return Promise.resolve({ notificationSettings: {} });+ }+ }+ this.owner.register('service:fetch', FetchStub);+ });++ test('onSelectNotifiable records notifiables and derives transport methods', async function (assert) {+ const controller = this.owner.lookup('controller:console/settings/notifications');+ await settled();++ controller.onSelectNotifiable({ definition: 'order.created', name: 'Order Created' }, [{ value: 'user_1' }]);++ const settings = controller.notificationSettings;+ const keys = Object.keys(settings);+ assert.strictEqual(keys.length, 1, 'one notification key is recorded');++ const entry = settings[keys[0]];+ assert.deepEqual(entry.notifiables, [{ value: 'user_1' }]);+ assert.strictEqual(entry.definition, 'order.created');+ assert.deepEqual(entry.via, [{ identifier: 'user_1', methods: ['email', 'sms'] }], 'each notifiable gets the default transport methods');+ });++ test('mutateNotificationSettings merges into the existing settings', async function (assert) {+ const controller = this.owner.lookup('controller:console/settings/notifications');+ await settled();++ controller.notificationSettings = { a: 1 };+ controller.mutateNotificationSettings({ b: 2 });++ assert.deepEqual(controller.notificationSettings, { a: 1, b: 2 });});});diff --git a/console/tests/unit/controllers/console/settings/two-fa-test.js b/console/tests/unit/controllers/console/settings/two-fa-test.jsindex 72662d6f..d56f2c84 100644--- a/console/tests/unit/controllers/console/settings/two-fa-test.js+++ b/console/tests/unit/controllers/console/settings/two-fa-test.js@@ -1,12 +1,33 @@import { module, test } from 'qunit';import { setupTest } from '@fleetbase/console/tests/helpers';+import { settled } from '@ember/test-helpers';+import Service from '@ember/service';module('Unit | Controller | console/settings/two-fa', function (hooks) {setupTest(hooks);- // TODO: Replace this with your real tests.- test('it exists', function (assert) {- let controller = this.owner.lookup('controller:console/settings/two-fa');- assert.ok(controller);+ hooks.beforeEach(function () {+ // Constructor auto-loads system/company/user 2FA settings; stub fetch so lookup settles.+ class FetchStub extends Service {+ get() {+ return Promise.resolve({});+ }+ }+ this.owner.register('service:fetch', FetchStub);+ });++ test('the toggle actions immutably patch twoFaSettings', async function (assert) {+ const controller = this.owner.lookup('controller:console/settings/two-fa');+ await settled();++ controller.onTwoFaToggled(true);+ assert.true(controller.twoFaSettings.enabled);++ controller.onTwoFaMethodSelected('sms');+ assert.strictEqual(controller.twoFaSettings.method, 'sms');+ assert.true(controller.twoFaSettings.enabled, 'previous keys are preserved');++ controller.onTwoFaEnforceToggled(true);+ assert.true(controller.twoFaSettings.enforced);});});