const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { resolveOnlineMeeting, fetchTranscriptVtt, fetchAiInsights, fetchRecordingUrl } = require('../lib/graph-meetings.js'); function fakeClient(routes) { return { api(path) { const handler = routes[path]; const builder = { query() { return builder; }, select() { return builder; }, version() { return builder; }, get: async () => { if (handler === undefined) throw Object.assign(new Error('Not found'), { statusCode: 404 }); if (typeof handler === 'function') return handler(); return handler; } }; return builder; } }; } describe('resolveOnlineMeeting', () => { it('resolves meeting by joinWebUrl', async () => { const client = fakeClient({ "/users/u/onlineMeetings": { value: [{ id: 'M1', joinWebUrl: 'https://teams/j' }] } }); const m = await resolveOnlineMeeting(client, 'u', 'https://teams/j'); assert.equal(m.id, 'M1'); }); it('returns null when no meeting matches', async () => { const client = fakeClient({ "/users/u/onlineMeetings": { value: [] } }); const m = await resolveOnlineMeeting(client, 'u', 'https://teams/j'); assert.equal(m, null); }); }); describe('fetchTranscriptVtt', () => { it('returns latest transcript content as string', async () => { const client = fakeClient({ "/users/u/onlineMeetings/M1/transcripts": { value: [ { id: 'T1', createdDateTime: '2026-05-06T09:00:00Z' }, { id: 'T2', createdDateTime: '2026-05-06T10:00:00Z' } ] }, "/users/u/onlineMeetings/M1/transcripts/T2/content": 'WEBVTT\n\n00:00:01.000 --> 00:00:02.000\nY\n' }); const vtt = await fetchTranscriptVtt(client, 'u', 'M1'); assert.ok(vtt.startsWith('WEBVTT')); }); it('returns null when no transcripts exist', async () => { const client = fakeClient({ "/users/u/onlineMeetings/M1/transcripts": { value: [] } }); const vtt = await fetchTranscriptVtt(client, 'u', 'M1'); assert.equal(vtt, null); }); }); describe('fetchAiInsights', () => { it('returns insights when available', async () => { const client = fakeClient({ "/copilot/users/u/onlineMeetings/M1/aiInsights": { value: [{ id: 'I1' }] }, "/copilot/users/u/onlineMeetings/M1/aiInsights/I1": { id: 'I1', actionItems: [], meetingNotes: [], mentions: [] } }); const out = await fetchAiInsights(client, 'u', 'M1'); assert.ok(out); assert.equal(out.id, 'I1'); }); it('returns null on 404', async () => { const client = fakeClient({}); const out = await fetchAiInsights(client, 'u', 'M1'); assert.equal(out, null); }); }); describe('fetchRecordingUrl', () => { it('returns latest recording url', async () => { const client = fakeClient({ "/users/u/onlineMeetings/M1/recordings": { value: [{ id: 'R1', recordingContentUrl: 'https://teams/play/R1', createdDateTime: '2026-05-06T11:00:00Z' }] } }); const out = await fetchRecordingUrl(client, 'u', 'M1'); assert.equal(out, 'https://teams/play/R1'); }); it('returns null when no recording', async () => { const client = fakeClient({ "/users/u/onlineMeetings/M1/recordings": { value: [] } }); const out = await fetchRecordingUrl(client, 'u', 'M1'); assert.equal(out, null); }); it('returns null on permission denied', async () => { const client = fakeClient({}); const out = await fetchRecordingUrl(client, 'u', 'M1'); assert.equal(out, null); }); });