| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- 'use strict';
- const assert = require('assert/strict');
- const {
- MISSING_TIMESTAMP,
- conversationTimestamp,
- compareConversationRecency,
- sortConversationsByRecency,
- maxConversationTimestamp,
- } = require('../mcp/src/core/conversation-order');
- function main() {
- assert.equal(conversationTimestamp(null), MISSING_TIMESTAMP);
- assert.equal(conversationTimestamp(''), MISSING_TIMESTAMP);
- assert.equal(conversationTimestamp('not-a-time'), MISSING_TIMESTAMP);
- const mixed = [
- { id: 'private-old', channelType: 'private', lastMessageAt: '2026-08-04T08:00:00.000Z' },
- { id: 'group-new', channelType: 'group', lastMessageAt: '2026-08-04T10:00:00.000Z' },
- { id: 'private-invalid', channelType: 'private', lastMessageAt: 'not-a-time' },
- { id: 'group-empty', channelType: 'group', lastMessageAt: '' },
- { id: 'private-null', channelType: 'private', lastMessageAt: null },
- ];
- const sorted = sortConversationsByRecency(mixed);
- assert.deepEqual(sorted.map(item => item.id), [
- 'group-new',
- 'private-old',
- 'private-invalid',
- 'group-empty',
- 'private-null',
- ]);
- assert.deepEqual(mixed.map(item => item.id), [
- 'private-old',
- 'group-new',
- 'private-invalid',
- 'group-empty',
- 'private-null',
- ]);
- const sameTime = [
- { id: 'private-first', channelType: 'private', lastMessageAt: '2026-08-04T09:00:00.000Z' },
- { id: 'group-second', channelType: 'group', lastMessageAt: '2026-08-04T09:00:00.000Z' },
- { id: 'private-third', channelType: 'private', lastMessageAt: '2026-08-04T09:00:00.000Z' },
- ];
- assert.deepEqual(sortConversationsByRecency(sameTime).map(item => item.id), [
- 'private-first',
- 'group-second',
- 'private-third',
- ]);
- assert(compareConversationRecency(mixed[1], mixed[0]) < 0);
- assert(compareConversationRecency(mixed[2], mixed[3]) === 0);
- assert.equal(maxConversationTimestamp(
- null,
- 'not-a-time',
- '2026-08-04T08:00:00.000Z',
- '2026-08-04T10:00:00.000Z',
- '2026-08-04T09:00:00.000Z',
- ), '2026-08-04T10:00:00.000Z');
- assert.equal(maxConversationTimestamp(['', null, 'not-a-time']), null);
- process.stdout.write(`${JSON.stringify({ status: 'ok', checks: 6 }, null, 2)}\n`);
- }
- try { main(); }
- catch (error) {
- process.stderr.write(`${error.stack || error.message}\n`);
- process.exit(1);
- }
|