|
| 1 | +import { describe, expect, test } from 'bun:test' |
| 2 | + |
| 3 | +import { |
| 4 | + generateSendAttachmentScript, |
| 5 | + generateSendTextScript, |
| 6 | + generateSendWithAttachmentScript, |
| 7 | +} from '../src/utils/applescript' |
| 8 | + |
| 9 | +describe('iMessage service routing for buddy-based sends', () => { |
| 10 | + test('generateSendTextScript should explicitly target iMessage service', () => { |
| 11 | + const script = generateSendTextScript('user@example.com', 'hello') |
| 12 | + |
| 13 | + expect(script).toContain('set targetService to 1st service whose service type = iMessage') |
| 14 | + expect(script).toContain('set targetBuddy to buddy "user@example.com" of targetService') |
| 15 | + }) |
| 16 | + |
| 17 | + test('generateSendAttachmentScript should explicitly target iMessage service once', () => { |
| 18 | + const { script } = generateSendAttachmentScript('user@example.com', '/Users/me/Pictures/photo.jpg') |
| 19 | + |
| 20 | + const serviceMatches = script.match(/set targetService to 1st service whose service type = iMessage/g) ?? [] |
| 21 | + const buddyMatches = script.match(/set targetBuddy to buddy /g) ?? [] |
| 22 | + |
| 23 | + expect(serviceMatches).toHaveLength(1) |
| 24 | + expect(buddyMatches).toHaveLength(1) |
| 25 | + }) |
| 26 | + |
| 27 | + test('generateSendWithAttachmentScript should not duplicate buddy setup in attachment snippet', () => { |
| 28 | + const { script } = generateSendWithAttachmentScript('user@example.com', 'hello', '/tmp/photo.jpg') |
| 29 | + |
| 30 | + const serviceMatches = script.match(/set targetService to 1st service whose service type = iMessage/g) ?? [] |
| 31 | + const buddyMatches = script.match(/set targetBuddy to buddy /g) ?? [] |
| 32 | + |
| 33 | + expect(serviceMatches).toHaveLength(1) |
| 34 | + expect(buddyMatches).toHaveLength(1) |
| 35 | + expect(script).toContain('send "hello" to targetBuddy') |
| 36 | + expect(script).toContain('send theFile to targetBuddy') |
| 37 | + }) |
| 38 | +}) |
0 commit comments