// scripts/test/fetch-meeting-artifacts.test.js const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { runFetch } = require('../fetch-meeting-artifacts.js'); function makeClient(map) { return { api(path) { const h = map[path]; const builder = { query() { return builder; }, select() { return builder; }, version() { return builder; }, async get() { if (h === undefined) throw Object.assign(new Error('nf'), { statusCode: 404 }); return typeof h === 'function' ? h() : h; } }; return builder; } }; } describe('runFetch', () => { it('returns full artifact bundle for happy path', async () => { const userId = 'u@krah.de'; const client = makeClient({ [`/users/${userId}/events/E1`]: { id: 'E1', subject: 'Jour Fixe IT Team', seriesMasterId: 'S1', start: { dateTime: '2026-05-06T09:00:00.0000000', timeZone: 'UTC' }, end: { dateTime: '2026-05-06T10:00:00.0000000', timeZone: 'UTC' }, attendees: [{ emailAddress: { name: 'Christian Kauer', address: 'c.kauer@krah-gruppe.de' } }], body: { contentType: 'html', content: 'Join' } }, [`/users/${userId}/onlineMeetings`]: { value: [{ id: 'M1', joinWebUrl: 'https://teams.microsoft.com/l/meetup-join/19%3aXYZ/0' }] }, [`/users/${userId}/onlineMeetings/M1/transcripts`]: { value: [{ id: 'T1', createdDateTime: '2026-05-06T10:01:00Z' }] }, [`/users/${userId}/onlineMeetings/M1/transcripts/T1/content`]: 'WEBVTT\n\n00:00:01.000 --> 00:00:02.000\nHallo.\n', [`/users/${userId}/onlineMeetings/M1/aiInsights`]: { value: [{ id: 'I1', meetingNotes: [{ title: 'Topic', text: 'Notiz' }] }] }, [`/users/${userId}/onlineMeetings/M1/recordings`]: { value: [{ id: 'R1', recordingContentUrl: 'https://teams/play/R1', createdDateTime: '2026-05-06T10:30:00Z' }] } }); const result = await runFetch(client, userId, { o365Id: 'E1' }); assert.equal(result.meeting.id, 'E1'); assert.equal(result.meeting.seriesMasterId, 'S1'); assert.equal(result.meeting.onlineMeetingId, 'M1'); assert.ok(result.transcript.includes('Christian Kauer: Hallo.')); assert.equal(result.recap.id, 'I1'); assert.equal(result.recordingUrl, 'https://teams/play/R1'); }); it('handles missing transcript gracefully', async () => { const userId = 'u@krah.de'; const client = makeClient({ [`/users/${userId}/events/E1`]: { id: 'E1', subject: 'X', seriesMasterId: null, start: { dateTime: '2026-05-06T09:00:00.0000000' }, end: { dateTime: '2026-05-06T10:00:00.0000000' }, attendees: [], body: { contentType: 'html', content: 'J' } }, [`/users/${userId}/onlineMeetings`]: { value: [{ id: 'M1', joinWebUrl: 'https://teams.microsoft.com/l/meetup-join/19%3aabc/0' }] }, [`/users/${userId}/onlineMeetings/M1/transcripts`]: { value: [] }, [`/users/${userId}/onlineMeetings/M1/recordings`]: { value: [] } }); const result = await runFetch(client, userId, { o365Id: 'E1' }); assert.equal(result.transcript, null); assert.equal(result.recap, null); assert.equal(result.recordingUrl, null); }); it('returns error info when event has no teams join url', async () => { const userId = 'u@krah.de'; const client = makeClient({ [`/users/${userId}/events/E1`]: { id: 'E1', subject: 'X', seriesMasterId: null, start: { dateTime: '2026-05-06T09:00:00.0000000' }, end: { dateTime: '2026-05-06T10:00:00.0000000' }, attendees: [], body: { contentType: 'text', content: 'no join url here' } } }); const result = await runFetch(client, userId, { o365Id: 'E1' }); assert.equal(result.transcript, null); assert.equal(result.recap, null); assert.ok(result.warnings.some(w => /join url/i.test(w))); }); });