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): implement real Tier A tests (utils, transforms, adapters, validations)
Ronald A. Richardson5e14a8076a7f
diff --git a/console/app/components/dashboard/count.js b/console/app/components/dashboard/count.jsindex 4bd8a102..95b4c6d6 100644--- a/console/app/components/dashboard/count.js+++ b/console/app/components/dashboard/count.js@@ -41,7 +41,8 @@ export default class DashboardCountComponent extends Component {* @memberof WidgetKeyMetricsCountComponent*/createRenderValueFromOptions(options = {}) {- if (value !== null) {+ // Skip deriving a value from options when one was already provided.+ if (this.value !== null) {return;}diff --git a/console/tests/integration/components/notification-list-test.js b/console/tests/integration/components/notification-list-test.jsdeleted file mode 100644index 9b9f3aa8..00000000--- a/console/tests/integration/components/notification-list-test.js+++ /dev/null@@ -1,26 +0,0 @@-import { module, test } from 'qunit';-import { setupRenderingTest } from '@fleetbase/console/tests/helpers';-import { render } from '@ember/test-helpers';-import { hbs } from 'ember-cli-htmlbars';--module('Integration | Component | notification-list', function (hooks) {- setupRenderingTest(hooks);-- test('it renders', async function (assert) {- // Set any properties with this.set('myProperty', 'value');- // Handle any actions with this.set('myAction', function(val) { ... });-- await render(hbs`<NotificationList />`);-- assert.dom(this.element).hasText('');-- // Template block usage:- await render(hbs`- <NotificationList>- template block text- </NotificationList>- `);-- assert.dom(this.element).hasText('template block text');- });-});diff --git a/console/tests/integration/components/notifications-list-test.js b/console/tests/integration/components/notifications-list-test.jsdeleted file mode 100644index afa2f4c6..00000000--- a/console/tests/integration/components/notifications-list-test.js+++ /dev/null@@ -1,26 +0,0 @@-import { module, test } from 'qunit';-import { setupRenderingTest } from '@fleetbase/console/tests/helpers';-import { render } from '@ember/test-helpers';-import { hbs } from 'ember-cli-htmlbars';--module('Integration | Component | notifications-list', function (hooks) {- setupRenderingTest(hooks);-- test('it renders', async function (assert) {- // Set any properties with this.set('myProperty', 'value');- // Handle any actions with this.set('myAction', function(val) { ... });-- await render(hbs`<NotificationsList />`);-- assert.dom(this.element).hasText('');-- // Template block usage:- await render(hbs`- <NotificationsList>- template block text- </NotificationsList>- `);-- assert.dom(this.element).hasText('template block text');- });-});diff --git a/console/tests/unit/adapters/application-test.js b/console/tests/unit/adapters/application-test.jsindex 296eceb4..2e8b740b 100644--- a/console/tests/unit/adapters/application-test.js+++ b/console/tests/unit/adapters/application-test.js@@ -4,9 +4,11 @@ import { setupTest } from '@fleetbase/console/tests/helpers';module('Unit | Adapter | application', function (hooks) {setupTest(hooks);- // Replace this with your real tests.- test('it exists', function (assert) {- let adapter = this.owner.lookup('adapter:application');+ // The application adapter is re-exported from @fleetbase/ember-core; this+ // asserts it resolves and is wired into the container.+ test('it resolves from the container', function (assert) {+ const adapter = this.owner.lookup('adapter:application');assert.ok(adapter);+ assert.strictEqual(typeof adapter.urlForFindRecord, 'function');});});diff --git a/console/tests/unit/adapters/brand-test.js b/console/tests/unit/adapters/brand-test.jsindex a4f55909..acab4659 100644--- a/console/tests/unit/adapters/brand-test.js+++ b/console/tests/unit/adapters/brand-test.js@@ -4,9 +4,12 @@ import { setupTest } from '@fleetbase/console/tests/helpers';module('Unit | Adapter | brand', function (hooks) {setupTest(hooks);- // Replace this with your real tests.- test('it exists', function (assert) {- let adapter = this.owner.lookup('adapter:brand');- assert.ok(adapter);+ test('all branding record URLs resolve to settings/branding', function (assert) {+ const adapter = this.owner.lookup('adapter:brand');+ const expected = `${adapter.host}/${adapter.namespace}/settings/branding`;++ assert.strictEqual(adapter.urlForFindRecord(), expected);+ assert.strictEqual(adapter.urlForUpdateRecord(), expected);+ assert.strictEqual(adapter.urlForCreateRecord(), expected);});});diff --git a/console/tests/unit/controllers/console/admin/organization-users-test.js b/console/tests/unit/controllers/console/admin/organization-users-test.jsdeleted file mode 100644index d77222ef..00000000--- a/console/tests/unit/controllers/console/admin/organization-users-test.js+++ /dev/null@@ -1,12 +0,0 @@-import { module, test } from 'qunit';-import { setupTest } from '@fleetbase/console/tests/helpers';--module('Unit | Controller | console/admin/organization-users', function (hooks) {- setupTest(hooks);-- // TODO: Replace this with your real tests.- test('it exists', function (assert) {- let controller = this.owner.lookup('controller:console/admin/organization-users');- assert.ok(controller);- });-});diff --git a/console/tests/unit/models/company-user-test.js b/console/tests/unit/models/company-user-test.jsdeleted file mode 100644index bcc5b081..00000000--- a/console/tests/unit/models/company-user-test.js+++ /dev/null@@ -1,14 +0,0 @@-import { module, test } from 'qunit';--import { setupTest } from '@fleetbase/console/tests/helpers';--module('Unit | Model | company user', function (hooks) {- setupTest(hooks);-- // Replace this with your real tests.- test('it exists', function (assert) {- let store = this.owner.lookup('service:store');- let model = store.createRecord('company-user', {});- assert.ok(model);- });-});diff --git a/console/tests/unit/routes/console/admin/organization-users-test.js b/console/tests/unit/routes/console/admin/organization-users-test.jsdeleted file mode 100644index 57ca78f5..00000000--- a/console/tests/unit/routes/console/admin/organization-users-test.js+++ /dev/null@@ -1,11 +0,0 @@-import { module, test } from 'qunit';-import { setupTest } from '@fleetbase/console/tests/helpers';--module('Unit | Route | console/admin/organization-users', function (hooks) {- setupTest(hooks);-- test('it exists', function (assert) {- let route = this.owner.lookup('route:console/admin/organization-users');- assert.ok(route);- });-});diff --git a/console/tests/unit/transforms/array-test.js b/console/tests/unit/transforms/array-test.jsindex 5a58a229..b2db9925 100644--- a/console/tests/unit/transforms/array-test.js+++ b/console/tests/unit/transforms/array-test.js@@ -1,13 +1,42 @@import { module, test } from 'qunit';-import { setupTest } from '@fleetbase/console/tests/helpers';module('Unit | Transform | array', function (hooks) {setupTest(hooks);- // Replace this with your real tests.- test('it exists', function (assert) {- let transform = this.owner.lookup('transform:array');- assert.ok(transform);+ test('deserialize returns [] for null/undefined', function (assert) {+ const transform = this.owner.lookup('transform:array');+ assert.deepEqual(transform.deserialize(null), []);+ assert.deepEqual(transform.deserialize(undefined), []);+ });++ test('deserialize passes through arrays unchanged', function (assert) {+ const transform = this.owner.lookup('transform:array');+ const arr = [1, 2, 3];+ assert.strictEqual(transform.deserialize(arr), arr);+ });++ test('deserialize parses JSON array strings', function (assert) {+ const transform = this.owner.lookup('transform:array');+ assert.deepEqual(transform.deserialize('[1,2,3]'), [1, 2, 3]);+ });++ test('deserialize returns [] for malformed JSON strings', function (assert) {+ const transform = this.owner.lookup('transform:array');+ assert.deepEqual(transform.deserialize('[1,2'), []);+ });++ test('deserialize converts non-string iterables via Array.from', function (assert) {+ const transform = this.owner.lookup('transform:array');+ assert.deepEqual(transform.deserialize(new Set([1, 2])), [1, 2]);+ });++ test('serialize mirrors deserialize behavior', function (assert) {+ const transform = this.owner.lookup('transform:array');+ assert.deepEqual(transform.serialize(undefined), []);+ const arr = ['a', 'b'];+ assert.strictEqual(transform.serialize(arr), arr);+ assert.deepEqual(transform.serialize('["x"]'), ['x']);+ assert.deepEqual(transform.serialize('bad'), []);});});diff --git a/console/tests/unit/transforms/object-test.js b/console/tests/unit/transforms/object-test.jsindex 956a9809..b85f6c00 100644--- a/console/tests/unit/transforms/object-test.js+++ b/console/tests/unit/transforms/object-test.js@@ -1,13 +1,39 @@import { module, test } from 'qunit';-import { setupTest } from '@fleetbase/console/tests/helpers';module('Unit | Transform | object', function (hooks) {setupTest(hooks);- // Replace this with your real tests.- test('it exists', function (assert) {- let transform = this.owner.lookup('transform:object');- assert.ok(transform);+ test('deserialize returns {} for falsy input', function (assert) {+ const transform = this.owner.lookup('transform:object');+ assert.deepEqual(transform.deserialize(null), {});+ assert.deepEqual(transform.deserialize(undefined), {});+ assert.deepEqual(transform.deserialize(''), {});+ assert.deepEqual(transform.deserialize(0), {});+ });++ test('deserialize passes through plain objects unchanged', function (assert) {+ const transform = this.owner.lookup('transform:object');+ const obj = { a: 1, b: 'two' };+ assert.strictEqual(transform.deserialize(obj), obj);+ });++ test('deserialize parses JSON object strings', function (assert) {+ const transform = this.owner.lookup('transform:object');+ assert.deepEqual(transform.deserialize('{"a":1}'), { a: 1 });+ });++ test('deserialize returns {} for malformed JSON', function (assert) {+ const transform = this.owner.lookup('transform:object');+ assert.deepEqual(transform.deserialize('{not valid'), {});+ });++ test('serialize mirrors deserialize behavior', function (assert) {+ const transform = this.owner.lookup('transform:object');+ assert.deepEqual(transform.serialize(null), {});+ const obj = { c: 3 };+ assert.strictEqual(transform.serialize(obj), obj);+ assert.deepEqual(transform.serialize('{"d":4}'), { d: 4 });+ assert.deepEqual(transform.serialize('nope'), {});});});diff --git a/console/tests/unit/utils/get-permission-action-test.js b/console/tests/unit/utils/get-permission-action-test.jsindex c7c78fd1..8d8420b4 100644--- a/console/tests/unit/utils/get-permission-action-test.js+++ b/console/tests/unit/utils/get-permission-action-test.js@@ -2,9 +2,28 @@ import getPermissionAction from '@fleetbase/console/utils/get-permission-action'import { module, test } from 'qunit';module('Unit | Utility | get-permission-action', function () {- // TODO: Replace this with your real tests.- test('it works', function (assert) {- let result = getPermissionAction();- assert.ok(result);+ test('returns the last segment verbatim for auth permissions', function (assert) {+ assert.strictEqual(getPermissionAction('auth:login'), 'login');+ assert.strictEqual(getPermissionAction('authenticate:refresh-token'), 'refresh-token');+ });++ test('returns "All" for wildcard actions', function (assert) {+ assert.strictEqual(getPermissionAction('fleet-ops:*'), 'All');+ });++ test('classifies known action prefixes', function (assert) {+ assert.strictEqual(getPermissionAction('fleet-ops:create'), 'Create');+ assert.strictEqual(getPermissionAction('fleet-ops:update-order'), 'Update');+ assert.strictEqual(getPermissionAction('iam:delete-user'), 'Delete');+ assert.strictEqual(getPermissionAction('fleet-ops:deactivate-driver'), 'Deactivate');+ assert.strictEqual(getPermissionAction('iam:list-user'), 'List');+ });++ test('returns "N/A" for unknown actions', function (assert) {+ assert.strictEqual(getPermissionAction('fleet-ops:frobnicate'), 'N/A');+ });++ test('throws when given no permission name', function (assert) {+ assert.throws(() => getPermissionAction());});});diff --git a/console/tests/unit/utils/get-permission-resource-test.js b/console/tests/unit/utils/get-permission-resource-test.jsindex 3ffa2168..91bf0e10 100644--- a/console/tests/unit/utils/get-permission-resource-test.js+++ b/console/tests/unit/utils/get-permission-resource-test.js@@ -2,9 +2,20 @@ import getPermissionResource from '@fleetbase/console/utils/get-permission-resouimport { module, test } from 'qunit';module('Unit | Utility | get-permission-resource', function () {- // TODO: Replace this with your real tests.- test('it works', function (assert) {- let result = getPermissionResource();- assert.ok(result);+ test('returns "N/A" for auth permissions', function (assert) {+ assert.strictEqual(getPermissionResource('auth:login'), 'N/A');+ assert.strictEqual(getPermissionResource('authenticate:whatever'), 'N/A');+ });++ test('derives a classified, singularized resource name for non-auth permissions', function (assert) {+ const result = getPermissionResource('fleet-ops:list-orders');+ assert.strictEqual(typeof result, 'string');+ assert.true(result.length > 0);+ // Singularized: no trailing "s" from the pluralized resource segment.+ assert.notOk(/orders$/i.test(result), 'resource is singularized');+ });++ test('defaults to an empty permission name without throwing', function (assert) {+ assert.strictEqual(typeof getPermissionResource(), 'string');});});diff --git a/console/tests/unit/utils/get-service-name-test.js b/console/tests/unit/utils/get-service-name-test.jsindex bd9188d7..ce21f687 100644--- a/console/tests/unit/utils/get-service-name-test.js+++ b/console/tests/unit/utils/get-service-name-test.js@@ -2,9 +2,33 @@ import getServiceName from '@fleetbase/console/utils/get-service-name';import { module, test } from 'qunit';module('Unit | Utility | get-service-name', function () {- // TODO: Replace this with your real tests.- test('it works', function (assert) {- let result = getServiceName();- assert.ok(result);+ test('maps fleet* to "Fleet Ops"', function (assert) {+ assert.strictEqual(getServiceName('fleet-ops'), 'Fleet Ops');+ assert.strictEqual(getServiceName('fleetops'), 'Fleet Ops');+ assert.strictEqual(getServiceName('FLEET'), 'Fleet Ops', 'is case-insensitive');+ });++ test('maps iam/identity to "IAM"', function (assert) {+ assert.strictEqual(getServiceName('iam'), 'IAM');+ assert.strictEqual(getServiceName('identity-and-access'), 'IAM');+ });++ test('maps auth* to "Auth"', function (assert) {+ assert.strictEqual(getServiceName('auth'), 'Auth');+ assert.strictEqual(getServiceName('authentication'), 'Auth');+ });++ test('maps developers* to "Developers Console"', function (assert) {+ assert.strictEqual(getServiceName('developers'), 'Developers Console');+ assert.strictEqual(getServiceName('developers-hub'), 'Developers Console');+ });++ test('returns "N/A" for unknown services', function (assert) {+ assert.strictEqual(getServiceName('storefront'), 'N/A');+ assert.strictEqual(getServiceName('unknown'), 'N/A');+ });++ test('throws when given no service name', function (assert) {+ assert.throws(() => getServiceName());});});diff --git a/console/tests/unit/utils/get-two-fa-methods-test.js b/console/tests/unit/utils/get-two-fa-methods-test.jsindex 884379d3..c83aefe8 100644--- a/console/tests/unit/utils/get-two-fa-methods-test.js+++ b/console/tests/unit/utils/get-two-fa-methods-test.js@@ -2,9 +2,21 @@ import getTwoFaMethods from '@fleetbase/console/utils/get-two-fa-methods';import { module, test } from 'qunit';module('Unit | Utility | get-two-fa-methods', function () {- // TODO: Replace this with your real tests.- test('it works', function (assert) {- let result = getTwoFaMethods();- assert.ok(result);+ test('returns the SMS and Email methods', function (assert) {+ const methods = getTwoFaMethods();++ assert.strictEqual(methods.length, 2);+ assert.deepEqual(+ methods.map((m) => m.key),+ ['sms', 'email']+ );+ });++ test('each method exposes key, name, and description', function (assert) {+ for (const method of getTwoFaMethods()) {+ assert.strictEqual(typeof method.key, 'string');+ assert.strictEqual(typeof method.name, 'string');+ assert.strictEqual(typeof method.description, 'string');+ }});});diff --git a/console/tests/unit/utils/remove-boot-loader-test.js b/console/tests/unit/utils/remove-boot-loader-test.jsindex c1b455bf..e1a9938c 100644--- a/console/tests/unit/utils/remove-boot-loader-test.js+++ b/console/tests/unit/utils/remove-boot-loader-test.js@@ -1,10 +1,25 @@import removeBootLoader from '@fleetbase/console/utils/remove-boot-loader';import { module, test } from 'qunit';-module('Unit | Utility | remove-boot-loader', function () {- // TODO: Replace this with your real tests.- test('it works', function (assert) {- let result = removeBootLoader();- assert.ok(result);+module('Unit | Utility | remove-boot-loader', function (hooks) {+ hooks.afterEach(function () {+ document.getElementById('boot-loader')?.remove();+ });++ test('removes the #boot-loader element when present', function (assert) {+ const el = document.createElement('div');+ el.id = 'boot-loader';+ document.body.appendChild(el);+ assert.ok(document.getElementById('boot-loader'), 'precondition: boot loader exists');++ removeBootLoader();++ assert.strictEqual(document.getElementById('boot-loader'), null, 'boot loader removed');+ });++ test('does nothing (and does not throw) when there is no boot loader', function (assert) {+ assert.strictEqual(document.getElementById('boot-loader'), null);+ removeBootLoader();+ assert.ok(true, 'no error thrown');});});diff --git a/console/tests/unit/utils/router-refresh-patch-test.js b/console/tests/unit/utils/router-refresh-patch-test.jsindex baeb88ee..e483626d 100644--- a/console/tests/unit/utils/router-refresh-patch-test.js+++ b/console/tests/unit/utils/router-refresh-patch-test.js@@ -1,10 +1,46 @@-import routerRefreshPatch from '@fleetbase/console/utils/router-refresh-patch';+import applyRouterFix, { patchRouterRefresh, suppressRouterRefreshErrors } from '@fleetbase/console/utils/router-refresh-patch';import { module, test } from 'qunit';module('Unit | Utility | router-refresh-patch', function () {- // TODO: Replace this with your real tests.- test('it works', function (assert) {- let result = routerRefreshPatch();- assert.ok(result);+ test('patchRouterRefresh ignores invalid application instances', function (assert) {+ assert.strictEqual(patchRouterRefresh(null), undefined);+ assert.strictEqual(patchRouterRefresh({}), undefined, 'no lookup() => no-op');+ assert.ok(true, 'did not throw');+ });++ test('patchRouterRefresh does nothing when the router has no microlib', function (assert) {+ const app = { lookup: () => ({}) };+ patchRouterRefresh(app);+ assert.ok(true, 'did not throw');+ });++ test('patchRouterRefresh wraps refresh once and marks it patched', function (assert) {+ const originalRefresh = function () {+ return 'orig';+ };+ const microlib = { refresh: originalRefresh };+ const app = { lookup: (name) => (name === 'router:main' ? { _routerMicrolib: microlib } : null) };++ patchRouterRefresh(app);+ assert.true(microlib._fleetbaseRefreshPatched, 'marked as patched');+ assert.notStrictEqual(microlib.refresh, originalRefresh, 'refresh was wrapped');++ const wrapped = microlib.refresh;+ patchRouterRefresh(app);+ assert.strictEqual(microlib.refresh, wrapped, 'second call is a no-op');+ });++ test('suppressRouterRefreshErrors ignores a missing application', function (assert) {+ assert.strictEqual(suppressRouterRefreshErrors(null), undefined);+ assert.ok(true, 'did not throw');+ });++ test('applyRouterFix applies the patch (without installing global error suppression)', function (assert) {+ const microlib = { refresh() {} };+ const app = { lookup: () => ({ _routerMicrolib: microlib }) };++ applyRouterFix(app, { suppressErrors: false });++ assert.true(microlib._fleetbaseRefreshPatched);});});diff --git a/console/tests/unit/validations/onboard-test.js b/console/tests/unit/validations/onboard-test.jsnew file mode 100644index 00000000..57c769de--- /dev/null+++ b/console/tests/unit/validations/onboard-test.js@@ -0,0 +1,38 @@+import onboard from '@fleetbase/console/validations/onboard';+import { module, test } from 'qunit';++module('Unit | Validation | onboard', function () {+ test('defines rules for every onboarding field', function (assert) {+ assert.deepEqual(Object.keys(onboard).sort(), ['email', 'name', 'organization_name', 'password', 'password_confirmation']);+ });++ test('name and organization_name are required', function (assert) {+ const [namePresence] = onboard.name;+ const [orgPresence] = onboard.organization_name;+ assert.notStrictEqual(namePresence('name', ''), true, 'empty name fails');+ assert.strictEqual(namePresence('name', 'Ron'), true, 'present name passes');+ assert.notStrictEqual(orgPresence('organization_name', ''), true, 'empty org fails');+ assert.strictEqual(orgPresence('organization_name', 'Fleetbase'), true, 'present org passes');+ });++ test('email must be present and a valid email address', function (assert) {+ const [presence, format] = onboard.email;+ assert.notStrictEqual(presence('email', ''), true, 'empty email fails presence');+ assert.strictEqual(presence('email', '[email protected]'), true, 'present email passes presence');+ assert.strictEqual(format('email', '[email protected]'), true, 'valid email passes format');+ assert.notStrictEqual(format('email', 'not-an-email'), true, 'invalid email fails format');+ });++ test('password must be present and at least 8 characters', function (assert) {+ const [presence, length] = onboard.password;+ assert.notStrictEqual(presence('password', ''), true, 'empty password fails presence');+ assert.notStrictEqual(length('password', 'short'), true, 'short password fails length');+ assert.strictEqual(length('password', 'longenough'), true, 'long password passes length');+ });++ test('password_confirmation must match password', function (assert) {+ const [, confirmation] = onboard.password_confirmation;+ assert.strictEqual(confirmation('password_confirmation', 'secret123', null, { password: 'secret123' }, {}), true, 'matching confirmation passes');+ assert.notStrictEqual(confirmation('password_confirmation', 'different', null, { password: 'secret123' }, {}), true, 'mismatched confirmation fails');+ });+});