| 1 | import { test } from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | |
| 4 | import { activitySpan, chatActivity } from "./activity.ts"; |
| 5 | |
| 6 | const span = { from: "2026-10-08T18:00:00.000Z", until: "2026-10-09T18:00:00.000Z" }; |
| 7 | |
| 8 | test("messages, conversations with any, and who said how much, most first", () => { |
| 9 | const activity = chatActivity( |
| 10 | [ |
| 11 | { channel_id: "chn_general", author: "user:usr_ana", n: 70 }, |
| 12 | { channel_id: "chn_general", author: "agent:agt_margo", n: 15 }, |
| 13 | { channel_id: "chn_dev", author: "user:usr_bo", n: 30 }, |
| 14 | { channel_id: "chn_dev", author: "user:usr_ana", n: 5 }, |
| 15 | // A conversation with nothing in the span is not active. |
| 16 | { channel_id: "chn_quiet", author: "user:usr_bo", n: 0 }, |
| 17 | ], |
| 18 | span, |
| 19 | ); |
| 20 | assert.deepEqual(activity, { |
| 21 | ...span, |
| 22 | messages: 120, |
| 23 | channels: 2, |
| 24 | authors: [ |
| 25 | { key: "user:usr_ana", messages: 75 }, |
| 26 | { key: "user:usr_bo", messages: 30 }, |
| 27 | { key: "agent:agt_margo", messages: 15 }, |
| 28 | ], |
| 29 | }); |
| 30 | }); |
| 31 | |
| 32 | test("nothing said is zeros, not an error", () => { |
| 33 | assert.deepEqual(chatActivity([], span), { ...span, messages: 0, channels: 0, authors: [] }); |
| 34 | }); |
| 35 | |
| 36 | test("a span is two times in order", () => { |
| 37 | assert.equal(activitySpan(span.from, span.until)?.fromMs, Date.parse(span.from)); |
| 38 | assert.equal(activitySpan(span.until, span.from), null); |
| 39 | assert.equal(activitySpan("yesterday", span.until), null); |
| 40 | assert.equal(activitySpan(null, span.until), null); |
| 41 | }); |