/** * Unit tests for shared send path selection (pure logic mirror). * Run: node tests/mailbox-send-path.test.js */ const assert = require('assert'); const { normalizeMailbox, buildPath } = require('../utils/mailbox'); function resolveSendPath(args) { const mb = normalizeMailbox(args.mailbox); const onBehalf = args.onBehalfOf === true || args.onBehalfOf === 'true'; if (mb.kind === 'user' && !onBehalf) { return buildPath(mb, 'sendMail'); } return 'me/sendMail'; } assert.strictEqual(resolveSendPath({}), 'me/sendMail'); assert.strictEqual(resolveSendPath({ mailbox: 'me' }), 'me/sendMail'); assert.strictEqual( resolveSendPath({ mailbox: 'helpdesk@contoso.com' }), 'users/helpdesk@contoso.com/sendMail' ); assert.strictEqual( resolveSendPath({ mailbox: 'helpdesk@contoso.com', onBehalfOf: true }), 'me/sendMail' ); assert.strictEqual( resolveSendPath({ mailbox: 'helpdesk@contoso.com', onBehalfOf: 'true' }), 'me/sendMail' ); console.log('✅ send path selection'); console.log('\nAll mailbox-send-path tests passed.');