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): cover the chat-channel, user and category serializers
Ronald A. Richardson655dd32ef0b3
diff --git a/console/tests/unit/serializers/category-test.js b/console/tests/unit/serializers/category-test.jsindex a5c14045..1251afe4 100644--- a/console/tests/unit/serializers/category-test.js+++ b/console/tests/unit/serializers/category-test.js@@ -15,3 +15,27 @@ module('Unit | Serializer | category', function (hooks) {assert.notOk('subcategories' in json, 'subcategories is suppressed');});});++module('Unit | Serializer | category | relationship pruning', function (hooks) {+ setupTest(hooks);++ test('the parent and subcategories relationships are never sent back', function (assert) {+ const store = this.owner.lookup('service:store');+ const serializer = store.serializerFor('category');+ const json = {};++ assert.strictEqual(serializer.serializeBelongsTo({}, json, { key: 'parent' }), undefined, 'parent is skipped');+ assert.strictEqual(serializer.serializeHasMany({}, json, { key: 'subcategories' }), undefined, 'subcategories are skipped');+ assert.deepEqual(json, {}, 'neither wrote anything into the payload');+ });++ test('other relationships still serialize', function (assert) {+ const store = this.owner.lookup('service:store');+ const category = store.createRecord('category', { name: 'Parcels' });++ const json = category.serialize();++ assert.strictEqual(json.name, 'Parcels');+ assert.notOk(json.subcategories, 'the pruned relationships are absent');+ });+});diff --git a/console/tests/unit/serializers/chat-channel-test.js b/console/tests/unit/serializers/chat-channel-test.jsindex a69afba8..dbc79df2 100644--- a/console/tests/unit/serializers/chat-channel-test.js+++ b/console/tests/unit/serializers/chat-channel-test.js@@ -12,3 +12,67 @@ module('Unit | Serializer | chat-channel', function (hooks) {assert.notOk('title' in json, 'custom serialize omits other attributes');});});++module('Unit | Serializer | chat-channel | feed', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ this.store = this.owner.lookup('service:store');+ this.serializer = this.store.serializerFor('chat-channel');+ });++ test('serialize sends only the fields the API accepts', function (assert) {+ const channel = this.store.createRecord('chat-channel', { name: 'Dispatch', meta: { pinned: true }, title: 'ignored' });++ const json = channel.serialize();++ assert.deepEqual(json, { name: 'Dispatch', meta: { pinned: true } });+ });++ test('serializeItem materialises each feed entry into its own record type', function (assert) {+ const message = this.serializer.serializeItem({ type: 'message', created_at: '2026-01-01', data: { uuid: 'm_1' } });+ const log = this.serializer.serializeItem({ type: 'log', created_at: '2026-01-02', data: { uuid: 'l_1' } });+ const attachment = this.serializer.serializeItem({ type: 'attachment', created_at: '2026-01-03', data: { uuid: 'a_1' } });++ assert.strictEqual(message.record.constructor.modelName, 'chat-message');+ assert.strictEqual(message.record.id, 'm_1');+ assert.strictEqual(log.record.constructor.modelName, 'chat-log');+ assert.strictEqual(attachment.record.constructor.modelName, 'chat-attachment');+ assert.strictEqual(message.type, 'message', 'the rest of the entry is preserved');+ });++ test('an unrecognised feed entry type is dropped', function (assert) {+ assert.strictEqual(this.serializer.serializeItem({ type: 'not-a-type', data: {} }), null);+ });++ test('serializeFeed orders the entries oldest first', function (assert) {+ const feed = this.serializer.serializeFeed([+ { type: 'message', created_at: '2026-03-01', data: { uuid: 'm_2' } },+ { type: 'message', created_at: '2026-01-01', data: { uuid: 'm_1' } },+ { type: 'log', created_at: '2026-02-01', data: { uuid: 'l_1' } },+ ]);++ assert.deepEqual(+ feed.map((entry) => entry.record.id),+ ['m_1', 'l_1', 'm_2']+ );+ });++ test('serializeFeed with no entries yields an empty feed', function (assert) {+ assert.deepEqual(this.serializer.serializeFeed(), []);+ });++ test('normalize converts an incoming feed and leaves other payloads alone', function (assert) {+ const withFeed = this.serializer.normalize(this.store.modelFor('chat-channel'), {+ uuid: 'ch_1',+ name: 'Dispatch',+ feed: [{ type: 'message', created_at: '2026-01-01', data: { uuid: 'm_1' } }],+ });++ assert.strictEqual(withFeed.data.attributes.feed.length, 1);+ assert.strictEqual(withFeed.data.attributes.feed[0].record.id, 'm_1', 'the raw entry became a record');++ const withoutFeed = this.serializer.normalize(this.store.modelFor('chat-channel'), { uuid: 'ch_2', name: 'Ops' });+ assert.strictEqual(withoutFeed.data.id, 'ch_2', 'a payload with no feed normalizes normally');+ });+});diff --git a/console/tests/unit/serializers/user-test.js b/console/tests/unit/serializers/user-test.jsindex a9aaabac..c44b4bfe 100644--- a/console/tests/unit/serializers/user-test.js+++ b/console/tests/unit/serializers/user-test.js@@ -24,3 +24,61 @@ module('Unit | Serializer | user', function (hooks) {});});});++module('Unit | Serializer | user | payload hygiene', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ this.store = this.owner.lookup('service:store');+ this.serializer = this.store.serializerFor('user');+ });++ test('serialize never sends the password, verification flags or server timestamps', function (assert) {+ const user = this.store.createRecord('user', {+ name: 'Ron',+ email: '[email protected]',+ password: 'secret',+ email_verified_at: new Date(),+ phone_verified_at: new Date(),+ created_at: new Date(),+ updated_at: new Date(),+ deleted_at: new Date(),+ });++ const json = user.serialize();++ assert.strictEqual(json.name, 'Ron', 'the editable fields still go');+ for (const key of ['password', 'email_verified_at', 'phone_verified_at', 'created_at', 'updated_at', 'deleted_at']) {+ assert.notOk(key in json, `${key} is stripped`);+ }+ });++ test('a partial payload does not blank out fields on an already-loaded user', function (assert) {+ this.store.push({+ data: { id: 'user_1', type: 'user', attributes: { name: 'Ron', phone: '+15550001111', avatar_url: '/original.png' } },+ });++ const normalized = this.serializer.normalize(this.store.modelFor('user'), {+ uuid: 'user_1',+ name: 'Ron Richardson',+ phone: null,+ avatar_url: '/replaced.png',+ });++ assert.strictEqual(normalized.data.attributes.name, 'Ron Richardson', 'real values still apply');+ assert.notOk('phone' in normalized.data.attributes, 'a null does not wipe the loaded phone');+ assert.notOk('avatar_url' in normalized.data.attributes, 'the avatar is always left to the loaded record');+ });++ test('a payload for a user that is not loaded yet is applied in full', function (assert) {+ const normalized = this.serializer.normalize(this.store.modelFor('user'), {+ uuid: 'user_new',+ name: 'Sam',+ phone: null,+ avatar_url: '/avatar.png',+ });++ assert.strictEqual(normalized.data.attributes.name, 'Sam');+ assert.strictEqual(normalized.data.attributes.avatar_url, '/avatar.png', 'nothing to protect, so everything lands');+ });+});