Skip to content

Modular logistics and supply chain operating system (LSOS)

fix(console): read the API config under its real key when downloading a file

Ronald A. Richardson457e2b232c69
diff --git a/console/app/models/chat-attachment.js b/console/app/models/chat-attachment.js
index e0330f71..12025894 100644
--- a/console/app/models/chat-attachment.js
+++ b/console/app/models/chat-attachment.js
@@ -70,7 +70,7 @@ export default class ChatAttachment extends Model {
/** @methods */
downloadFromApi() {
- window.open(config.api.host + '/' + config.api.namespace + '/files/download?file=' + this.file_uuid, '_self');
+ window.open(config.API.host + '/' + config.API.namespace + '/files/download?file=' + this.file_uuid, '_self');
}
download() {
diff --git a/console/app/models/file.js b/console/app/models/file.js
index eb27a5cf..834c2fe1 100644
--- a/console/app/models/file.js
+++ b/console/app/models/file.js
@@ -64,7 +64,7 @@ export default class FileModel extends Model {
/** @methods */
downloadFromApi() {
- window.open(config.api.host + '/' + config.api.namespace + '/files/download?file=' + this.id, '_self');
+ window.open(config.API.host + '/' + config.API.namespace + '/files/download?file=' + this.id, '_self');
}
download() {
diff --git a/console/tests/unit/models/category-test.js b/console/tests/unit/models/category-test.js
index 13d59e68..5046a4e7 100644
--- a/console/tests/unit/models/category-test.js
+++ b/console/tests/unit/models/category-test.js
@@ -11,3 +11,14 @@ module('Unit | Model | category', function (hooks) {
assert.ok(model);
});
});
+
+module('Unit | Model | category | customerId', function (hooks) {
+ setupTest(hooks);
+
+ test('customerId rewrites a contact public id as a customer one', function (assert) {
+ const store = this.owner.lookup('service:store');
+
+ assert.strictEqual(store.createRecord('category', { public_id: 'contact_abc123' }).customerId, 'customer_abc123');
+ assert.strictEqual(store.createRecord('category', { public_id: 'category_xyz' }).customerId, 'category_xyz', 'ids that are not contacts are left alone');
+ });
+});
diff --git a/console/tests/unit/models/chat-attachment-test.js b/console/tests/unit/models/chat-attachment-test.js
index 1abded81..e66a0bea 100644
--- a/console/tests/unit/models/chat-attachment-test.js
+++ b/console/tests/unit/models/chat-attachment-test.js
@@ -63,3 +63,26 @@ module('Unit | Model | chat-attachment', function (hooks) {
});
});
});
+
+module('Unit | Model | chat-attachment | download', function (hooks) {
+ setupTest(hooks);
+
+ test('downloadFromApi navigates to the API download endpoint for the attached file', function (assert) {
+ const opened = [];
+ const originalOpen = window.open;
+ window.open = (url, target) => opened.push({ url, target });
+
+ try {
+ this.owner
+ .lookup('service:store')
+ .push({ data: { id: 'att_1', type: 'chat-attachment', attributes: { file_uuid: 'file_9' } } })
+ .downloadFromApi();
+ } finally {
+ window.open = originalOpen;
+ }
+
+ assert.strictEqual(opened.length, 1, 'the browser is sent to the download URL');
+ assert.ok(opened[0].url.endsWith('/files/download?file=file_9'), `the attached file uuid is used, not the attachment id (got ${opened[0].url})`);
+ assert.strictEqual(opened[0].target, '_self');
+ });
+});
diff --git a/console/tests/unit/models/chat-channel-test.js b/console/tests/unit/models/chat-channel-test.js
index 39edead3..b3ba540c 100644
--- a/console/tests/unit/models/chat-channel-test.js
+++ b/console/tests/unit/models/chat-channel-test.js
@@ -1,5 +1,6 @@
import { module, test } from 'qunit';
import { setupTest } from '@fleetbase/console/tests/helpers';
+import { format } from 'date-fns';
module('Unit | Model | chat-channel', function (hooks) {
setupTest(hooks);
@@ -24,3 +25,77 @@ module('Unit | Model | chat-channel', function (hooks) {
assert.true(channel.doesntExistsInFeed('log', { id: 'm1' }));
});
});
+
+module('Unit | Model | chat-channel | behaviour', function (hooks) {
+ setupTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.store = this.owner.lookup('service:store');
+ });
+
+ test('the timestamp getters format valid dates and withhold invalid ones', function (assert) {
+ const channel = this.store.createRecord('chat-channel', {
+ created_at: new Date('2026-01-15T10:30:00Z'),
+ updated_at: new Date('2026-02-20T08:05:00Z'),
+ });
+
+ assert.strictEqual(channel.createdAt, format(new Date('2026-01-15T10:30:00Z'), 'PP HH:mm'));
+ assert.strictEqual(channel.updatedAt, format(new Date('2026-02-20T08:05:00Z'), 'PP HH:mm'));
+ assert.ok(channel.createdAgo.length > 0);
+ assert.ok(channel.updatedAgo.length > 0);
+
+ const undated = this.store.createRecord('chat-channel');
+ assert.strictEqual(undated.createdAt, null, 'an unset created_at yields null rather than throwing');
+ assert.strictEqual(undated.updatedAt, null);
+ assert.strictEqual(undated.createdAgo, null);
+ assert.strictEqual(undated.updatedAgo, null);
+ });
+
+ test('toJSON emits only the fields the API accepts', function (assert) {
+ const channel = this.store.createRecord('chat-channel', {
+ company_uuid: 'co_1',
+ name: 'Dispatch',
+ meta: { pinned: true },
+ title: 'ignored',
+ });
+
+ assert.deepEqual(channel.toJSON(), { company_uuid: 'co_1', name: 'Dispatch', meta: { pinned: true } });
+ });
+
+ test('existsInFeed and doesntExistsInFeed match on both type and record id', function (assert) {
+ const channel = this.store.createRecord('chat-channel');
+ channel.feed = [
+ { type: 'message', record: { id: 'm_1' } },
+ { type: 'log', record: { id: 'l_1' } },
+ ];
+
+ assert.true(channel.existsInFeed('message', { id: 'm_1' }));
+ assert.false(channel.existsInFeed('message', { id: 'm_2' }), 'a different id does not match');
+ assert.false(channel.existsInFeed('log', { id: 'm_1' }), 'a different type does not match either');
+
+ assert.false(channel.doesntExistsInFeed('message', { id: 'm_1' }));
+ assert.true(channel.doesntExistsInFeed('message', { id: 'm_2' }));
+ });
+
+ test('reloadParticipants queries by channel and stores the result', async function (assert) {
+ const channel = this.store.push({ data: { id: 'ch_1', type: 'chat-channel' } });
+ // participants is a hasMany, so it will only accept real records.
+ const participants = [this.store.push({ data: { id: 'p_1', type: 'chat-participant' } })];
+ const queries = [];
+
+ this.store.query = (type, params) => {
+ queries.push({ type, params });
+ return Promise.resolve(participants);
+ };
+
+ const result = await channel.reloadParticipants();
+
+ assert.deepEqual(queries, [{ type: 'chat-participant', params: { chat_channel_uuid: 'ch_1' } }]);
+ assert.strictEqual(result, participants, 'the participants are handed back');
+ assert.deepEqual(
+ channel.participants.map((participant) => participant.id),
+ ['p_1'],
+ 'and stored on the channel'
+ );
+ });
+});
diff --git a/console/tests/unit/models/custom-field-test.js b/console/tests/unit/models/custom-field-test.js
index 1b1eefa6..5b07f01b 100644
--- a/console/tests/unit/models/custom-field-test.js
+++ b/console/tests/unit/models/custom-field-test.js
@@ -12,3 +12,18 @@ module('Unit | Model | custom field', function (hooks) {
assert.ok(model);
});
});
+
+module('Unit | Model | custom-field | valueType', function (hooks) {
+ setupTest(hooks);
+
+ test('each input type maps to the kind of value it stores', function (assert) {
+ const store = this.owner.lookup('service:store');
+ const field = (type) => store.createRecord('custom-field', { type }).valueType;
+
+ assert.strictEqual(field('file-upload'), 'file');
+ assert.strictEqual(field('date-time-input'), 'date');
+ assert.strictEqual(field('model-select'), 'model');
+ assert.strictEqual(field('text-input'), 'text', 'anything else stores plain text');
+ assert.strictEqual(field(undefined), 'text', 'so does an unset type');
+ });
+});
diff --git a/console/tests/unit/models/custom-field-value-test.js b/console/tests/unit/models/custom-field-value-test.js
index a8be2964..cdaf2c16 100644
--- a/console/tests/unit/models/custom-field-value-test.js
+++ b/console/tests/unit/models/custom-field-value-test.js
@@ -1,6 +1,7 @@
import { module, test } from 'qunit';
import { setupTest } from '@fleetbase/console/tests/helpers';
+import Service from '@ember/service';
module('Unit | Model | custom field value', function (hooks) {
setupTest(hooks);
@@ -12,3 +13,38 @@ module('Unit | Model | custom field value', function (hooks) {
assert.ok(model);
});
});
+
+module('Unit | Model | custom-field-value | asFile', function (hooks) {
+ setupTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.converted = [];
+ const context = this;
+
+ class FetchStub extends Service {
+ jsonToModel(json, modelName) {
+ context.converted.push({ json, modelName });
+ return { id: 'file_1', modelName };
+ }
+ }
+ this.owner.register('service:fetch', FetchStub);
+ this.store = this.owner.lookup('service:store');
+ });
+
+ test('a JSON object value is converted into a file model', function (assert) {
+ const value = '{"uuid":"file_1","original_filename":"invoice.pdf"}';
+ const record = this.store.createRecord('custom-field-value', { value });
+
+ assert.deepEqual(record.asFile, { id: 'file_1', modelName: 'file' });
+ assert.deepEqual(this.converted, [{ json: value, modelName: 'file' }]);
+ });
+
+ test('a value that is not a JSON object is not treated as a file', function (assert) {
+ const store = this.store;
+
+ assert.strictEqual(store.createRecord('custom-field-value', { value: 'just text' }).asFile, null);
+ assert.strictEqual(store.createRecord('custom-field-value', { value: '[1,2]' }).asFile, null, 'an array is not a file object');
+ assert.strictEqual(store.createRecord('custom-field-value').asFile, null, 'neither is an unset value');
+ assert.deepEqual(this.converted, [], 'the fetch service is never asked to convert');
+ });
+});
diff --git a/console/tests/unit/models/dashboard-widget-test.js b/console/tests/unit/models/dashboard-widget-test.js
index ebf8bf0a..3ea82dab 100644
--- a/console/tests/unit/models/dashboard-widget-test.js
+++ b/console/tests/unit/models/dashboard-widget-test.js
@@ -12,3 +12,38 @@ module('Unit | Model | dashboard widget', function (hooks) {
assert.ok(model);
});
});
+
+module('Unit | Model | dashboard-widget | updateProperties', function (hooks) {
+ setupTest(hooks);
+
+ test('updateProperties applies the changes and persists them', async function (assert) {
+ const store = this.owner.lookup('service:store');
+ const widget = store.push({ data: { id: 'w_1', type: 'dashboard-widget' } });
+ let saved = 0;
+ widget.save = () => {
+ saved++;
+ return Promise.resolve(widget);
+ };
+
+ const result = await widget.updateProperties({ name: 'Earnings', component: 'kpi-tile' });
+
+ assert.strictEqual(widget.name, 'Earnings');
+ assert.strictEqual(widget.component, 'kpi-tile');
+ assert.strictEqual(saved, 1, 'the widget is saved once');
+ assert.strictEqual(result, widget, 'the saved record is handed back');
+ });
+
+ test('updateProperties with no changes still saves', async function (assert) {
+ const store = this.owner.lookup('service:store');
+ const widget = store.push({ data: { id: 'w_2', type: 'dashboard-widget' } });
+ let saved = 0;
+ widget.save = () => {
+ saved++;
+ return Promise.resolve(widget);
+ };
+
+ await widget.updateProperties();
+
+ assert.strictEqual(saved, 1);
+ });
+});
diff --git a/console/tests/unit/models/file-test.js b/console/tests/unit/models/file-test.js
index f848f0fa..6af34894 100644
--- a/console/tests/unit/models/file-test.js
+++ b/console/tests/unit/models/file-test.js
@@ -1,5 +1,6 @@
import { module, test } from 'qunit';
import { setupTest } from '@fleetbase/console/tests/helpers';
+import Service from '@ember/service';
module('Unit | Model | file', function (hooks) {
setupTest(hooks);
@@ -11,3 +12,73 @@ module('Unit | Model | file', function (hooks) {
assert.ok(model);
});
});
+
+module('Unit | Model | file | type detection and download', function (hooks) {
+ setupTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.store = this.owner.lookup('service:store');
+ });
+
+ test('isVideo and isImage classify the content type, with negated companions', function (assert) {
+ const video = this.store.createRecord('file', { content_type: 'video/mp4' });
+ assert.true(video.isVideo);
+ assert.false(video.isNotVideo);
+ assert.false(video.isImage);
+ assert.true(video.isNotImage);
+
+ const image = this.store.createRecord('file', { content_type: 'image/png' });
+ assert.true(image.isImage);
+ assert.false(image.isNotImage);
+ assert.false(image.isVideo);
+ assert.true(image.isNotVideo);
+
+ const document = this.store.createRecord('file', { content_type: 'application/pdf' });
+ assert.false(document.isImage);
+ assert.false(document.isVideo);
+ assert.true(document.isNotImage);
+ assert.true(document.isNotVideo);
+ });
+
+ test('download delegates to the fetch service with the original filename and type', async function (assert) {
+ const downloads = [];
+ class FetchStub extends Service {
+ download(path, params, options) {
+ downloads.push({ path, params, options });
+ return Promise.resolve('downloaded');
+ }
+ }
+ this.owner.register('service:fetch', FetchStub);
+
+ const file = this.store.push({
+ data: { id: 'file_1', type: 'file', attributes: { original_filename: 'invoice.pdf', content_type: 'application/pdf' } },
+ });
+
+ const result = await file.download();
+
+ assert.strictEqual(result, 'downloaded');
+ assert.deepEqual(downloads, [
+ {
+ path: 'files/download',
+ params: { file: 'file_1' },
+ options: { fileName: 'invoice.pdf', mimeType: 'application/pdf' },
+ },
+ ]);
+ });
+
+ test('downloadFromApi navigates to the API download endpoint for this file', function (assert) {
+ const opened = [];
+ const originalOpen = window.open;
+ window.open = (url, target) => opened.push({ url, target });
+
+ try {
+ this.store.push({ data: { id: 'file_2', type: 'file' } }).downloadFromApi();
+ } finally {
+ window.open = originalOpen;
+ }
+
+ assert.strictEqual(opened.length, 1, 'the browser is sent to the download URL');
+ assert.ok(opened[0].url.endsWith('/files/download?file=file_2'), `the file id is in the URL (got ${opened[0].url})`);
+ assert.strictEqual(opened[0].target, '_self', 'in the same tab, so the download starts in place');
+ });
+});
diff --git a/console/tests/unit/models/group-test.js b/console/tests/unit/models/group-test.js
index 61b86095..9e27d608 100644
--- a/console/tests/unit/models/group-test.js
+++ b/console/tests/unit/models/group-test.js
@@ -11,3 +11,19 @@ module('Unit | Model | group', function (hooks) {
assert.ok(model);
});
});
+
+module('Unit | Model | group | members', function (hooks) {
+ setupTest(hooks);
+
+ test('membersList names every user in the group', function (assert) {
+ const store = this.owner.lookup('service:store');
+ const group = store.createRecord('group', { name: 'Dispatchers' });
+
+ assert.deepEqual(group.membersList, [], 'an empty group has no members');
+
+ group.users.pushObject(store.createRecord('user', { name: 'Ron' }));
+ group.users.pushObject(store.createRecord('user', { name: 'Sam' }));
+
+ assert.deepEqual(group.membersList, ['Ron', 'Sam']);
+ });
+});
diff --git a/console/tests/unit/models/notification-test.js b/console/tests/unit/models/notification-test.js
index 8bcc9b1a..c3c62260 100644
--- a/console/tests/unit/models/notification-test.js
+++ b/console/tests/unit/models/notification-test.js
@@ -1,6 +1,7 @@
import { module, test } from 'qunit';
import { setupTest } from '@fleetbase/console/tests/helpers';
+import { format } from 'date-fns';
module('Unit | Model | notification', function (hooks) {
setupTest(hooks);
@@ -12,3 +13,58 @@ module('Unit | Model | notification', function (hooks) {
assert.ok(model);
});
});
+
+module('Unit | Model | notification | read state', function (hooks) {
+ setupTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.store = this.owner.lookup('service:store');
+ });
+
+ test('an unread notification reports itself as unread', function (assert) {
+ const notification = this.store.createRecord('notification');
+
+ assert.false(notification.isRead);
+ assert.false(notification.read);
+ assert.true(notification.unread);
+ });
+
+ test('a notification with a read timestamp reports itself as read', function (assert) {
+ const readAt = new Date('2026-02-20T08:05:00Z');
+ const notification = this.store.createRecord('notification', { read_at: readAt });
+
+ assert.true(notification.isRead);
+ assert.true(notification.read);
+ assert.false(notification.unread);
+ assert.strictEqual(notification.readAt, format(readAt, 'yyyy-MM-dd HH:mm'));
+ });
+
+ test('markAsRead stamps the time and saves', async function (assert) {
+ const notification = this.store.push({ data: { id: 'n_1', type: 'notification' } });
+ let saved = 0;
+ notification.save = () => {
+ saved++;
+ return Promise.resolve(notification);
+ };
+
+ await notification.markAsRead();
+
+ assert.strictEqual(saved, 1, 'the change is persisted');
+ assert.true(notification.read_at instanceof Date, 'the read time is stamped');
+ assert.true(notification.isRead);
+ });
+
+ test('markAsRead is a no-op for an already read notification', async function (assert) {
+ const readAt = new Date('2026-02-20T08:05:00Z');
+ const notification = this.store.push({ data: { id: 'n_2', type: 'notification', attributes: { read_at: readAt } } });
+ let saved = 0;
+ notification.save = () => {
+ saved++;
+ return Promise.resolve(notification);
+ };
+
+ assert.strictEqual(await notification.markAsRead(), undefined);
+ assert.strictEqual(saved, 0, 'nothing is re-saved');
+ assert.strictEqual(notification.read_at.getTime(), readAt.getTime(), 'the original read time is kept');
+ });
+});
diff --git a/console/tests/unit/models/policy-test.js b/console/tests/unit/models/policy-test.js
index 5a9167e1..d9a2136c 100644
--- a/console/tests/unit/models/policy-test.js
+++ b/console/tests/unit/models/policy-test.js
@@ -11,3 +11,20 @@ module('Unit | Model | policy', function (hooks) {
assert.strictEqual(json.name, 'Dispatcher');
});
});
+
+module('Unit | Model | policy | permissions', function (hooks) {
+ setupTest(hooks);
+
+ test('toJSON serializes the record and permissionsArray materialises the relationship', function (assert) {
+ const store = this.owner.lookup('service:store');
+ const policy = store.createRecord('policy', { name: 'Dispatch policy' });
+
+ assert.strictEqual(typeof policy.toJSON(), 'object');
+ assert.deepEqual(policy.permissionsArray, []);
+
+ const permission = store.createRecord('permission', { name: 'orders.view' });
+ policy.permissions.pushObject(permission);
+
+ assert.deepEqual(policy.permissionsArray, [permission]);
+ });
+});
diff --git a/console/tests/unit/models/role-test.js b/console/tests/unit/models/role-test.js
index 49a2dc7e..2595db68 100644
--- a/console/tests/unit/models/role-test.js
+++ b/console/tests/unit/models/role-test.js
@@ -11,3 +11,21 @@ module('Unit | Model | role', function (hooks) {
assert.strictEqual(json.name, 'Administrator');
});
});
+
+module('Unit | Model | role | permissions', function (hooks) {
+ setupTest(hooks);
+
+ test('toJSON serializes the record and permissionsArray materialises the relationship', function (assert) {
+ const store = this.owner.lookup('service:store');
+ const role = store.createRecord('role', { name: 'Dispatcher' });
+
+ const json = role.toJSON();
+ assert.strictEqual(typeof json, 'object', 'a plain object is produced');
+ assert.deepEqual(role.permissionsArray, [], 'a role with no permissions yields an empty array');
+
+ const permission = store.createRecord('permission', { name: 'orders.view' });
+ role.permissions.pushObject(permission);
+
+ assert.deepEqual(role.permissionsArray, [permission], 'attached permissions are listed');
+ });
+});
diff --git a/console/tests/unit/models/template-query-test.js b/console/tests/unit/models/template-query-test.js
new file mode 100644
index 00000000..8ac8d088
--- /dev/null
+++ b/console/tests/unit/models/template-query-test.js
@@ -0,0 +1,29 @@
+import { module, test } from 'qunit';
+import { setupTest } from '@fleetbase/console/tests/helpers';
+
+module('Unit | Model | template-query | naming', function (hooks) {
+ setupTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.store = this.owner.lookup('service:store');
+ this.query = (attrs) => this.store.createRecord('template-query', attrs);
+ });
+
+ test('variableName slugifies the name into a token-safe identifier', function (assert) {
+ assert.strictEqual(this.query({ name: 'Total Orders' }).variableName, 'total_orders');
+ assert.strictEqual(this.query({ name: 'Driver / Vehicle count!' }).variableName, 'driver_vehicle_count');
+ assert.strictEqual(this.query({ name: ' Leading and trailing ' }).variableName, 'leading_and_trailing', 'padding is trimmed off the ends');
+ assert.strictEqual(this.query({}).variableName, '', 'an unnamed query has no variable');
+ });
+
+ test('variableToken wraps the variable name in braces', function (assert) {
+ assert.strictEqual(this.query({ name: 'Total Orders' }).variableToken, '{total_orders}');
+ assert.strictEqual(this.query({}).variableToken, '{}', 'an unnamed query still yields a well-formed token');
+ });
+
+ test('resourceTypeLabel shows only the class name from a namespaced type', function (assert) {
+ assert.strictEqual(this.query({ resource_type: 'Fleetbase\\FleetOps\\Models\\Order' }).resourceTypeLabel, 'Order');
+ assert.strictEqual(this.query({ resource_type: 'Order' }).resourceTypeLabel, 'Order', 'an unnamespaced type is used as-is');
+ assert.strictEqual(this.query({}).resourceTypeLabel, '', 'no type means no label');
+ });
+});
diff --git a/console/tests/unit/models/template-test.js b/console/tests/unit/models/template-test.js
new file mode 100644
index 00000000..5ff4b096
--- /dev/null
+++ b/console/tests/unit/models/template-test.js
@@ -0,0 +1,36 @@
+import { module, test } from 'qunit';
+import { setupTest } from '@fleetbase/console/tests/helpers';
+
+module('Unit | Model | template | presentation', function (hooks) {
+ setupTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.store = this.owner.lookup('service:store');
+ });
+
+ test('isDraft and isPublished read the status', function (assert) {
+ const draft = this.store.createRecord('template', { status: 'draft' });
+ assert.true(draft.isDraft);
+ assert.false(draft.isPublished);
+
+ const published = this.store.createRecord('template', { status: 'published' });
+ assert.false(published.isDraft);
+ assert.true(published.isPublished);
+
+ const archived = this.store.createRecord('template', { status: 'archived' });
+ assert.false(archived.isDraft);
+ assert.false(archived.isPublished);
+ });
+
+ test('dimensionLabel describes a custom size by its measurements', function (assert) {
+ const custom = this.store.createRecord('template', { paper_size: 'custom', width: 210, height: 297, unit: 'mm' });
+
+ assert.strictEqual(custom.dimensionLabel, '210 × 297 mm');
+ });
+
+ test('dimensionLabel describes a standard size by name and orientation', function (assert) {
+ const standard = this.store.createRecord('template', { paper_size: 'A4', orientation: 'portrait' });
+
+ assert.strictEqual(standard.dimensionLabel, 'A4 (portrait)');
+ });
+});
diff --git a/console/tests/unit/models/timestamps-test.js b/console/tests/unit/models/timestamps-test.js
new file mode 100644
index 00000000..f93ccca9
--- /dev/null
+++ b/console/tests/unit/models/timestamps-test.js
@@ -0,0 +1,53 @@
+import { module, test } from 'qunit';
+import { setupTest } from '@fleetbase/console/tests/helpers';
+import { format, formatDistanceToNow } from 'date-fns';
+
+/**
+ * Almost every model exposes the same family of timestamp getters over created_at and
+ * updated_at. The format strings differ per model, so they are spelled out here rather than
+ * derived — that way this table asserts the actual contract of each model instead of just
+ * mirroring whatever the code happens to do.
+ */
+const DATETIME = 'yyyy-MM-dd HH:mm';
+const SHORT = 'PP';
+
+const MODELS = [
+ { model: 'category', created: DATETIME, updated: DATETIME, short: SHORT },
+ { model: 'comment', created: DATETIME, updated: DATETIME },
+ { model: 'custom-field', created: DATETIME, updated: DATETIME },
+ { model: 'custom-field-value', created: DATETIME, updated: DATETIME },
+ { model: 'dashboard-widget', created: DATETIME, updated: DATETIME, short: SHORT },
+ { model: 'group', created: DATETIME, updated: DATETIME },
+ { model: 'policy', created: DATETIME, updated: DATETIME },
+ { model: 'role', created: DATETIME, updated: DATETIME, short: SHORT },
+ { model: 'template', created: DATETIME, updated: DATETIME, short: SHORT },
+ { model: 'template-query', created: DATETIME, updated: DATETIME, short: SHORT },
+ // The file model formats its updated stamp as a long date instead.
+ { model: 'file', created: DATETIME, updated: 'PPP' },
+];
+
+const CREATED_AT = new Date('2026-01-15T10:30:00Z');
+const UPDATED_AT = new Date('2026-02-20T08:05:00Z');
+
+module('Unit | Model | timestamp getters', function (hooks) {
+ setupTest(hooks);
+
+ MODELS.forEach(({ model, created, updated, short }) => {
+ test(`${model} formats created_at and updated_at`, function (assert) {
+ const record = this.owner.lookup('service:store').createRecord(model, {
+ created_at: CREATED_AT,
+ updated_at: UPDATED_AT,
+ });
+
+ assert.strictEqual(record.createdAt, format(CREATED_AT, created), 'createdAt');
+ assert.strictEqual(record.updatedAt, format(UPDATED_AT, updated), 'updatedAt');
+ assert.strictEqual(record.createdAgo, formatDistanceToNow(CREATED_AT), 'createdAgo is relative');
+ assert.strictEqual(record.updatedAgo, formatDistanceToNow(UPDATED_AT), 'updatedAgo is relative');
+
+ if (short) {
+ assert.strictEqual(record.createdAtShort, format(CREATED_AT, short), 'createdAtShort');
+ assert.strictEqual(record.updatedAtShort, format(UPDATED_AT, short), 'updatedAtShort');
+ }
+ });
+ });
+});