import { describe, expect, it } from 'vitest'; import { buildBrowserCommand, GmailClient } from '../src/gmail/client.js'; describe('GmailClient', () => { it('uses PowerShell to open Windows OAuth URLs without splitting query parameters', () => { const url = 'https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&response_type=code'; expect(buildBrowserCommand(url, 'win32')).toEqual({ file: 'powershell.exe', args: ['-NoProfile', '-Command', 'Start-Process -FilePath $args[0]', url] }); }); it('loads HTML messages from the configured Gmail label', async () => { const calls: string[] = []; const gmail = { users: { labels: { list: async () => ({ data: { labels: [{ id: 'Label_1', name: 'Newsletters' }] } }) }, messages: { list: async (_params: unknown) => { calls.push('list'); return { data: { messages: [{ id: 'msg-1' }] } }; }, get: async () => { calls.push('get'); return { data: { id: 'msg-1', payload: { headers: [ { name: 'Message-ID', value: '' }, { name: 'From', value: 'Weekly ' }, { name: 'Date', value: 'Sat, 16 May 2026 10:00:00 -0500' } ], parts: [ { mimeType: 'text/html', body: { data: Buffer.from( '

Python

Post' ).toString('base64url') } } ] } } }; } } } }; const messages = await new GmailClient(gmail).fetchMessages('Newsletters', { maxResults: 5 }); expect(calls).toEqual(['list', 'get']); expect(messages).toEqual([ { id: 'msg-1', messageId: '', from: 'Weekly ', date: '2026-05-16T15:00:00.000Z', subject: '', html: '

Python

Post', headers: { date: 'Sat, 16 May 2026 10:00:00 -0500', from: 'Weekly ', listId: undefined, messageId: '', subject: '' } } ]); }); });