| 27 | } |
| 28 | |
| 29 | function seedChatDb(db: ReturnType<typeof openBetterSqliteDatabase>): void { |
| 30 | db.exec(CHAT_DB_SCHEMA) |
| 31 | db.prepare( |
| 32 | `INSERT INTO meta (name, platform, type, imported_at, group_id, owner_id) |
| 33 | VALUES ('Chart Test Group', 'wechat', 'group', ?, 'g1', 'u_alice')` |
| 34 | ).run(unixTs('2026-06-03T00:00:00Z')) |
| 35 | |
| 36 | const insertMember = db.prepare( |
| 37 | `INSERT INTO member (platform_id, account_name, group_nickname) |
| 38 | VALUES (?, ?, ?)` |
| 39 | ) |
| 40 | insertMember.run('u_alice', 'Alice Account', 'Alice') |
| 41 | insertMember.run('u_bob', 'Bob Account', 'Bob') |
| 42 | insertMember.run('u_cara', 'Cara Account', 'Cara') |
| 43 | |
| 44 | const memberRows = db.prepare('SELECT id, group_nickname FROM member').all() as Array<{ |
| 45 | id: number |
| 46 | group_nickname: string |
| 47 | }> |
| 48 | const memberId = new Map(memberRows.map((row) => [row.group_nickname, row.id])) |
| 49 | const insertMessage = db.prepare( |
| 50 | `INSERT INTO message (sender_id, sender_account_name, sender_group_nickname, ts, type, content, platform_message_id) |
| 51 | VALUES (?, ?, ?, ?, ?, ?, ?)` |
| 52 | ) |
| 53 | const add = (name: 'Alice' | 'Bob' | 'Cara', ts: string, type: number, content: string) => { |
| 54 | const id = memberId.get(name) |
| 55 | assert.ok(id, `missing member id for ${name}`) |
| 56 | insertMessage.run(id, `${name} Account`, name, unixTs(ts), type, content, `${name}-${ts}`) |
| 57 | } |
| 58 | |
| 59 | add('Alice', '2026-06-01T09:00:00Z', 0, 'morning hello') |
| 60 | add('Alice', '2026-06-01T10:00:00Z', 0, 'standup note') |
| 61 | add('Alice', '2026-06-02T09:00:00Z', 1, '[图片]') |
| 62 | add('Alice', '2026-06-02T10:00:00Z', 0, 'follow up') |
| 63 | add('Bob', '2026-06-01T09:00:00Z', 0, 'first reply') |
| 64 | add('Bob', '2026-06-02T10:00:00Z', 0, 'second reply') |
| 65 | add('Bob', '2026-06-02T11:00:00Z', 0, 'third reply') |
| 66 | add('Cara', '2026-06-01T09:00:00Z', 0, 'other member') |
| 67 | add('Cara', '2026-06-03T12:00:00Z', 0, 'outside selected members') |
| 68 | } |
| 69 | |
| 70 | describe('render_chart integration with a real chat SQLite database', () => { |
| 71 | it('executes read-only SQL against chat tables and returns flexible chart payloads', async () => { |