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 admin organization details controllers
Ronald A. Richardsonaeb760c3c845
diff --git a/console/tests/unit/controllers/console/admin/organizations/details-test.js b/console/tests/unit/controllers/console/admin/organizations/details-test.jsnew file mode 100644index 00000000..bedc8880--- /dev/null+++ b/console/tests/unit/controllers/console/admin/organizations/details-test.js@@ -0,0 +1,48 @@+import { module, test } from 'qunit';+import { setupTest } from '@fleetbase/console/tests/helpers';++module('Unit | Controller | console/admin/organizations/details', function (hooks) {+ setupTest(hooks);++ function lookup(owner) {+ return owner.lookup('controller:console/admin/organizations/details');+ }++ test('status getters read the organization model with defaults', function (assert) {+ const controller = lookup(this.owner);+ controller.model = { status: 'active', onboarding_completed: true, billing_status: 'active' };++ assert.strictEqual(controller.organization, controller.model);+ assert.strictEqual(controller.organizationStatus, 'active');+ assert.strictEqual(controller.onboardingStatus, 'complete');+ assert.strictEqual(controller.billingStatus, 'active');+ });++ test('status getters fall back when the model is sparse', function (assert) {+ const controller = lookup(this.owner);+ controller.model = {};++ assert.strictEqual(controller.organizationStatus, 'active');+ assert.strictEqual(controller.onboardingStatus, 'incomplete');+ assert.strictEqual(controller.billingStatus, 'not configured');+ });++ test('owner getters resolve the belongsTo and expose identity fields', function (assert) {+ const controller = lookup(this.owner);+ controller.model = { owner_uuid: 'owner_1', owner: { id: 'owner_1', name: 'Ron', email: '[email protected]' } };++ assert.strictEqual(controller.ownerName, 'Ron');+ assert.strictEqual(controller.ownerEmail, '[email protected]');+ assert.strictEqual(controller.ownerId, 'owner_1');+ assert.true(controller.hasOwner);+ });++ test('hasOwner is true from owner_uuid even without a loaded owner record', function (assert) {+ const controller = lookup(this.owner);+ controller.model = { owner_uuid: 'owner_2', owner: null };++ assert.strictEqual(controller.owner, null);+ assert.strictEqual(controller.ownerId, 'owner_2', 'falls back to owner_uuid');+ assert.true(controller.hasOwner);+ });+});diff --git a/console/tests/unit/controllers/console/admin/organizations/details/index-test.js b/console/tests/unit/controllers/console/admin/organizations/details/index-test.jsnew file mode 100644index 00000000..b0c6e29a--- /dev/null+++ b/console/tests/unit/controllers/console/admin/organizations/details/index-test.js@@ -0,0 +1,60 @@+import { module, test } from 'qunit';+import { setupTest } from '@fleetbase/console/tests/helpers';++module('Unit | Controller | console/admin/organizations/details/index', function (hooks) {+ setupTest(hooks);++ function lookup(owner) {+ return owner.lookup('controller:console/admin/organizations/details/index');+ }++ test('owner getters resolve from the organization model', function (assert) {+ const controller = lookup(this.owner);+ controller.model = {+ status: 'active',+ users_count: 7,+ onboarding_completed: true,+ owner: { name: 'Ron', email: '[email protected]', phone: '555-1234' },+ };++ assert.strictEqual(controller.organization, controller.model);+ assert.strictEqual(controller.ownerName, 'Ron');+ assert.strictEqual(controller.ownerEmail, '[email protected]');+ assert.strictEqual(controller.ownerPhone, '555-1234');+ assert.strictEqual(controller.ownerState, 'Assigned');+ assert.strictEqual(controller.onboardingState, 'Complete');+ assert.strictEqual(controller.statusLabel, 'active');+ });++ test('getters fall back sensibly when the owner and flags are missing', function (assert) {+ const controller = lookup(this.owner);+ controller.model = { status: 'suspended', owner: null };++ assert.strictEqual(controller.owner, null);+ assert.strictEqual(controller.ownerState, 'Missing');+ assert.strictEqual(controller.onboardingState, 'Incomplete');+ assert.strictEqual(controller.statusLabel, 'suspended');+ });++ test('metrics builds a four-card KPI summary from the model', function (assert) {+ const controller = lookup(this.owner);+ controller.model = { status: 'active', users_count: 3, onboarding_completed: false, owner: { email: '[email protected]' } };++ const metrics = controller.metrics;+ assert.strictEqual(metrics.length, 4);+ assert.deepEqual(+ metrics.map((m) => m.label),+ ['Users', 'Owner', 'Onboarding', 'Status']+ );+ assert.strictEqual(metrics[0].value, 3, 'users metric reads users_count');+ assert.strictEqual(metrics[2].value, 'Incomplete', 'onboarding metric reflects the flag');+ });++ test('resolveBelongsTo unwraps content and drops pending proxies', function (assert) {+ const controller = lookup(this.owner);++ assert.strictEqual(controller.resolveBelongsTo(null), null);+ assert.deepEqual(controller.resolveBelongsTo({ content: { id: 'x' } }), { id: 'x' });+ assert.strictEqual(controller.resolveBelongsTo({ isPending: true }), null);+ });+});