(url, options = {})
| 73 | test('fetchMicrosoftMailboxMessages 会回退到可用的 token 策略并保留邮箱夹信息', async () => { |
| 74 | const requests = []; |
| 75 | const fetchImpl = async (url, options = {}) => { |
| 76 | requests.push({ url, options }); |
| 77 | if (String(url).includes('/oauth2/v2.0/token')) { |
| 78 | const params = new URLSearchParams(String(options.body || '')); |
| 79 | if (String(url).includes('/common/') && params.get('scope')?.includes('Mail.Read')) { |
| 80 | return { |
| 81 | ok: false, |
| 82 | status: 400, |
| 83 | statusText: 'Bad Request', |
| 84 | text: async () => JSON.stringify({ error_description: 'common delegated failed' }), |
| 85 | }; |
| 86 | } |
| 87 | return { |
| 88 | ok: true, |
| 89 | json: async () => ({ |
| 90 | access_token: 'access-token-1', |
| 91 | refresh_token: 'refresh-token-next', |
| 92 | }), |
| 93 | }; |
| 94 | } |
| 95 | |
| 96 | assert.match(String(url), /graph\.microsoft\.com\/v1\.0\/me\/mailFolders\/junkemail\/messages/); |
| 97 | return { |
| 98 | ok: true, |
| 99 | json: async () => ({ |
| 100 | value: [ |
| 101 | { |
| 102 | from: { emailAddress: { address: 'noreply@openai.com' } }, |
| 103 | subject: 'OpenAI verification', |
| 104 | bodyPreview: 'Use 445566 to continue', |
| 105 | receivedDateTime: '2026-04-14T10:06:00.000Z', |
| 106 | id: 'mail-1', |
| 107 | }, |
| 108 | ], |
| 109 | }), |
| 110 | }; |
| 111 | }; |
| 112 | |
| 113 | const result = await fetchMicrosoftMailboxMessages({ |
| 114 | clientId: 'client-1', |
no outgoing calls
no test coverage detected