Skip to content

Commit 8a4d95d

Browse files
authored
Merge pull request #41 from photon-hq/fix/clean-imessage-service-routing
refactor ♻️: clean up iMessage service routing fix and eliminate redundant buddy/chat setup
2 parents 0da0e8d + 9c64ac7 commit 8a4d95d

File tree

5 files changed

+497
-108
lines changed

5 files changed

+497
-108
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
})

bun.lock

Lines changed: 37 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)