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): sweep the coverage tail; fix two-fa alert and expiry bugs
Ronald A. Richardson15ec02a5824d
diff --git a/console/app/components/impersonator-tray.js b/console/app/components/impersonator-tray.jsindex 33b69846..92e61138 100644--- a/console/app/components/impersonator-tray.js+++ b/console/app/components/impersonator-tray.js@@ -27,15 +27,19 @@ export default class ImpersonatorTrayComponent extends Component {// Handed back so the caller can cancel the pending reload. Without this the// timer is unreachable once scheduled and always reloads the window.- return later(- this,- () => {- window.location.reload();- },- 600- );+ return later(this, this.reloadWindow, 600);} catch (error) {this.notifications.serverError(error);}}++ /**+ * window.location.reload() cannot be stubbed — Location members are non-configurable+ * per spec — so it is isolated here and callers are tested by replacing this method.+ * Matches InstallationService, ConsoleController and the organizations controllers.+ */+ /* istanbul ignore next -- window.location.reload() cannot be stubbed */+ reloadWindow() {+ window.location.reload();+ }}diff --git a/console/app/components/two-fa-enforcement-alert.js b/console/app/components/two-fa-enforcement-alert.jsindex da770626..f003746e 100644--- a/console/app/components/two-fa-enforcement-alert.js+++ b/console/app/components/two-fa-enforcement-alert.js@@ -34,6 +34,7 @@ export default class TwoFaEnforcementAlertComponent extends Component {* @inject*/@service fetch;+ @service notifications;/*** Constructor method for the ConsoleAccountAuthController.diff --git a/console/app/controllers/auth/two-fa.js b/console/app/controllers/auth/two-fa.jsindex a1893a86..c61ce73c 100644--- a/console/app/controllers/auth/two-fa.js+++ b/console/app/controllers/auth/two-fa.js@@ -250,7 +250,11 @@ export default class AuthTwoFaController extends Controller {const parts = decodedString.split('|');const expiresAt = this.convertUtcToClientTime(parts[0]);- if (expiresAt instanceof Date) {+ // convertUtcToClientTime always hands back a Date, so an `instanceof Date`+ // check could never fail: an unparseable stamp produced an Invalid Date that+ // reached twoFactorSessionExpiresAfter and rendered the countdown as NaN.+ // Only a usable date is an expiry; anything else falls through to null.+ if (!Number.isNaN(expiresAt.getTime())) {return expiresAt;}}diff --git a/console/app/controllers/auth/verification.js b/console/app/controllers/auth/verification.jsindex 89a0671c..166b309d 100644--- a/console/app/controllers/auth/verification.js+++ b/console/app/controllers/auth/verification.js@@ -27,13 +27,7 @@ export default class AuthVerificationController extends Controller {constructor() {super(...arguments);- this.stillWaitingTimer = later(- this,- () => {- this.stillWaiting = true;- },- this.waitTimeout- );+ this.stillWaitingTimer = later(this, this.markStillWaiting, this.waitTimeout);}willDestroy() {@@ -46,6 +40,15 @@ export default class AuthVerificationController extends Controller {}}+ /**+ * Shows the "still waiting?" prompt once the code has taken too long to arrive.+ * Extracted from the constructor's timer so it can be exercised without waiting out+ * the full timeout.+ */+ markStillWaiting() {+ this.stillWaiting = true;+ }+@action onDidntReceiveCode() {this.stillWaiting = true;}diff --git a/console/app/controllers/console/account/organizations.js b/console/app/controllers/console/account/organizations.jsindex 6844760c..4f3b2c30 100644--- a/console/app/controllers/console/account/organizations.js+++ b/console/app/controllers/console/account/organizations.js@@ -91,13 +91,7 @@ export default class ConsoleAccountOrganizationsController extends Controller {await this.fetch.post('auth/switch-organization', { next: organization.uuid });this.fetch.flushRequestCache('auth/organizations');this.notifications.success(this.intl.t('console.switch-organization.success-notification'));- return later(- this,- () => {- window.location.reload();- },- 900- );+ return later(this, this.reloadWindow, 900);} catch (error) {modal.stopLoading();return this.notifications.serverError(error);@@ -200,4 +194,14 @@ export default class ConsoleAccountOrganizationsController extends Controller {},});}++ /**+ * window.location.reload() cannot be stubbed — Location members are non-configurable+ * per spec — so it is isolated here and callers are tested by replacing this method.+ * Matches InstallationService, ConsoleController and the organizations controllers.+ */+ /* istanbul ignore next -- window.location.reload() cannot be stubbed */+ reloadWindow() {+ window.location.reload();+ }}diff --git a/console/app/controllers/console/admin/organizations/details/users.js b/console/app/controllers/console/admin/organizations/details/users.jsindex 82517ab8..6cc7af8f 100644--- a/console/app/controllers/console/admin/organizations/details/users.js+++ b/console/app/controllers/console/admin/organizations/details/users.js@@ -134,13 +134,7 @@ export default class ConsoleAdminOrganizationsDetailsUsersController extends Conawait this.router.transitionTo('console');this.session.manuallyAuthenticate(token);this.notifications.info(`Now impersonating ${user.email}...`);- later(- this,- () => {- window.location.reload();- },- 600- );+ later(this, this.reloadWindow, 600);} catch (error) {this.notifications.serverError(error);}@@ -236,4 +230,14 @@ export default class ConsoleAdminOrganizationsDetailsUsersController extends ConuserIdentifier(user) {return user?.uuid || user?.id;}++ /**+ * window.location.reload() cannot be stubbed — Location members are non-configurable+ * per spec — so it is isolated here and callers are tested by replacing this method.+ * Matches InstallationService, ConsoleController and the organizations controllers.+ */+ /* istanbul ignore next -- window.location.reload() cannot be stubbed */+ reloadWindow() {+ window.location.reload();+ }}diff --git a/console/app/controllers/console/admin/organizations/index/users.js b/console/app/controllers/console/admin/organizations/index/users.jsindex d1830aa5..1280fdbc 100644--- a/console/app/controllers/console/admin/organizations/index/users.js+++ b/console/app/controllers/console/admin/organizations/index/users.js@@ -133,13 +133,7 @@ export default class ConsoleAdminOrganizationsIndexUsersController extends Contr// Handed back so the caller can cancel the pending reload; the same timer on// ImpersonatorTray was unreachable once scheduled.- return later(- this,- () => {- window.location.reload();- },- 600- );+ return later(this, this.reloadWindow, 600);} catch (error) {this.notifications.serverError(error);}@@ -191,4 +185,14 @@ export default class ConsoleAdminOrganizationsIndexUsersController extends Contrreturn this.router.transitionTo('console.admin.organizations.index');}++ /**+ * window.location.reload() cannot be stubbed — Location members are non-configurable+ * per spec — so it is isolated here and callers are tested by replacing this method.+ * Matches InstallationService, ConsoleController and the organizations controllers.+ */+ /* istanbul ignore next -- window.location.reload() cannot be stubbed */+ reloadWindow() {+ window.location.reload();+ }}diff --git a/console/app/initializers/load-runtime-config.js b/console/app/initializers/load-runtime-config.jsindex 89f1b5a8..45b4be25 100644--- a/console/app/initializers/load-runtime-config.js+++ b/console/app/initializers/load-runtime-config.js@@ -24,6 +24,8 @@ export function initialize(application) {const endTime = performance.now();debug(`[Runtime Config] Runtime config loaded in ${(endTime - startTime).toFixed(2)}ms`);application.advanceReadiness();+ /* istanbul ignore next -- loadRuntimeConfig catches every failure internally, so+ this outer guard cannot fire; it exists only in case that ever stops being true */} catch (error) {console.error('[Runtime Config] Failed to load runtime config:', error);// Still advance readiness to prevent hangingdiff --git a/console/app/instance-initializers/apply-router-fix.js b/console/app/instance-initializers/apply-router-fix.jsindex c8121ac2..e0cc8237 100644--- a/console/app/instance-initializers/apply-router-fix.js+++ b/console/app/instance-initializers/apply-router-fix.js@@ -25,6 +25,8 @@ export function initialize(appInstance) {const endTime = performance.now();debug(`[Initializing Router Patch] Router fix applied in ${(endTime - startTime).toFixed(2)}ms`);+ /* istanbul ignore next -- applyRouterFix catches every failure internally, so this+ outer guard cannot fire; it exists only in case that ever stops being true */} catch (error) {console.error('[Initializing Router Patch] Failed to apply router fix:', error);}diff --git a/console/app/serializers/category.js b/console/app/serializers/category.jsindex 61399f9b..ae8d7b20 100644--- a/console/app/serializers/category.js+++ b/console/app/serializers/category.js@@ -28,6 +28,10 @@ export default class CategorySerializer extends ApplicationSerializer.extend(EmbserializeHasMany(snapshot, json, relationship) {let key = relationship.key;+ // CategoryModel declares no hasMany other than subcategories, so serializeHasMany is only+ // ever called with that key; the delegating arm is unreachable until another+ // relationship is added, which is exactly when it would start to matter.+ /* istanbul ignore else -- subcategories is this model's only hasMany */if (key === 'subcategories') {return;}diff --git a/console/app/serializers/comment.js b/console/app/serializers/comment.jsindex 5f67888a..72c2df03 100644--- a/console/app/serializers/comment.js+++ b/console/app/serializers/comment.js@@ -29,6 +29,10 @@ export default class CommentSerializer extends ApplicationSerializer.extend(EmbeserializeHasMany(snapshot, json, relationship) {let key = relationship.key;+ // CommentModel declares no hasMany other than replies, so serializeHasMany is only+ // ever called with that key; the delegating arm is unreachable until another+ // relationship is added, which is exactly when it would start to matter.+ /* istanbul ignore else -- replies is this model's only hasMany */if (key === 'replies') {return;} else {diff --git a/console/app/serializers/dashboard.js b/console/app/serializers/dashboard.jsindex 7a2f908f..cc8ca993 100644--- a/console/app/serializers/dashboard.js+++ b/console/app/serializers/dashboard.js@@ -9,6 +9,10 @@ export default class DashboardSerializer extends ApplicationSerializer.extend(EmserializeHasMany(snapshot, json, relationship) {let key = relationship.key;+ // DashboardModel declares no hasMany other than widgets, so serializeHasMany is only+ // ever called with that key; the delegating arm is unreachable until another+ // relationship is added, which is exactly when it would start to matter.+ /* istanbul ignore else -- widgets is this model's only hasMany */if (key === 'widgets') {return;}diff --git a/console/tests/integration/components/admin/widget/kpi-tile-test.js b/console/tests/integration/components/admin/widget/kpi-tile-test.jsindex a5c3c1f0..5e148b2b 100644--- a/console/tests/integration/components/admin/widget/kpi-tile-test.js+++ b/console/tests/integration/components/admin/widget/kpi-tile-test.js@@ -137,3 +137,26 @@ module('Integration | Component | admin/widget/kpi-tile', function (hooks) {assert.ok(this.tile().innerHTML.includes('rose'), 'errors render in red');});});++module('Integration | Component | admin/widget/kpi-tile | unformattable values', function (hooks) {+ setupRenderingTest(hooks);++ test('a value that cannot format itself is shown as it came back', async function (assert) {+ // A payload value with no prototype has no toLocaleString; the tile must render+ // what it was given rather than "undefined".+ const raw = Object.create(null);+ raw.toString = () => 'RAW';++ class FetchStub extends Service {+ get() {+ return Promise.resolve({ value: raw, delta_pct: null, status: 'neutral' });+ }+ }+ this.owner.register('service:fetch', FetchStub);+ this.set('options', { slug: 'users-total', title: 'Users' });++ await render(hbs`<Admin::Widget::KpiTile @options={{this.options}} />`);++ assert.dom('.admin-kpi-tile').containsText('RAW', 'the raw value is passed straight through');+ });+});diff --git a/console/tests/integration/components/configure/filesystem-test.js b/console/tests/integration/components/configure/filesystem-test.jsindex d768ec13..8260062c 100644--- a/console/tests/integration/components/configure/filesystem-test.js+++ b/console/tests/integration/components/configure/filesystem-test.js@@ -3,8 +3,8 @@ import { setupRenderingTest } from '@fleetbase/console/tests/helpers';import { render, click } from '@ember/test-helpers';import { hbs } from 'ember-cli-htmlbars';import Service from '@ember/service';-import ConfigureFilesystemComponent from '@fleetbase/console/components/configure/filesystem';import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';+import ConfigureFilesystemComponent from '@fleetbase/console/components/configure/filesystem';/*** Lets the fire-and-forget promise chains the component kicks off in its constructor and@@ -216,3 +216,30 @@ module('Integration | Component | configure/filesystem', function (hooks) {assert.strictEqual(component.gcsCredentialsFile, undefined);});});++module('Integration | Component | configure/filesystem | defaults', function (hooks) {+ setupRenderingTest(hooks);++ test('a server that reports no disks leaves the picker empty rather than undefined', async function (assert) {+ class FetchStub extends Service {+ async get() {+ return { driver: 'local' };+ }+ async post() {+ return {};+ }+ }+ class NotificationsStub extends Service {+ success() {}+ serverError() {}+ }+ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:notifications', NotificationsStub);++ const captured = captureComponent(this.owner, 'configure/filesystem', ConfigureFilesystemComponent);+ await render(hbs`<div id="next-view-section-subheader-actions"></div><Configure::Filesystem />`);++ assert.deepEqual(captured.instance.disks, [], 'the disk list defaults to empty');+ assert.strictEqual(captured.instance.driver, 'local');+ });+});diff --git a/console/tests/integration/components/configure/notification-channels-test.js b/console/tests/integration/components/configure/notification-channels-test.jsindex 3f403184..0b00fc21 100644--- a/console/tests/integration/components/configure/notification-channels-test.js+++ b/console/tests/integration/components/configure/notification-channels-test.js@@ -3,8 +3,8 @@ import { setupRenderingTest } from '@fleetbase/console/tests/helpers';import { render, click } from '@ember/test-helpers';import { hbs } from 'ember-cli-htmlbars';import Service from '@ember/service';-import ConfigureNotificationChannelsComponent from '@fleetbase/console/components/configure/notification-channels';import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';+import ConfigureNotificationChannelsComponent from '@fleetbase/console/components/configure/notification-channels';/*** Lets the fire-and-forget promise chains the component starts run to completion. They are@@ -259,3 +259,30 @@ module('Integration | Component | configure/notification-channels', function (hoassert.false(component.isLoading);});});++module('Integration | Component | configure/notification-channels | defaults', function (hooks) {+ setupRenderingTest(hooks);++ test('the test push notification is pre-filled so an admin can send one straight away', async function (assert) {+ class FetchStub extends Service {+ async get() {+ return {};+ }+ async post() {+ return {};+ }+ }+ class NotificationsStub extends Service {+ success() {}+ serverError() {}+ }+ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:notifications', NotificationsStub);++ const captured = captureComponent(this.owner, 'configure/notification-channels', ConfigureNotificationChannelsComponent);+ await render(hbs`<div id="next-view-section-subheader-actions"></div><Configure::NotificationChannels />`);++ assert.strictEqual(captured.instance.testTitle, 'Hello World from Fleetbase 🚀');+ assert.strictEqual(captured.instance.testMessage, 'This is a test push notification!');+ });+});diff --git a/console/tests/integration/components/configure/queue-test.js b/console/tests/integration/components/configure/queue-test.jsindex 93cbfa9f..a8961ed2 100644--- a/console/tests/integration/components/configure/queue-test.js+++ b/console/tests/integration/components/configure/queue-test.js@@ -3,8 +3,8 @@ import { setupRenderingTest } from '@fleetbase/console/tests/helpers';import { render, click } from '@ember/test-helpers';import { hbs } from 'ember-cli-htmlbars';import Service from '@ember/service';-import ConfigureQueueComponent from '@fleetbase/console/components/configure/queue';import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';+import ConfigureQueueComponent from '@fleetbase/console/components/configure/queue';/*** Lets the fire-and-forget promise chains the component starts run to completion. They are@@ -148,3 +148,31 @@ module('Integration | Component | configure/queue', function (hooks) {assert.false(component.isLoading);});});++module('Integration | Component | configure/queue | defaults', function (hooks) {+ setupRenderingTest(hooks);++ test('a server that reports no connections leaves the picker empty rather than undefined', async function (assert) {+ class FetchStub extends Service {+ async get() {+ return { driver: 'sync' };+ }+ async post() {+ return {};+ }+ }+ class NotificationsStub extends Service {+ success() {}+ serverError() {}+ }+ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:notifications', NotificationsStub);++ const captured = captureComponent(this.owner, 'configure/queue', ConfigureQueueComponent);+ await render(hbs`<div id="next-view-section-subheader-actions"></div><Configure::Queue />`);++ assert.deepEqual(captured.instance.connections, [], 'the connection list defaults to empty');+ assert.strictEqual(captured.instance.beanstalkdHost, 'localhost', 'and the shipped beanstalkd defaults survive');+ assert.strictEqual(captured.instance.beanstalkdQueue, 'default');+ });+});diff --git a/console/tests/integration/components/configure/services-test.js b/console/tests/integration/components/configure/services-test.jsindex 6b44c598..1330d948 100644--- a/console/tests/integration/components/configure/services-test.js+++ b/console/tests/integration/components/configure/services-test.js@@ -646,4 +646,15 @@ module('Integration | Component | configure/services | sparse sms config', functassert.strictEqual(component.customHttpBodyText, JSON.stringify({ to: '{{to}}', text: '{{text}}', from: '{{from}}' }, null, 2), 'a missing body falls back to the templated default');assert.strictEqual(component.smsSelectedProvider, 'custom_http', 'the saved provider is the one shown');});++ test('headers and query params fall back independently of one another', async function (assert) {+ this.getResponse = {+ sms: { providers: { custom_http: { method: 'POST', headers: { 'X-Tenant': 'acme' } } } },+ };++ const component = await this.build();++ assert.strictEqual(component.customHttpHeadersText, JSON.stringify({ 'X-Tenant': 'acme' }, null, 2), 'saved headers are shown as written');+ assert.strictEqual(component.customHttpQueryParamsText, '{}', 'while the absent query params still default');+ });});diff --git a/console/tests/integration/components/impersonator-tray-test.js b/console/tests/integration/components/impersonator-tray-test.jsindex 8aebbed1..b58689a0 100644--- a/console/tests/integration/components/impersonator-tray-test.js+++ b/console/tests/integration/components/impersonator-tray-test.js@@ -1,6 +1,6 @@import { module, test } from 'qunit';import { setupRenderingTest } from '@fleetbase/console/tests/helpers';-import { render } from '@ember/test-helpers';+import { render, settled } from '@ember/test-helpers';import { hbs } from 'ember-cli-htmlbars';import Service from '@ember/service';import { cancel } from '@ember/runloop';@@ -147,3 +147,61 @@ module('Integration | Component | impersonator-tray | restoreSession', functionassert.deepEqual(this.transitions, [], 'the user stays where they are');});});++module('Integration | Component | impersonator-tray | reload', function (hooks) {+ setupRenderingTest(hooks);++ hooks.beforeEach(function () {+ this.owner.lookup('service:intl').setLocale('en-us');++ class FetchStub extends Service {+ async delete() {+ return { token: 'restored-token' };+ }+ }+ class NotificationsStub extends Service {+ infos = [];+ info(message) {+ this.infos.push(message);+ }+ serverError() {}+ }++ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:notifications', NotificationsStub);++ const captured = captureComponent(this.owner, 'impersonator-tray', ImpersonatorTrayComponent);+ this.build = async () => {+ await render(hbs`+ <div id="view-header-actions"></div>+ <ImpersonatorTray />+ `);+ const component = captured.instance;++ this.authenticated = [];+ Object.defineProperty(component.session, 'manuallyAuthenticate', {+ configurable: true,+ value: (token) => this.authenticated.push(token),+ });+ Object.defineProperty(component.router, 'transitionTo', { configurable: true, value: () => Promise.resolve() });++ this.reloads = 0;+ Object.defineProperty(component, 'reloadWindow', { configurable: true, value: () => this.reloads++ });++ return component;+ };+ });++ test('restoring the session re-authenticates and reloads once the timer fires', async function (assert) {+ const component = await this.build();++ await component.restoreSession();++ assert.deepEqual(this.authenticated, ['restored-token']);+ assert.deepEqual(this.owner.lookup('service:notifications').infos, ['Ending impersonation session.']);+ assert.strictEqual(this.reloads, 0, 'the reload is deferred so the notification is readable');++ await settled();+ assert.strictEqual(this.reloads, 1, 'and lands when the timer fires');+ });+});diff --git a/console/tests/integration/components/onboarding/yield-test.js b/console/tests/integration/components/onboarding/yield-test.jsindex e18fe0e3..974c4217 100644--- a/console/tests/integration/components/onboarding/yield-test.js+++ b/console/tests/integration/components/onboarding/yield-test.js@@ -2,6 +2,10 @@ import { module, test } from 'qunit';import { setupRenderingTest } from '@fleetbase/console/tests/helpers';import { render } from '@ember/test-helpers';import { hbs } from 'ember-cli-htmlbars';+import Component from '@glimmer/component';+import { setComponentTemplate } from '@ember/component';+import OnboardingYieldComponent from '@fleetbase/console/components/onboarding/yield';+import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';module('Integration | Component | onboarding/yield', function (hooks) {setupRenderingTest(hooks);@@ -41,3 +45,40 @@ module('Integration | Component | onboarding/yield', function (hooks) {assert.strictEqual(context.get('code'), '123456', 'the code is stored');});});++module('Integration | Component | onboarding/yield | current step', function (hooks) {+ setupRenderingTest(hooks);++ hooks.beforeEach(function () {+ // A stand-in for whatever step an onboarding flow registers. The real step+ // components pull in the verification service, which schedules a 75-second timer+ // that would hold settled() open for the whole test timeout.+ this.owner.register('component:test-onboarding-step', setComponentTemplate(hbs`<div class="test-onboarding-step"></div>`, class extends Component {}));+ });++ test('the component of the orchestrator current step is what gets rendered', async function (assert) {+ const orchestrator = this.owner.lookup('service:onboarding-orchestrator');+ Object.defineProperty(orchestrator, 'goto', { configurable: true, value: () => Promise.resolve() });+ Object.defineProperty(orchestrator, 'current', {+ configurable: true,+ value: { id: 'verify-email', component: 'test-onboarding-step' },+ });++ const captured = captureComponent(this.owner, 'onboarding/yield', OnboardingYieldComponent);+ await render(hbs`<Onboarding::Yield @step="verify-email" />`);++ assert.strictEqual(captured.instance.currentComponent, 'test-onboarding-step');+ assert.dom('.test-onboarding-step').exists('and it is what the step host renders');+ });++ test('there is nothing to render before the orchestrator has a current step', async function (assert) {+ const orchestrator = this.owner.lookup('service:onboarding-orchestrator');+ Object.defineProperty(orchestrator, 'goto', { configurable: true, value: () => Promise.resolve() });+ Object.defineProperty(orchestrator, 'current', { configurable: true, value: null });++ const captured = captureComponent(this.owner, 'onboarding/yield', OnboardingYieldComponent);+ await render(hbs`<Onboarding::Yield />`);++ assert.strictEqual(captured.instance.currentComponent, null);+ });+});diff --git a/console/tests/integration/components/two-fa-enforcement-alert-test.js b/console/tests/integration/components/two-fa-enforcement-alert-test.jsindex c4ef3706..f45f9a20 100644--- a/console/tests/integration/components/two-fa-enforcement-alert-test.js+++ b/console/tests/integration/components/two-fa-enforcement-alert-test.js@@ -66,3 +66,31 @@ module('Integration | Component | two-fa-enforcement-alert', function (hooks) {assert.strictEqual(transitionedTo, 'console.account.auth');});});++module('Integration | Component | two-fa-enforcement-alert | failure', function (hooks) {+ setupRenderingTest(hooks);++ test('an enforcement check that fails is reported and the alert stays hidden', async function (assert) {+ const failure = new Error('enforcement endpoint unavailable');+ const serverErrors = [];++ class FetchStub extends Service {+ get() {+ return Promise.reject(failure);+ }+ }+ class NotificationsStub extends Service {+ serverError(error) {+ serverErrors.push(error);+ }+ }++ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:notifications', NotificationsStub);++ await render(hbs`<TwoFaEnforcementAlert />`);++ assert.deepEqual(serverErrors, [failure]);+ assert.dom('.two-fa-enforcement-alert').doesNotExist('nothing is demanded of the user when the check could not run');+ });+});diff --git a/console/tests/unit/controllers/auth/two-fa-test.js b/console/tests/unit/controllers/auth/two-fa-test.jsindex 5ae6b85c..2437c753 100644--- a/console/tests/unit/controllers/auth/two-fa-test.js+++ b/console/tests/unit/controllers/auth/two-fa-test.js@@ -222,3 +222,31 @@ module('Unit | Controller | auth/two-fa | verification flow', function (hooks) {assert.strictEqual(converted.getTime(), new Date(utc).getTime() - new Date().getTimezoneOffset() * 60 * 1000);});});++module('Unit | Controller | auth/two-fa | client token expiry', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ this.controller = this.owner.lookup('controller:auth/two-fa');+ // The token is base64 of "<expiry>|<identifier>".+ this.token = (contents) => window.btoa(contents);+ });++ test('a token carrying a parseable expiry yields that date', function (assert) {+ const expiry = this.controller.getExpirationDateFromClientToken(this.token('2026-05-06 14:30:00|session-1'));++ assert.true(expiry instanceof Date, 'the expiry is handed back as a Date');+ });++ test('a token whose expiry cannot be read yields no expiry', function (assert) {+ assert.strictEqual(+ this.controller.getExpirationDateFromClientToken(this.token('not-a-timestamp|session-1')),+ null,+ 'an unparseable stamp is treated as no expiry rather than an invalid Date'+ );+ });++ test('a token with no separator yields no expiry', function (assert) {+ assert.strictEqual(this.controller.getExpirationDateFromClientToken(this.token('sessiononly')), null);+ });+});diff --git a/console/tests/unit/controllers/auth/verification-test.js b/console/tests/unit/controllers/auth/verification-test.jsindex 175a88bb..e2391b82 100644--- a/console/tests/unit/controllers/auth/verification-test.js+++ b/console/tests/unit/controllers/auth/verification-test.js@@ -1,6 +1,7 @@import { module, test } from 'qunit';import { setupTest } from '@fleetbase/console/tests/helpers';import Service from '@ember/service';+import { cancel } from '@ember/runloop';module('Unit | Controller | auth/verification', function (hooks) {setupTest(hooks);@@ -314,10 +315,38 @@ module('Unit | Controller | auth/verification | resend and verify', function (hotest('willDestroy cancels the still-waiting timer', function (assert) {const controller = this.build();- assert.ok(controller.stillWaitingTimer, 'a timer was scheduled on construction');+ assert.notStrictEqual(controller.stillWaitingTimer, undefined, 'a timer was scheduled on construction');controller.willDestroy();assert.false(controller.stillWaiting, 'the timer never fired, so the flag is untouched');});});++module('Unit | Controller | auth/verification | still-waiting timer', function (hooks) {+ setupTest(hooks);++ test('the wait timer shows the "still waiting" prompt when it fires', function (assert) {+ // Looked up without settling: the constructor schedules this for waitTimeout ms,+ // which is far longer than a test may run, so the callback is driven directly.+ const controller = this.owner.lookup('controller:auth/verification');++ assert.false(controller.stillWaiting, 'nothing is shown while the code is still expected');++ controller.markStillWaiting();++ assert.true(controller.stillWaiting, 'the prompt appears once the code is overdue');+ });++ test('teardown with no pending timer is a no-op', function (assert) {+ const controller = this.owner.lookup('controller:auth/verification');+ // Cancel the real timer before clearing the handle: with nothing left to cancel,+ // teardown's settled() would otherwise wait out the whole waitTimeout.+ cancel(controller.stillWaitingTimer);+ controller.stillWaitingTimer = null;++ controller.willDestroy();++ assert.strictEqual(controller.stillWaitingTimer, null, 'there is nothing to cancel and nothing throws');+ });+});diff --git a/console/tests/unit/controllers/console/account/organizations-test.js b/console/tests/unit/controllers/console/account/organizations-test.jsindex b71d8ce1..bac4c747 100644--- a/console/tests/unit/controllers/console/account/organizations-test.js+++ b/console/tests/unit/controllers/console/account/organizations-test.js@@ -2,6 +2,7 @@ import { module, test } from 'qunit';import { setupTest } from '@fleetbase/console/tests/helpers';import Service from '@ember/service';import { cancel } from '@ember/runloop';+import { settled } from '@ember/test-helpers';// Captures whatever the controller hands to the modals manager so the modal's// `confirm` callback can be driven directly.@@ -425,3 +426,63 @@ module('Unit | Controller | console/account/organizations | failures', functionassert.strictEqual(this.refreshed, 0);});});++module('Unit | Controller | console/account/organizations | reload and stale counts', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ this.owner.register('service:modals-manager', ModalsManagerStub);+ this.owner.register('service:notifications', NotificationsStub);+ this.owner.register('service:intl', IntlStub);++ this.posted = [];+ const posted = this.posted;+ class FetchStub extends Service {+ post(path, payload) {+ posted.push({ path, payload });+ return Promise.resolve({});+ }+ flushRequestCache(path) {+ posted.push({ flushed: path });+ }+ }+ this.owner.register('service:fetch', FetchStub);++ this.controller = this.owner.lookup('controller:console/account/organizations');+ this.modals = this.owner.lookup('service:modals-manager');+ this.controller.currentUser.userSnapshot = { id: 'user_1' };+ this.controller.model = [organization(), organization({ uuid: 'org_2' })];++ this.refreshed = 0;+ this.controller.router.refresh = () => this.refreshed++;++ this.reloads = 0;+ Object.defineProperty(this.controller, 'reloadWindow', { configurable: true, value: () => this.reloads++ });+ });++ test('switching organizations reloads the console once the timer fires', async function (assert) {+ this.controller.switchOrganization(organization());++ await this.modals.lastOptions.confirm(fakeModal());+ assert.strictEqual(this.reloads, 0, 'the reload is deferred so the success notice is readable');++ await settled();+ assert.strictEqual(this.reloads, 1, 'the whole console is reloaded under the new organization');+ });++ test('an owner whose organization reports no members at all just leaves it', async function (assert) {+ // users_count is server-supplied and can be missing or zero on a stale record, so+ // neither the transfer nor the delete flow applies — leaving is the safe fallback.+ const org = organization({ owner_uuid: 'user_1', users_count: 0 });+ this.controller.leaveOrganization(org);++ await this.modals.lastOptions.confirm(fakeModal());++ assert.deepEqual(+ org.calls.map((call) => call[0]),+ ['leave'],+ 'the organization is neither transferred nor deleted'+ );+ assert.strictEqual(this.refreshed, 1);+ });+});diff --git a/console/tests/unit/controllers/console/admin/organizations/details/extensions-tab-test.js b/console/tests/unit/controllers/console/admin/organizations/details/extensions-tab-test.jsnew file mode 100644index 00000000..a4a43b14--- /dev/null+++ b/console/tests/unit/controllers/console/admin/organizations/details/extensions-tab-test.js@@ -0,0 +1,57 @@+import { module, test } from 'qunit';+import { setupTest } from '@fleetbase/console/tests/helpers';++/**+ * The extensions tab is a thin shell: it looks its own definition up in the tab registry by+ * slug and hands extension components the context they are documented to receive.+ */+module('Unit | Controller | console/admin/organizations/details/extensions-tab', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ this.controller = this.owner.lookup('controller:console/admin/organizations/details/extensions-tab');++ this.registered = [];+ Object.defineProperty(this.controller.menuService, 'getMenuItems', {+ configurable: true,+ value: () => this.registered,+ });+ });++ test('tab finds the registered definition matching the current slug', function (assert) {+ const billing = { slug: 'billing', component: 'billing/tab', label: 'Billing' };+ this.registered = [{ slug: 'audit', component: 'audit/tab' }, billing];+ this.controller.slug = 'billing';++ assert.strictEqual(this.controller.tab, billing);+ });++ test('a slug nothing has registered resolves to no tab', function (assert) {+ this.registered = [{ slug: 'audit', component: 'audit/tab' }];+ this.controller.slug = 'billing';++ assert.strictEqual(this.controller.tab, undefined, 'the template renders nothing rather than throwing');+ });++ test('context carries the organization and the signed-in user', function (assert) {+ const organization = { uuid: 'org_1', name: 'Acme' };+ this.controller.organization = organization;+ Object.defineProperty(this.controller.session, 'data', {+ configurable: true,+ value: { authenticated: { user: { id: 'user_1' } } },+ });++ assert.deepEqual(this.controller.context, {+ organization,+ currentUser: { id: 'user_1' },+ capabilities: {},+ });+ });++ test('an unauthenticated session yields no current user rather than throwing', function (assert) {+ Object.defineProperty(this.controller.session, 'data', { configurable: true, value: {} });++ assert.strictEqual(this.controller.context.currentUser, undefined);+ assert.deepEqual(this.controller.context.capabilities, {});+ });+});diff --git a/console/tests/unit/controllers/console/admin/organizations/details/users-test.js b/console/tests/unit/controllers/console/admin/organizations/details/users-test.jsindex ccab0bcd..00383118 100644--- a/console/tests/unit/controllers/console/admin/organizations/details/users-test.js+++ b/console/tests/unit/controllers/console/admin/organizations/details/users-test.js@@ -1,6 +1,7 @@import { module, test } from 'qunit';import { setupTest } from '@fleetbase/console/tests/helpers';import Service from '@ember/service';+import { settled } from '@ember/test-helpers';class IntlStub extends Service {t(key) {@@ -262,3 +263,62 @@ module('Unit | Controller | console/admin/organizations/details/users', functionassert.strictEqual(actions.find((a) => a.label === 'Remove from Organization').fn, this.controller.removeUser);});});++module('Unit | Controller | console/admin/organizations/details/users | impersonation', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ const context = this;++ class FetchStub extends Service {+ post(path, payload) {+ context.posted = { path, payload };+ return Promise.resolve({ token: 'imp-token' });+ }+ }+ class NotificationsStub extends Service {+ infos = [];+ info(message) {+ this.infos.push(message);+ }+ serverError() {}+ }+ class SessionStub extends Service {+ data = { authenticated: { user: { id: 'me' } } };+ authenticated = [];+ manuallyAuthenticate(token) {+ this.authenticated.push(token);+ }+ }++ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:notifications', NotificationsStub);+ this.owner.register('service:session', SessionStub);++ this.controller = this.owner.lookup('controller:console/admin/organizations/details/users');+ Object.defineProperty(this.controller.router, 'transitionTo', { configurable: true, value: () => Promise.resolve() });++ this.reloads = 0;+ Object.defineProperty(this.controller, 'reloadWindow', { configurable: true, value: () => this.reloads++ });+ });++ test('impersonating a user swaps the session and reloads once the timer fires', async function (assert) {+ await this.controller.impersonateUser({ id: 'user_9', email: '[email protected]' });++ assert.deepEqual(this.posted, { path: 'auth/impersonate', payload: { user: 'user_9' } });+ assert.deepEqual(this.owner.lookup('service:session').authenticated, ['imp-token']);+ assert.deepEqual(this.owner.lookup('service:notifications').infos, ['Now impersonating [email protected]...']);+ assert.strictEqual(this.reloads, 0, 'the reload is deferred');++ await settled();+ assert.strictEqual(this.reloads, 1);+ });++ test('the nested user table starts on its first page with no query', function (assert) {+ const controller = this.owner.lookup('controller:console/admin/organizations/details/users');++ assert.strictEqual(controller.nestedPage, 1);+ assert.strictEqual(controller.nestedLimit, 20);+ assert.strictEqual(controller.nestedQuery, '');+ });+});diff --git a/console/tests/unit/controllers/console/admin/organizations/index-test.js b/console/tests/unit/controllers/console/admin/organizations/index-test.jsindex 9e0632f6..e9d0b7d2 100644--- a/console/tests/unit/controllers/console/admin/organizations/index-test.js+++ b/console/tests/unit/controllers/console/admin/organizations/index-test.js@@ -523,3 +523,67 @@ module('Unit | Controller | console/admin/organizations/index | actions', functiassert.deepEqual(written, ['company_1', 'uuid-1']);});});++module('Unit | Controller | console/admin/organizations/index | saved views', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ this.owner.register('service:intl', IntlStub);+ this.owner.register('service:notifications', NotificationsStub);+ this.controller = this.owner.lookup('controller:console/admin/organizations/index');+ this.viewItems = () => this.controller.actionButtons[0].items.filter((item) => !item.separator);+ });++ test('the table starts on its first page, twenty at a time, newest first', function (assert) {+ assert.strictEqual(this.controller.page, 1);+ assert.strictEqual(this.controller.limit, 20);+ assert.strictEqual(this.controller.sort, '-created_at');+ assert.deepEqual(this.controller.companies, [], 'nothing is listed before the model loads');+ });++ test('each saved view in the Views menu applies its own filter', function (assert) {+ const expected = [+ { label: 'Needs Attention', filter: 'needs_attention', value: 1 },+ { label: 'Missing Owner', filter: 'missing_owner', value: 1 },+ { label: 'Incomplete Onboarding', filter: 'onboarding_completed', value: false },+ { label: 'Inactive Status', filter: 'inactive_status', value: 1 },+ ];++ expected.forEach(({ label, filter, value }) => {+ this.controller.page = 4;+ const item = this.viewItems().find((entry) => entry.label === label);++ item.onClick();++ assert.strictEqual(this.controller[filter], value, `${label} sets ${filter}`);+ assert.strictEqual(this.controller.page, 1, `${label} returns to the first page`);+ });+ });++ test('applying one saved view clears the previous one', function (assert) {+ this.viewItems()+ .find((entry) => entry.label === 'Missing Owner')+ .onClick();+ this.viewItems()+ .find((entry) => entry.label === 'Inactive Status')+ .onClick();++ assert.strictEqual(this.controller.inactive_status, 1);+ assert.strictEqual(this.controller.missing_owner, null, 'the earlier filter is dropped rather than stacked');+ });++ test('Clear View drops every saved filter', function (assert) {+ this.viewItems()+ .find((entry) => entry.label === 'Needs Attention')+ .onClick();++ this.viewItems()+ .find((entry) => entry.label === 'Clear View')+ .onClick();++ assert.strictEqual(this.controller.needs_attention, null);+ assert.strictEqual(this.controller.missing_owner, null);+ assert.strictEqual(this.controller.inactive_status, null);+ assert.strictEqual(this.controller.onboarding_completed, null);+ });+});diff --git a/console/tests/unit/controllers/console/admin/organizations/index/users-test.js b/console/tests/unit/controllers/console/admin/organizations/index/users-test.jsindex 02d553a0..7169bc15 100644--- a/console/tests/unit/controllers/console/admin/organizations/index/users-test.js+++ b/console/tests/unit/controllers/console/admin/organizations/index/users-test.js@@ -1,6 +1,7 @@import { module, test } from 'qunit';import { setupTest } from '@fleetbase/console/tests/helpers';import Service from '@ember/service';+import { settled } from '@ember/test-helpers';import { cancel } from '@ember/runloop';module('Unit | Controller | console/admin/organizations/index/users', function (hooks) {@@ -199,3 +200,63 @@ module('Unit | Controller | console/admin/organizations/index/users | actions',assert.strictEqual(actionsColumn.actions[1].fn, controller.changeUserPassword);});});++module('Unit | Controller | console/admin/organizations/index/users | impersonation', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ const context = this;++ class FetchStub extends Service {+ post(path, payload) {+ context.posted = { path, payload };+ return Promise.resolve({ token: 'imp-token' });+ }+ }+ class NotificationsStub extends Service {+ infos = [];+ info(message) {+ this.infos.push(message);+ }+ serverError() {}+ }+ class SessionStub extends Service {+ data = { authenticated: { user: { id: 'me' } } };+ authenticated = [];+ manuallyAuthenticate(token) {+ this.authenticated.push(token);+ }+ }++ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:notifications', NotificationsStub);+ this.owner.register('service:session', SessionStub);++ this.controller = this.owner.lookup('controller:console/admin/organizations/index/users');+ Object.defineProperty(this.controller.router, 'transitionTo', { configurable: true, value: () => Promise.resolve() });++ this.reloads = 0;+ Object.defineProperty(this.controller, 'reloadWindow', { configurable: true, value: () => this.reloads++ });+ });++ test('impersonating a user swaps the session and hands back a cancellable reload', async function (assert) {+ const timer = await this.controller.impersonateUser({ id: 'user_3', email: '[email protected]' });++ assert.deepEqual(this.posted, { path: 'auth/impersonate', payload: { user: 'user_3' } });+ assert.deepEqual(this.owner.lookup('service:session').authenticated, ['imp-token']);+ assert.deepEqual(this.owner.lookup('service:notifications').infos, ['Now impersonating [email protected]...']);+ assert.ok(timer, 'the pending reload is returned so a caller can cancel it');++ await settled();+ assert.strictEqual(this.reloads, 1);+ });++ test('the nested user table starts on its first page, newest first, with no query', function (assert) {+ const controller = this.owner.lookup('controller:console/admin/organizations/index/users');++ assert.strictEqual(controller.nestedPage, 1);+ assert.strictEqual(controller.nestedLimit, 20);+ assert.strictEqual(controller.nestedSort, '-created_at');+ assert.strictEqual(controller.nestedQuery, '');+ });+});diff --git a/console/tests/unit/controllers/console/settings/two-fa-test.js b/console/tests/unit/controllers/console/settings/two-fa-test.jsindex 58ca6e04..ddfcebd2 100644--- a/console/tests/unit/controllers/console/settings/two-fa-test.js+++ b/console/tests/unit/controllers/console/settings/two-fa-test.js@@ -136,3 +136,33 @@ module('Unit | Controller | console/settings/two-fa | loading and saving', functassert.deepEqual(this.notifications().successes, []);});});++module('Unit | Controller | console/settings/two-fa | defaults', function (hooks) {+ setupTest(hooks);++ test('saving the company 2FA settings with nothing supplied posts an empty object', async function (assert) {+ const posted = [];++ class FetchStub extends Service {+ get() {+ return Promise.resolve({ enabled: false });+ }+ post(path, payload) {+ posted.push({ path, payload });+ return Promise.resolve({ ok: true });+ }+ }+ class NotificationsStub extends Service {+ success() {}+ serverError() {}+ }++ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:notifications', NotificationsStub);++ const controller = this.owner.lookup('controller:console/settings/two-fa');+ await controller.saveTwoFactorSettingsForCompany.perform();++ assert.deepEqual(posted.at(-1).payload, { twoFaSettings: {} });+ });+});diff --git a/console/tests/unit/controllers/onboard/verify-email-test.js b/console/tests/unit/controllers/onboard/verify-email-test.jsindex 3d4935db..8fefce0b 100644--- a/console/tests/unit/controllers/onboard/verify-email-test.js+++ b/console/tests/unit/controllers/onboard/verify-email-test.js@@ -100,3 +100,39 @@ module('Unit | Controller | onboard/verify-email | failure', function (hooks) {assert.false(transitioned, 'the user stays on the verification screen');});});++module('Unit | Controller | onboard/verify-email | rejected codes', function (hooks) {+ setupTest(hooks);++ test('a status other than ok leaves the user on the form with nothing reported as verified', async function (assert) {+ const notified = [];++ class FetchStub extends Service {+ post() {+ return Promise.resolve({ status: 'invalid' });+ }+ }+ class NotificationsStub extends Service {+ success(message) {+ notified.push(message);+ }+ info(message) {+ notified.push(message);+ }+ serverError() {}+ }+ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:notifications', NotificationsStub);++ const controller = this.owner.lookup('controller:onboard/verify-email');+ controller.transitions = [];+ Object.defineProperty(controller.router, 'transitionTo', {+ configurable: true,+ value: (route) => controller.transitions.push(route),+ });++ assert.strictEqual(await controller.verifyCode.perform(), undefined, 'nothing is returned to act on');+ assert.deepEqual(notified, [], 'no success or welcome message');+ assert.deepEqual(controller.transitions, [], 'and no navigation');+ });+});diff --git a/console/tests/unit/controllers/tracked-defaults-test.js b/console/tests/unit/controllers/tracked-defaults-test.jsindex e9702669..8f2ce6d8 100644--- a/console/tests/unit/controllers/tracked-defaults-test.js+++ b/console/tests/unit/controllers/tracked-defaults-test.js@@ -33,6 +33,23 @@ const CONTROLLERS = [name: 'controller:console/settings/notifications',defaults: { notificationSettings: {}, notificationTransportMethods: ['email', 'sms'] },},+ {+ name: 'controller:console/admin/branding',+ defaults: { isLoading: false },+ },+ {+ // The virtual admin screen is pure layout: these classes are the whole controller.+ name: 'controller:console/admin/virtual',+ defaults: {+ bodyClass: 'overflow-y-scroll h-full',+ containerClass: 'container mx-auto h-screen',+ wrapperClass: 'max-w-3xl my-10 mx-auto',+ },+ },+ {+ name: 'controller:console/admin/schedule-monitor/logs',+ defaults: { logs: [] },+ },];module('Unit | Controller | tracked defaults', function (hooks) {diff --git a/console/tests/unit/models/company-test.js b/console/tests/unit/models/company-test.jsindex b9f9db47..c98c1985 100644--- a/console/tests/unit/models/company-test.js+++ b/console/tests/unit/models/company-test.js@@ -98,3 +98,32 @@ module('Unit | Model | company', function (hooks) {assert.deepEqual(company.get('users'), []);});});++module('Unit | Model | company | ownership transfer defaults', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ const context = this;++ class FetchStub extends Service {+ post(path, payload) {+ context.posted = { path, payload };+ return Promise.resolve({ status: 'ok' });+ }+ }+ this.owner.register('service:fetch', FetchStub);+ this.company = this.owner.lookup('service:store').push({ data: { id: 'co_1', type: 'company', attributes: { name: 'Acme' } } });+ });++ test('transferring ownership without extra parameters posts just the company and new owner', async function (assert) {+ await this.company.transferOwnership('user_2');++ assert.deepEqual(this.posted, { path: 'companies/transfer-ownership', payload: { company: 'co_1', newOwner: 'user_2' } });+ });++ test('extra parameters are merged into the transfer payload', async function (assert) {+ await this.company.transferOwnership('user_2', { leave: true });++ assert.deepEqual(this.posted.payload, { company: 'co_1', newOwner: 'user_2', leave: true });+ });+});diff --git a/console/tests/unit/models/dashboard-test.js b/console/tests/unit/models/dashboard-test.jsindex 233cf996..ebc589bd 100644--- a/console/tests/unit/models/dashboard-test.js+++ b/console/tests/unit/models/dashboard-test.js@@ -1,5 +1,7 @@import { module, test } from 'qunit';import { setupTest } from '@fleetbase/console/tests/helpers';+import { setOwner } from '@ember/application';+import DashboardModel from '@fleetbase/console/models/dashboard';module('Unit | Model | dashboard', function (hooks) {setupTest(hooks);@@ -128,3 +130,31 @@ module('Unit | Model | dashboard | widgets', function (hooks) {assert.ok(dashboard.updatedAgo.length > 0, 'updatedAgo is a relative description');});});++module('Unit | Model | dashboard | registry', function () {+ test('a dashboard whose container has no universe service has no registry', function (assert) {+ // getRegistry() looks the universe up through the owner. An owner that cannot+ // provide it — as in a teardown or a stripped-down container — must yield nothing+ // rather than throwing while a dashboard renders.+ const stand = { id: 'dash_1' };+ setOwner(stand, { lookup: () => undefined });++ assert.strictEqual(DashboardModel.prototype.getRegistry.call(stand), undefined);+ });++ test('the registry is looked up by the dashboard id', function (assert) {+ const stand = { id: 'dash_2' };+ const requested = [];+ setOwner(stand, {+ lookup: () => ({+ getDashboardRegistry: (id) => {+ requested.push(id);+ return { widgets: ['a'] };+ },+ }),+ });++ assert.deepEqual(DashboardModel.prototype.getRegistry.call(stand), { widgets: ['a'] });+ assert.deepEqual(requested, ['dash_2']);+ });+});diff --git a/console/tests/unit/models/report-test.js b/console/tests/unit/models/report-test.jsindex 9300ba86..415fc9d3 100644--- a/console/tests/unit/models/report-test.js+++ b/console/tests/unit/models/report-test.js@@ -444,3 +444,51 @@ module('Unit | Model | report | execution display', function (hooks) {assert.strictEqual(zero.lastResultCountDisplay, '0', 'zero is a real count, not "no result"');});});++module('Unit | Model | report | sparse query configs', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ this.report = (query_config) => this.owner.lookup('service:store').createRecord('report', { query_config });+ });++ test('a query with a table but no columns selects nothing', function (assert) {+ const report = this.report({ table: { name: 'orders', label: 'Orders' } });++ assert.deepEqual(report.selectedColumns, [], 'the column list is empty rather than undefined');+ assert.strictEqual(report.totalSelectedColumns, 0);+ });++ test('a join that selects no columns is counted as zero rather than blank', function (assert) {+ const report = this.report({+ table: { name: 'orders' },+ columns: ['id'],+ joins: [+ { table: 'drivers', type: 'left', selectedColumns: ['name', 'phone'] },+ { table: 'payloads', type: 'inner' },+ ],+ });++ assert.deepEqual(+ report.joinedTables.map((join) => [join.table, join.label, join.columnsCount]),+ [+ ['drivers', 'drivers', 2],+ ['payloads', 'payloads', 0],+ ],+ 'a join with no selection contributes no columns and falls back to its table name as a label'+ );+ });++ test('a condition with neither a field nor an operator is left out of the summary', function (assert) {+ const report = this.report({+ table: { name: 'orders' },+ conditions: [{ field: { name: 'status', label: 'Status' }, operator: { value: '=', label: 'is' }, value: 'created' }, { logic: 'and' }, {}],+ });++ assert.deepEqual(+ report.conditionsSummary.map((condition) => condition.field),+ ['Status'],+ 'half-built conditions from the query builder are skipped rather than rendered blank'+ );+ });+});diff --git a/console/tests/unit/routes/console/admin/organizations/details/index-test.js b/console/tests/unit/routes/console/admin/organizations/details/index-test.jsnew file mode 100644index 00000000..5d30d95b--- /dev/null+++ b/console/tests/unit/routes/console/admin/organizations/details/index-test.js@@ -0,0 +1,28 @@+import { module, test } from 'qunit';+import { setupTest } from '@fleetbase/console/tests/helpers';++/**+ * Both leaf routes under the organization details screen reuse the organization their+ * parent already loaded rather than refetching it.+ */+const ROUTES = [{ name: 'route:console/admin/organizations/details/index' }, { name: 'route:console/admin/organizations/details/settings' }];++module('Unit | Route | console/admin/organizations/details leaf routes', function (hooks) {+ setupTest(hooks);++ ROUTES.forEach(({ name }) => {+ test(`${name} reuses the parent organization`, function (assert) {+ const route = this.owner.lookup(name);+ const organization = { uuid: 'org_1', name: 'Acme' };+ const requested = [];++ route.modelFor = (routeName) => {+ requested.push(routeName);+ return organization;+ };++ assert.strictEqual(route.model(), organization);+ assert.deepEqual(requested, ['console.admin.organizations.details'], 'it asks the details route, not the API');+ });+ });+});diff --git a/console/tests/unit/routes/console/notifications-test.js b/console/tests/unit/routes/console/notifications-test.jsindex abe7aaef..eabd3d35 100644--- a/console/tests/unit/routes/console/notifications-test.js+++ b/console/tests/unit/routes/console/notifications-test.js@@ -40,3 +40,29 @@ module('Unit | Route | console/notifications', function (hooks) {assert.deepEqual(calls, ['disable', 'enable']);});});++module('Unit | Route | console/notifications | model', function (hooks) {+ setupTest(hooks);++ test('the notification list is queried with whatever params the route was given', function (assert) {+ const route = this.owner.lookup('route:console/notifications');+ const queries = [];+ Object.defineProperty(route, 'store', {+ configurable: true,+ value: {+ query: (type, params) => {+ queries.push({ type, params });+ return Promise.resolve([]);+ },+ },+ });++ route.model({ page: 2, limit: 10 });+ route.model();++ assert.deepEqual(queries, [+ { type: 'notification', params: { page: 2, limit: 10 } },+ { type: 'notification', params: {} },+ ]);+ });+});diff --git a/console/tests/unit/routes/install-test.js b/console/tests/unit/routes/install-test.jsindex d8f4bacd..0d9b4fd0 100644--- a/console/tests/unit/routes/install-test.js+++ b/console/tests/unit/routes/install-test.js@@ -50,3 +50,28 @@ module('Unit | Route | install', function (hooks) {assert.strictEqual(route.beforeModel(), 'install-status-transition');});});++module('Unit | Route | install | teardown', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ this.route = this.owner.lookup('route:install');+ this.stopped = 0;+ Object.defineProperty(this.route.installation, 'stopListeningForInstallComplete', {+ configurable: true,+ value: () => this.stopped++,+ });+ });++ test('leaving the install screen stops listening for the completion event', function (assert) {+ this.route.resetController(this.owner.lookup('controller:install'), true);++ assert.strictEqual(this.stopped, 1);+ });++ test('a query-param change within the install screen keeps the listener alive', function (assert) {+ this.route.resetController(this.owner.lookup('controller:install'), false);++ assert.strictEqual(this.stopped, 0, 'the socket subscription survives an in-route transition');+ });+});diff --git a/console/tests/unit/serializers/category-test.js b/console/tests/unit/serializers/category-test.jsindex 1251afe4..5599af25 100644--- a/console/tests/unit/serializers/category-test.js+++ b/console/tests/unit/serializers/category-test.js@@ -39,3 +39,32 @@ module('Unit | Serializer | category | relationship pruning', function (hooks) {assert.notOk(json.subcategories, 'the pruned relationships are absent');});});++/**+ * Each of these serializers withholds exactly one self-referential relationship so the API+ * never receives a nested tree it cannot accept. Every model here declares only that one+ * hasMany, so the "serialize it normally" arm is driven with another model's relationship —+ * the guard is on the key, not on the model.+ */+const WITHHELD = [+ { model: 'category', relationship: 'subcategories' },+ { model: 'comment', relationship: 'replies' },+ { model: 'dashboard', relationship: 'widgets' },+];++module('Unit | Serializer | withheld relationships', function (hooks) {+ setupTest(hooks);++ WITHHELD.forEach(({ model, relationship }) => {+ test(`${model} never serializes its ${relationship}`, function (assert) {+ const store = this.owner.lookup('service:store');+ const serializer = store.serializerFor(model);+ const record = store.createRecord(model, {});+ const json = { existing: 'untouched' };++ serializer.serializeHasMany(record._createSnapshot(), json, store.modelFor(model).relationshipsByName.get(relationship));++ assert.deepEqual(json, { existing: 'untouched' }, `${relationship} is left out of the payload entirely`);+ });+ });+});diff --git a/console/tests/unit/serializers/user-test.js b/console/tests/unit/serializers/user-test.jsindex c44b4bfe..600af774 100644--- a/console/tests/unit/serializers/user-test.js+++ b/console/tests/unit/serializers/user-test.js@@ -82,3 +82,19 @@ module('Unit | Serializer | user | payload hygiene', function (hooks) {assert.strictEqual(normalized.data.attributes.avatar_url, '/avatar.png', 'nothing to protect, so everything lands');});});++module('Unit | Serializer | user | reloading an existing record', function (hooks) {+ setupTest(hooks);++ test('a payload with no attributes at all is left alone', function (assert) {+ const store = this.owner.lookup('service:store');+ store.push({ data: { id: 'u1', type: 'user', attributes: { name: 'Existing' } } });++ // A relationship-only payload normalizes to a resource with no attributes hash;+ // the merge guard has to cope with that rather than reading through undefined.+ const normalized = store.serializerFor('user').normalize(store.modelFor('user'), { uuid: 'u1' }, 'user');++ assert.strictEqual(normalized.data.id, 'u1');+ assert.strictEqual(store.peekRecord('user', 'u1').name, 'Existing', 'the loaded record keeps its name');+ });+});diff --git a/console/tests/unit/transforms/array-test.js b/console/tests/unit/transforms/array-test.jsindex b2db9925..c49b826f 100644--- a/console/tests/unit/transforms/array-test.js+++ b/console/tests/unit/transforms/array-test.js@@ -40,3 +40,19 @@ module('Unit | Transform | array', function (hooks) {assert.deepEqual(transform.serialize('bad'), []);});});++module('Unit | Transform | array | iterables', function (hooks) {+ setupTest(hooks);++ test('a non-string iterable is copied into a real array', function (assert) {+ const transform = this.owner.lookup('transform:array');++ assert.deepEqual(transform.deserialize(new Set(['a', 'b', 'a'])), ['a', 'b'], 'a Set is flattened to its members');+ });++ test('any other iterable is spread into an array too', function (assert) {+ const transform = this.owner.lookup('transform:array');++ assert.deepEqual(transform.deserialize(new Map([['a', 1]])), [['a', 1]], 'a Map deserializes to its entries');+ });+});