agent-messenger 2.10.0 → 2.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/dist/package.json +1 -1
- package/dist/src/platforms/teams/token-extractor.d.ts.map +1 -1
- package/dist/src/platforms/teams/token-extractor.js +15 -2
- package/dist/src/platforms/teams/token-extractor.js.map +1 -1
- package/dist/src/shared/chromium/decryptor.d.ts +6 -0
- package/dist/src/shared/chromium/decryptor.d.ts.map +1 -1
- package/dist/src/shared/chromium/decryptor.js +26 -6
- package/dist/src/shared/chromium/decryptor.js.map +1 -1
- package/e2e/channeltalk.e2e.test.ts +13 -13
- package/e2e/channeltalkbot.e2e.test.ts +13 -13
- package/e2e/discord.e2e.test.ts +24 -24
- package/e2e/discordbot.e2e.test.ts +16 -16
- package/e2e/instagram.e2e.test.ts +10 -10
- package/e2e/kakaotalk.e2e.test.ts +7 -7
- package/e2e/line.e2e.test.ts +8 -8
- package/e2e/slack.e2e.test.ts +34 -34
- package/e2e/slackbot.e2e.test.ts +14 -14
- package/e2e/teams.e2e.test.ts +23 -23
- package/e2e/telegram.e2e.test.ts +8 -8
- package/e2e/webex.e2e.test.ts +14 -14
- package/e2e/whatsapp.e2e.test.ts +8 -8
- package/e2e/whatsappbot.e2e.test.ts +6 -6
- package/package.json +1 -1
- package/skills/agent-channeltalk/SKILL.md +1 -1
- package/skills/agent-channeltalkbot/SKILL.md +1 -1
- package/skills/agent-discord/SKILL.md +1 -1
- package/skills/agent-discordbot/SKILL.md +1 -1
- package/skills/agent-instagram/SKILL.md +1 -1
- package/skills/agent-kakaotalk/SKILL.md +1 -1
- package/skills/agent-line/SKILL.md +1 -1
- package/skills/agent-slack/SKILL.md +1 -1
- package/skills/agent-slackbot/SKILL.md +1 -1
- package/skills/agent-teams/SKILL.md +1 -1
- package/skills/agent-telegram/SKILL.md +1 -1
- package/skills/agent-webex/SKILL.md +1 -1
- package/skills/agent-wechatbot/SKILL.md +1 -1
- package/skills/agent-whatsapp/SKILL.md +1 -1
- package/skills/agent-whatsappbot/SKILL.md +1 -1
- package/src/platforms/channeltalk/client.test.ts +26 -26
- package/src/platforms/channeltalk/commands/auth.test.ts +16 -16
- package/src/platforms/channeltalk/commands/bot.test.ts +2 -2
- package/src/platforms/channeltalk/commands/chat.test.ts +3 -3
- package/src/platforms/channeltalk/commands/group.test.ts +4 -4
- package/src/platforms/channeltalk/commands/manager.test.ts +2 -2
- package/src/platforms/channeltalk/commands/message.test.ts +17 -17
- package/src/platforms/channeltalk/commands/snapshot.test.ts +7 -7
- package/src/platforms/channeltalk/commands/whoami.test.ts +3 -3
- package/src/platforms/channeltalk/credential-manager.test.ts +18 -18
- package/src/platforms/channeltalk/ensure-auth.test.ts +5 -5
- package/src/platforms/channeltalk/index.test.ts +23 -23
- package/src/platforms/channeltalk/token-extractor.test.ts +21 -21
- package/src/platforms/channeltalk/types.test.ts +12 -12
- package/src/platforms/channeltalkbot/client.test.ts +14 -14
- package/src/platforms/channeltalkbot/commands/auth.test.ts +16 -16
- package/src/platforms/channeltalkbot/commands/bot.test.ts +6 -6
- package/src/platforms/channeltalkbot/commands/chat.test.ts +9 -9
- package/src/platforms/channeltalkbot/commands/group.test.ts +6 -6
- package/src/platforms/channeltalkbot/commands/manager.test.ts +3 -3
- package/src/platforms/channeltalkbot/commands/message.test.ts +10 -10
- package/src/platforms/channeltalkbot/commands/snapshot.test.ts +7 -7
- package/src/platforms/channeltalkbot/commands/whoami.test.ts +4 -4
- package/src/platforms/channeltalkbot/credential-manager.test.ts +27 -27
- package/src/platforms/channeltalkbot/index.test.ts +15 -15
- package/src/platforms/discord/client.test.ts +28 -28
- package/src/platforms/discord/commands/auth.test.ts +7 -7
- package/src/platforms/discord/commands/channel.test.ts +7 -7
- package/src/platforms/discord/commands/dm.test.ts +4 -4
- package/src/platforms/discord/commands/file.test.ts +4 -4
- package/src/platforms/discord/commands/friend.test.ts +6 -6
- package/src/platforms/discord/commands/member.test.ts +5 -5
- package/src/platforms/discord/commands/mention.test.ts +5 -5
- package/src/platforms/discord/commands/message.test.ts +9 -9
- package/src/platforms/discord/commands/note.test.ts +6 -6
- package/src/platforms/discord/commands/profile.test.ts +4 -4
- package/src/platforms/discord/commands/reaction.test.ts +5 -5
- package/src/platforms/discord/commands/server.test.ts +7 -7
- package/src/platforms/discord/commands/snapshot.test.ts +6 -6
- package/src/platforms/discord/commands/thread.test.ts +6 -6
- package/src/platforms/discord/commands/user.test.ts +5 -5
- package/src/platforms/discord/commands/whoami.test.ts +6 -6
- package/src/platforms/discord/credential-manager.test.ts +16 -16
- package/src/platforms/discord/ensure-auth.test.ts +8 -8
- package/src/platforms/discord/index.test.ts +17 -17
- package/src/platforms/discord/listener.test.ts +33 -33
- package/src/platforms/discord/token-extractor.test.ts +53 -53
- package/src/platforms/discord/types.test.ts +26 -26
- package/src/platforms/discordbot/client.test.ts +31 -31
- package/src/platforms/discordbot/commands/auth.test.ts +18 -18
- package/src/platforms/discordbot/commands/channel.test.ts +11 -11
- package/src/platforms/discordbot/commands/file.test.ts +7 -7
- package/src/platforms/discordbot/commands/message.test.ts +25 -25
- package/src/platforms/discordbot/commands/reaction.test.ts +6 -6
- package/src/platforms/discordbot/commands/server.test.ts +12 -12
- package/src/platforms/discordbot/commands/snapshot.test.ts +13 -13
- package/src/platforms/discordbot/commands/thread.test.ts +10 -10
- package/src/platforms/discordbot/commands/user.test.ts +9 -9
- package/src/platforms/discordbot/commands/whoami.test.ts +4 -4
- package/src/platforms/discordbot/credential-manager.test.ts +28 -28
- package/src/platforms/instagram/client.test.ts +18 -18
- package/src/platforms/instagram/commands/auth.test.ts +11 -11
- package/src/platforms/instagram/commands/chat.test.ts +6 -6
- package/src/platforms/instagram/commands/message.test.ts +11 -11
- package/src/platforms/instagram/commands/shared.test.ts +12 -12
- package/src/platforms/instagram/commands/whoami.test.ts +3 -3
- package/src/platforms/instagram/credential-manager.test.ts +21 -21
- package/src/platforms/instagram/ensure-auth.test.ts +4 -4
- package/src/platforms/instagram/index.test.ts +9 -9
- package/src/platforms/instagram/listener.test.ts +8 -8
- package/src/platforms/instagram/token-extractor.test.ts +35 -35
- package/src/platforms/kakaotalk/client.test.ts +33 -33
- package/src/platforms/kakaotalk/commands/auth.test.ts +11 -11
- package/src/platforms/kakaotalk/commands/chat.test.ts +6 -6
- package/src/platforms/kakaotalk/commands/message.test.ts +7 -7
- package/src/platforms/kakaotalk/commands/whoami.test.ts +5 -5
- package/src/platforms/kakaotalk/credential-manager.test.ts +15 -15
- package/src/platforms/kakaotalk/index.test.ts +15 -15
- package/src/platforms/kakaotalk/listener.test.ts +17 -17
- package/src/platforms/line/client.test.ts +17 -17
- package/src/platforms/line/commands/auth.test.ts +8 -8
- package/src/platforms/line/commands/chat.test.ts +7 -7
- package/src/platforms/line/commands/friend.test.ts +6 -6
- package/src/platforms/line/commands/message.test.ts +7 -7
- package/src/platforms/line/commands/whoami.test.ts +6 -6
- package/src/platforms/line/credential-manager.test.ts +17 -17
- package/src/platforms/line/index.test.ts +10 -10
- package/src/platforms/line/listener.test.ts +15 -15
- package/src/platforms/line/types.test.ts +14 -14
- package/src/platforms/slack/cli.test.ts +8 -8
- package/src/platforms/slack/client.test.ts +151 -151
- package/src/platforms/slack/commands/activity.test.ts +13 -13
- package/src/platforms/slack/commands/auth.test.ts +34 -34
- package/src/platforms/slack/commands/bookmark.test.ts +9 -9
- package/src/platforms/slack/commands/channel.test.ts +17 -17
- package/src/platforms/slack/commands/drafts.test.ts +7 -7
- package/src/platforms/slack/commands/emoji.test.ts +3 -3
- package/src/platforms/slack/commands/file.test.ts +12 -12
- package/src/platforms/slack/commands/message.test.ts +19 -19
- package/src/platforms/slack/commands/pin.test.ts +7 -7
- package/src/platforms/slack/commands/reaction.test.ts +10 -10
- package/src/platforms/slack/commands/reminder.test.ts +9 -9
- package/src/platforms/slack/commands/saved.test.ts +7 -7
- package/src/platforms/slack/commands/sections.test.ts +5 -5
- package/src/platforms/slack/commands/snapshot.test.ts +13 -13
- package/src/platforms/slack/commands/unread.test.ts +6 -6
- package/src/platforms/slack/commands/user.test.ts +10 -10
- package/src/platforms/slack/commands/usergroup.test.ts +15 -15
- package/src/platforms/slack/commands/whoami.test.ts +6 -6
- package/src/platforms/slack/commands/workspace.test.ts +26 -26
- package/src/platforms/slack/credential-manager.test.ts +14 -14
- package/src/platforms/slack/ensure-auth.test.ts +21 -21
- package/src/platforms/slack/index.test.ts +12 -12
- package/src/platforms/slack/listener.test.ts +17 -17
- package/src/platforms/slack/token-extractor-node.test.ts +2 -2
- package/src/platforms/slack/token-extractor.test.ts +37 -37
- package/src/platforms/slack/types.test.ts +21 -21
- package/src/platforms/slackbot/client.test.ts +22 -22
- package/src/platforms/slackbot/commands/auth.test.ts +14 -14
- package/src/platforms/slackbot/commands/channel.test.ts +7 -7
- package/src/platforms/slackbot/commands/message.test.ts +13 -13
- package/src/platforms/slackbot/commands/reaction.test.ts +6 -6
- package/src/platforms/slackbot/commands/user.test.ts +7 -7
- package/src/platforms/slackbot/commands/whoami.test.ts +4 -4
- package/src/platforms/slackbot/credential-manager.test.ts +22 -22
- package/src/platforms/slackbot/types.test.ts +7 -7
- package/src/platforms/teams/client.test.ts +30 -30
- package/src/platforms/teams/commands/auth.test.ts +8 -8
- package/src/platforms/teams/commands/channel.test.ts +7 -7
- package/src/platforms/teams/commands/file.test.ts +4 -4
- package/src/platforms/teams/commands/message.test.ts +5 -5
- package/src/platforms/teams/commands/reaction.test.ts +4 -4
- package/src/platforms/teams/commands/snapshot.test.ts +7 -7
- package/src/platforms/teams/commands/team.test.ts +8 -8
- package/src/platforms/teams/commands/user.test.ts +4 -4
- package/src/platforms/teams/commands/whoami.test.ts +6 -6
- package/src/platforms/teams/credential-manager.test.ts +17 -17
- package/src/platforms/teams/ensure-auth.test.ts +13 -13
- package/src/platforms/teams/index.test.ts +15 -15
- package/src/platforms/teams/token-extractor.test.ts +219 -145
- package/src/platforms/teams/token-extractor.ts +13 -2
- package/src/platforms/teams/types.test.ts +26 -26
- package/src/platforms/telegram/app-config.test.ts +4 -4
- package/src/platforms/telegram/chat-utils.test.ts +12 -12
- package/src/platforms/telegram/client.test.ts +4 -4
- package/src/platforms/telegram/commands/auth.test.ts +16 -16
- package/src/platforms/telegram/commands/chat.test.ts +9 -9
- package/src/platforms/telegram/commands/message.test.ts +6 -6
- package/src/platforms/telegram/commands/shared.test.ts +3 -3
- package/src/platforms/telegram/commands/whoami.test.ts +3 -3
- package/src/platforms/telegram/credential-manager.test.ts +10 -10
- package/src/platforms/telegram/types.test.ts +6 -6
- package/src/platforms/webex/app-config.test.ts +8 -8
- package/src/platforms/webex/cli.test.ts +5 -5
- package/src/platforms/webex/client.test.ts +65 -65
- package/src/platforms/webex/commands/auth.test.ts +18 -18
- package/src/platforms/webex/commands/member.test.ts +5 -5
- package/src/platforms/webex/commands/message.test.ts +12 -12
- package/src/platforms/webex/commands/snapshot.test.ts +5 -5
- package/src/platforms/webex/commands/space.test.ts +10 -10
- package/src/platforms/webex/commands/whoami.test.ts +6 -6
- package/src/platforms/webex/credential-manager.test.ts +22 -22
- package/src/platforms/webex/encryption.test.ts +4 -4
- package/src/platforms/webex/ensure-auth.test.ts +5 -5
- package/src/platforms/webex/index.test.ts +5 -5
- package/src/platforms/webex/markdown-to-html.test.ts +33 -33
- package/src/platforms/webex/token-extractor.test.ts +23 -23
- package/src/platforms/webex/types.test.ts +27 -27
- package/src/platforms/wechatbot/client.test.ts +27 -27
- package/src/platforms/wechatbot/commands/auth.test.ts +15 -15
- package/src/platforms/wechatbot/commands/message.test.ts +8 -8
- package/src/platforms/wechatbot/commands/template.test.ts +9 -9
- package/src/platforms/wechatbot/commands/user.test.ts +7 -7
- package/src/platforms/wechatbot/commands/whoami.test.ts +5 -5
- package/src/platforms/wechatbot/credential-manager.test.ts +18 -18
- package/src/platforms/wechatbot/index.test.ts +10 -10
- package/src/platforms/wechatbot/types.test.ts +25 -25
- package/src/platforms/whatsapp/commands/auth.test.ts +13 -13
- package/src/platforms/whatsapp/commands/chat.test.ts +8 -8
- package/src/platforms/whatsapp/commands/message.test.ts +10 -10
- package/src/platforms/whatsapp/commands/whoami.test.ts +3 -3
- package/src/platforms/whatsapp/credential-manager.test.ts +23 -23
- package/src/platforms/whatsapp/ensure-auth.test.ts +4 -4
- package/src/platforms/whatsapp/index.test.ts +8 -8
- package/src/platforms/whatsapp/types.test.ts +42 -42
- package/src/platforms/whatsappbot/client.test.ts +27 -27
- package/src/platforms/whatsappbot/commands/auth.test.ts +14 -14
- package/src/platforms/whatsappbot/commands/message.test.ts +16 -16
- package/src/platforms/whatsappbot/commands/template.test.ts +9 -9
- package/src/platforms/whatsappbot/commands/whoami.test.ts +5 -5
- package/src/platforms/whatsappbot/credential-manager.test.ts +18 -18
- package/src/platforms/whatsappbot/index.test.ts +7 -7
- package/src/platforms/whatsappbot/types.test.ts +18 -18
- package/src/shared/chromium/browsers.test.ts +22 -22
- package/src/shared/chromium/cookie-reader.test.ts +13 -13
- package/src/shared/chromium/decryptor.test.ts +97 -32
- package/src/shared/chromium/decryptor.ts +27 -6
- package/src/shared/utils/concurrency.test.ts +6 -6
- package/src/shared/utils/derived-key-cache.test.ts +11 -11
- package/src/tui/utils.test.ts +31 -31
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, mock,
|
|
1
|
+
import { beforeEach, describe, expect, mock, it } from 'bun:test'
|
|
2
2
|
|
|
3
3
|
const mockSendTextMessage = mock(() =>
|
|
4
4
|
Promise.resolve({
|
|
@@ -64,7 +64,7 @@ describe('message commands', () => {
|
|
|
64
64
|
})
|
|
65
65
|
|
|
66
66
|
describe('sendAction', () => {
|
|
67
|
-
|
|
67
|
+
it('sends a text message and returns result', async () => {
|
|
68
68
|
const result = await sendAction('+1234567890', 'Hello!', {})
|
|
69
69
|
|
|
70
70
|
expect(result.messaging_product).toBe('whatsapp')
|
|
@@ -73,7 +73,7 @@ describe('message commands', () => {
|
|
|
73
73
|
expect(mockSendTextMessage).toHaveBeenCalledWith('+1234567890', 'Hello!')
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
it('returns error when client throws', async () => {
|
|
77
77
|
mockSendTextMessage.mockImplementationOnce(() => Promise.reject(new Error('Network error')))
|
|
78
78
|
|
|
79
79
|
const result = await sendAction('+1234567890', 'Hello!', {})
|
|
@@ -83,7 +83,7 @@ describe('message commands', () => {
|
|
|
83
83
|
})
|
|
84
84
|
|
|
85
85
|
describe('sendTemplateAction', () => {
|
|
86
|
-
|
|
86
|
+
it('sends a template message with default language', async () => {
|
|
87
87
|
const result = await sendTemplateAction('+1234567890', 'hello_world', {})
|
|
88
88
|
|
|
89
89
|
expect(result.messaging_product).toBe('whatsapp')
|
|
@@ -91,14 +91,14 @@ describe('message commands', () => {
|
|
|
91
91
|
expect(mockSendTemplateMessage).toHaveBeenCalledWith('+1234567890', 'hello_world', 'en_US', undefined)
|
|
92
92
|
})
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
it('sends a template message with custom language', async () => {
|
|
95
95
|
const result = await sendTemplateAction('+1234567890', 'hello_world', { language: 'pt_BR' })
|
|
96
96
|
|
|
97
97
|
expect(mockSendTemplateMessage).toHaveBeenCalledWith('+1234567890', 'hello_world', 'pt_BR', undefined)
|
|
98
98
|
expect(result.error).toBeUndefined()
|
|
99
99
|
})
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
it('parses and passes components JSON', async () => {
|
|
102
102
|
const components = [{ type: 'body', parameters: [{ type: 'text', text: 'World' }] }]
|
|
103
103
|
const result = await sendTemplateAction('+1234567890', 'hello_world', {
|
|
104
104
|
components: JSON.stringify(components),
|
|
@@ -108,7 +108,7 @@ describe('message commands', () => {
|
|
|
108
108
|
expect(result.error).toBeUndefined()
|
|
109
109
|
})
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
it('returns error for invalid components JSON', async () => {
|
|
112
112
|
const result = await sendTemplateAction('+1234567890', 'hello_world', {
|
|
113
113
|
components: 'not-valid-json',
|
|
114
114
|
})
|
|
@@ -116,7 +116,7 @@ describe('message commands', () => {
|
|
|
116
116
|
expect(result.error).toBe('Invalid --components JSON')
|
|
117
117
|
})
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
it('returns error when client throws', async () => {
|
|
120
120
|
mockSendTemplateMessage.mockImplementationOnce(() => Promise.reject(new Error('Template not found')))
|
|
121
121
|
|
|
122
122
|
const result = await sendTemplateAction('+1234567890', 'missing_template', {})
|
|
@@ -126,7 +126,7 @@ describe('message commands', () => {
|
|
|
126
126
|
})
|
|
127
127
|
|
|
128
128
|
describe('sendReactionAction', () => {
|
|
129
|
-
|
|
129
|
+
it('sends a reaction and returns result', async () => {
|
|
130
130
|
const result = await sendReactionAction('+1234567890', 'wamid.msg123', '👍', {})
|
|
131
131
|
|
|
132
132
|
expect(result.messaging_product).toBe('whatsapp')
|
|
@@ -134,7 +134,7 @@ describe('message commands', () => {
|
|
|
134
134
|
expect(mockSendReaction).toHaveBeenCalledWith('+1234567890', 'wamid.msg123', '👍')
|
|
135
135
|
})
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
it('returns error when client throws', async () => {
|
|
138
138
|
mockSendReaction.mockImplementationOnce(() => Promise.reject(new Error('Message not found')))
|
|
139
139
|
|
|
140
140
|
const result = await sendReactionAction('+1234567890', 'wamid.bad', '👍', {})
|
|
@@ -144,7 +144,7 @@ describe('message commands', () => {
|
|
|
144
144
|
})
|
|
145
145
|
|
|
146
146
|
describe('sendImageAction', () => {
|
|
147
|
-
|
|
147
|
+
it('sends an image message and returns result', async () => {
|
|
148
148
|
const result = await sendImageAction('+1234567890', 'https://example.com/image.jpg', {})
|
|
149
149
|
|
|
150
150
|
expect(result.messaging_product).toBe('whatsapp')
|
|
@@ -152,14 +152,14 @@ describe('message commands', () => {
|
|
|
152
152
|
expect(mockSendImageMessage).toHaveBeenCalledWith('+1234567890', 'https://example.com/image.jpg', undefined)
|
|
153
153
|
})
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
it('passes caption when provided', async () => {
|
|
156
156
|
const result = await sendImageAction('+1234567890', 'https://example.com/image.jpg', { caption: 'My photo' })
|
|
157
157
|
|
|
158
158
|
expect(mockSendImageMessage).toHaveBeenCalledWith('+1234567890', 'https://example.com/image.jpg', 'My photo')
|
|
159
159
|
expect(result.error).toBeUndefined()
|
|
160
160
|
})
|
|
161
161
|
|
|
162
|
-
|
|
162
|
+
it('returns error when client throws', async () => {
|
|
163
163
|
mockSendImageMessage.mockImplementationOnce(() => Promise.reject(new Error('Invalid URL')))
|
|
164
164
|
|
|
165
165
|
const result = await sendImageAction('+1234567890', 'bad-url', {})
|
|
@@ -169,7 +169,7 @@ describe('message commands', () => {
|
|
|
169
169
|
})
|
|
170
170
|
|
|
171
171
|
describe('sendDocumentAction', () => {
|
|
172
|
-
|
|
172
|
+
it('sends a document message and returns result', async () => {
|
|
173
173
|
const result = await sendDocumentAction('+1234567890', 'https://example.com/doc.pdf', {})
|
|
174
174
|
|
|
175
175
|
expect(result.messaging_product).toBe('whatsapp')
|
|
@@ -182,7 +182,7 @@ describe('message commands', () => {
|
|
|
182
182
|
)
|
|
183
183
|
})
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
it('passes filename and caption when provided', async () => {
|
|
186
186
|
const result = await sendDocumentAction('+1234567890', 'https://example.com/doc.pdf', {
|
|
187
187
|
filename: 'report.pdf',
|
|
188
188
|
caption: 'Monthly report',
|
|
@@ -197,7 +197,7 @@ describe('message commands', () => {
|
|
|
197
197
|
expect(result.error).toBeUndefined()
|
|
198
198
|
})
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
it('returns error when client throws', async () => {
|
|
201
201
|
mockSendDocumentMessage.mockImplementationOnce(() => Promise.reject(new Error('Upload failed')))
|
|
202
202
|
|
|
203
203
|
const result = await sendDocumentAction('+1234567890', 'https://example.com/doc.pdf', {})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, mock,
|
|
1
|
+
import { beforeEach, describe, expect, mock, it } from 'bun:test'
|
|
2
2
|
|
|
3
3
|
import type { WhatsAppBotTemplate } from '../types'
|
|
4
4
|
|
|
@@ -46,7 +46,7 @@ describe('template commands', () => {
|
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
describe('listAction', () => {
|
|
49
|
-
|
|
49
|
+
it('returns all templates', async () => {
|
|
50
50
|
const result = await listAction({})
|
|
51
51
|
|
|
52
52
|
expect(result.templates).toHaveLength(2)
|
|
@@ -55,28 +55,28 @@ describe('template commands', () => {
|
|
|
55
55
|
expect(mockListTemplates).toHaveBeenCalledWith(undefined)
|
|
56
56
|
})
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
it('passes limit when provided', async () => {
|
|
59
59
|
const result = await listAction({ limit: '1' })
|
|
60
60
|
|
|
61
61
|
expect(mockListTemplates).toHaveBeenCalledWith({ limit: 1 })
|
|
62
62
|
expect(result.error).toBeUndefined()
|
|
63
63
|
})
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
it('returns error for invalid limit', async () => {
|
|
66
66
|
const result = await listAction({ limit: 'abc' })
|
|
67
67
|
|
|
68
68
|
expect(result.error).toBeDefined()
|
|
69
69
|
expect(result.error).toContain('Invalid --limit')
|
|
70
70
|
})
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
it('returns error for zero limit', async () => {
|
|
73
73
|
const result = await listAction({ limit: '0' })
|
|
74
74
|
|
|
75
75
|
expect(result.error).toBeDefined()
|
|
76
76
|
expect(result.error).toContain('Invalid --limit')
|
|
77
77
|
})
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
it('returns error when client throws', async () => {
|
|
80
80
|
mockListTemplates.mockImplementationOnce(() => Promise.reject(new Error('API error')))
|
|
81
81
|
|
|
82
82
|
const result = await listAction({})
|
|
@@ -86,7 +86,7 @@ describe('template commands', () => {
|
|
|
86
86
|
})
|
|
87
87
|
|
|
88
88
|
describe('getAction', () => {
|
|
89
|
-
|
|
89
|
+
it('returns a specific template by name', async () => {
|
|
90
90
|
const result = await getAction('hello_world', {})
|
|
91
91
|
|
|
92
92
|
expect(result.template).toBeDefined()
|
|
@@ -95,13 +95,13 @@ describe('template commands', () => {
|
|
|
95
95
|
expect(mockGetTemplate).toHaveBeenCalledWith('hello_world')
|
|
96
96
|
})
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
it('returns error when template not found', async () => {
|
|
99
99
|
const result = await getAction('nonexistent_template', {})
|
|
100
100
|
|
|
101
101
|
expect(result.error).toContain('nonexistent_template')
|
|
102
102
|
})
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
it('returns error when client throws', async () => {
|
|
105
105
|
mockGetTemplate.mockImplementationOnce(() => Promise.reject(new Error('Network error')))
|
|
106
106
|
|
|
107
107
|
const result = await getAction('hello_world', {})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, mock,
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, mock, it } from 'bun:test'
|
|
2
2
|
import { existsSync, rmSync } from 'node:fs'
|
|
3
3
|
import { mkdir } from 'node:fs/promises'
|
|
4
4
|
import { tmpdir } from 'node:os'
|
|
@@ -35,7 +35,7 @@ describe('whoami command', () => {
|
|
|
35
35
|
}
|
|
36
36
|
})
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
it('returns phone number id, account name, and verified name', async () => {
|
|
39
39
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
40
40
|
await manager.setCredentials({
|
|
41
41
|
phone_number_id: '12345678901',
|
|
@@ -51,7 +51,7 @@ describe('whoami command', () => {
|
|
|
51
51
|
expect(result.error).toBeUndefined()
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
it('returns info for specific --account', async () => {
|
|
55
55
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
56
56
|
await manager.setCredentials({
|
|
57
57
|
phone_number_id: '11111111111',
|
|
@@ -71,7 +71,7 @@ describe('whoami command', () => {
|
|
|
71
71
|
expect(result.verified_name).toBe('Test Business')
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
it('returns error when verifyToken fails', async () => {
|
|
75
75
|
mockVerifyToken.mockImplementationOnce(() => Promise.reject(new Error('Invalid token')))
|
|
76
76
|
|
|
77
77
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
@@ -87,7 +87,7 @@ describe('whoami command', () => {
|
|
|
87
87
|
expect(result.error).toContain('Invalid token')
|
|
88
88
|
})
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
it('returns error when no credentials', async () => {
|
|
91
91
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
92
92
|
|
|
93
93
|
const result = await whoamiAction({ _credManager: manager })
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { afterAll, describe, expect,
|
|
1
|
+
import { afterAll, describe, expect, it } from 'bun:test'
|
|
2
2
|
import { existsSync, rmSync } from 'node:fs'
|
|
3
3
|
import { join } from 'node:path'
|
|
4
4
|
|
|
@@ -22,7 +22,7 @@ afterAll(() => {
|
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
describe('WhatsAppBotCredentialManager', () => {
|
|
25
|
-
|
|
25
|
+
it('load returns default config when file does not exist', async () => {
|
|
26
26
|
const manager = setup()
|
|
27
27
|
const config = await manager.load()
|
|
28
28
|
|
|
@@ -32,7 +32,7 @@ describe('WhatsAppBotCredentialManager', () => {
|
|
|
32
32
|
})
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
it('save creates file with correct permissions', async () => {
|
|
36
36
|
const testConfigDir = join(
|
|
37
37
|
import.meta.dir,
|
|
38
38
|
`.test-whatsappbot-config-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
@@ -61,13 +61,13 @@ describe('WhatsAppBotCredentialManager', () => {
|
|
|
61
61
|
expect(loaded).toEqual(config)
|
|
62
62
|
})
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
it('getCredentials returns null when not configured', async () => {
|
|
65
65
|
const manager = setup()
|
|
66
66
|
const creds = await manager.getCredentials()
|
|
67
67
|
expect(creds).toBeNull()
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
it('getCredentials returns credentials from env vars when E2E env vars are set', async () => {
|
|
71
71
|
const originalAccessToken = process.env.E2E_WHATSAPPBOT_ACCESS_TOKEN
|
|
72
72
|
const originalPhoneNumberId = process.env.E2E_WHATSAPPBOT_PHONE_NUMBER_ID
|
|
73
73
|
|
|
@@ -96,7 +96,7 @@ describe('WhatsAppBotCredentialManager', () => {
|
|
|
96
96
|
}
|
|
97
97
|
})
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
it('getCredentials ignores env vars when accountId is provided', async () => {
|
|
100
100
|
const originalAccessToken = process.env.E2E_WHATSAPPBOT_ACCESS_TOKEN
|
|
101
101
|
const originalPhoneNumberId = process.env.E2E_WHATSAPPBOT_PHONE_NUMBER_ID
|
|
102
102
|
|
|
@@ -121,7 +121,7 @@ describe('WhatsAppBotCredentialManager', () => {
|
|
|
121
121
|
}
|
|
122
122
|
})
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
it('getCredentials returns specific account by accountId', async () => {
|
|
125
125
|
const manager = setup()
|
|
126
126
|
await manager.setCredentials({
|
|
127
127
|
phone_number_id: 'phone-1',
|
|
@@ -142,13 +142,13 @@ describe('WhatsAppBotCredentialManager', () => {
|
|
|
142
142
|
})
|
|
143
143
|
})
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
it('getCredentials returns null for nonexistent accountId', async () => {
|
|
146
146
|
const manager = setup()
|
|
147
147
|
const creds = await manager.getCredentials('nonexistent')
|
|
148
148
|
expect(creds).toBeNull()
|
|
149
149
|
})
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
it('setCredentials saves and sets as current', async () => {
|
|
152
152
|
const manager = setup()
|
|
153
153
|
await manager.setCredentials({
|
|
154
154
|
phone_number_id: '123456789',
|
|
@@ -167,7 +167,7 @@ describe('WhatsAppBotCredentialManager', () => {
|
|
|
167
167
|
expect(config.current).toEqual({ account_id: '123456789' })
|
|
168
168
|
})
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
it('removeAccount deletes account and adjusts current', async () => {
|
|
171
171
|
const manager = setup()
|
|
172
172
|
await manager.setCredentials({
|
|
173
173
|
phone_number_id: '123456789',
|
|
@@ -186,13 +186,13 @@ describe('WhatsAppBotCredentialManager', () => {
|
|
|
186
186
|
expect(config.accounts['123456789']).toBeUndefined()
|
|
187
187
|
})
|
|
188
188
|
|
|
189
|
-
|
|
189
|
+
it('removeAccount returns false for non-existent account', async () => {
|
|
190
190
|
const manager = setup()
|
|
191
191
|
const removed = await manager.removeAccount('nonexistent')
|
|
192
192
|
expect(removed).toBe(false)
|
|
193
193
|
})
|
|
194
194
|
|
|
195
|
-
|
|
195
|
+
it('removeAccount does not clear current when a different account is removed', async () => {
|
|
196
196
|
const manager = setup()
|
|
197
197
|
await manager.setCredentials({
|
|
198
198
|
phone_number_id: 'phone-1',
|
|
@@ -212,7 +212,7 @@ describe('WhatsAppBotCredentialManager', () => {
|
|
|
212
212
|
expect(config.current).toEqual({ account_id: 'phone-2' })
|
|
213
213
|
})
|
|
214
214
|
|
|
215
|
-
|
|
215
|
+
it('setCurrent switches active account', async () => {
|
|
216
216
|
const manager = setup()
|
|
217
217
|
await manager.setCredentials({
|
|
218
218
|
phone_number_id: 'phone-1',
|
|
@@ -232,13 +232,13 @@ describe('WhatsAppBotCredentialManager', () => {
|
|
|
232
232
|
expect(config.current).toEqual({ account_id: 'phone-1' })
|
|
233
233
|
})
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
it('setCurrent returns false for non-existent account', async () => {
|
|
236
236
|
const manager = setup()
|
|
237
237
|
const result = await manager.setCurrent('nonexistent')
|
|
238
238
|
expect(result).toBe(false)
|
|
239
239
|
})
|
|
240
240
|
|
|
241
|
-
|
|
241
|
+
it('listAll returns all accounts with is_current flag', async () => {
|
|
242
242
|
const manager = setup()
|
|
243
243
|
await manager.setCredentials({
|
|
244
244
|
phone_number_id: 'phone-1',
|
|
@@ -261,13 +261,13 @@ describe('WhatsAppBotCredentialManager', () => {
|
|
|
261
261
|
expect(phone2?.is_current).toBe(true)
|
|
262
262
|
})
|
|
263
263
|
|
|
264
|
-
|
|
264
|
+
it('listAll returns empty array when no accounts', async () => {
|
|
265
265
|
const manager = setup()
|
|
266
266
|
const accounts = await manager.listAll()
|
|
267
267
|
expect(accounts).toHaveLength(0)
|
|
268
268
|
})
|
|
269
269
|
|
|
270
|
-
|
|
270
|
+
it('clearCredentials resets everything', async () => {
|
|
271
271
|
const manager = setup()
|
|
272
272
|
await manager.setCredentials({
|
|
273
273
|
phone_number_id: '123456789',
|
|
@@ -282,7 +282,7 @@ describe('WhatsAppBotCredentialManager', () => {
|
|
|
282
282
|
expect(config.accounts).toEqual({})
|
|
283
283
|
})
|
|
284
284
|
|
|
285
|
-
|
|
285
|
+
it('completes round-trip: set → get → remove → get null', async () => {
|
|
286
286
|
const manager = setup()
|
|
287
287
|
|
|
288
288
|
await manager.setCredentials({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expect,
|
|
1
|
+
import { expect, it } from 'bun:test'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
WhatsAppBotAccountEntrySchema,
|
|
@@ -9,26 +9,26 @@ import {
|
|
|
9
9
|
WhatsAppBotError,
|
|
10
10
|
} from '@/platforms/whatsappbot/index'
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
it('WhatsAppBotClient is exported from barrel', () => {
|
|
13
13
|
expect(typeof WhatsAppBotClient).toBe('function')
|
|
14
14
|
})
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
it('WhatsAppBotCredentialManager is exported from barrel', () => {
|
|
17
17
|
expect(typeof WhatsAppBotCredentialManager).toBe('function')
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
it('WhatsAppBotError is exported from barrel', () => {
|
|
21
21
|
expect(typeof WhatsAppBotError).toBe('function')
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
it('WhatsAppBotAccountEntrySchema is exported from barrel', () => {
|
|
25
25
|
expect(typeof WhatsAppBotAccountEntrySchema.parse).toBe('function')
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
it('WhatsAppBotConfigSchema is exported from barrel', () => {
|
|
29
29
|
expect(typeof WhatsAppBotConfigSchema.parse).toBe('function')
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
it('WhatsAppBotCredentialsSchema is exported from barrel', () => {
|
|
33
33
|
expect(typeof WhatsAppBotCredentialsSchema.parse).toBe('function')
|
|
34
34
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expect,
|
|
1
|
+
import { expect, it } from 'bun:test'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
WhatsAppBotAccountEntrySchema,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
WhatsAppBotError,
|
|
8
8
|
} from '@/platforms/whatsappbot/types'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
it('WhatsAppBotAccountEntrySchema validates correct data', () => {
|
|
11
11
|
const result = WhatsAppBotAccountEntrySchema.safeParse({
|
|
12
12
|
phone_number_id: '123456789',
|
|
13
13
|
account_name: 'Test Business',
|
|
@@ -16,7 +16,7 @@ test('WhatsAppBotAccountEntrySchema validates correct data', () => {
|
|
|
16
16
|
expect(result.success).toBe(true)
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
it('WhatsAppBotAccountEntrySchema rejects missing phone_number_id', () => {
|
|
20
20
|
const result = WhatsAppBotAccountEntrySchema.safeParse({
|
|
21
21
|
account_name: 'Test Business',
|
|
22
22
|
access_token: 'EAAtest123',
|
|
@@ -24,7 +24,7 @@ test('WhatsAppBotAccountEntrySchema rejects missing phone_number_id', () => {
|
|
|
24
24
|
expect(result.success).toBe(false)
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
it('WhatsAppBotAccountEntrySchema rejects missing account_name', () => {
|
|
28
28
|
const result = WhatsAppBotAccountEntrySchema.safeParse({
|
|
29
29
|
phone_number_id: '123456789',
|
|
30
30
|
access_token: 'EAAtest123',
|
|
@@ -32,7 +32,7 @@ test('WhatsAppBotAccountEntrySchema rejects missing account_name', () => {
|
|
|
32
32
|
expect(result.success).toBe(false)
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
it('WhatsAppBotAccountEntrySchema rejects missing access_token', () => {
|
|
36
36
|
const result = WhatsAppBotAccountEntrySchema.safeParse({
|
|
37
37
|
phone_number_id: '123456789',
|
|
38
38
|
account_name: 'Test Business',
|
|
@@ -40,7 +40,7 @@ test('WhatsAppBotAccountEntrySchema rejects missing access_token', () => {
|
|
|
40
40
|
expect(result.success).toBe(false)
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
it('WhatsAppBotConfigSchema validates with current account', () => {
|
|
44
44
|
const result = WhatsAppBotConfigSchema.safeParse({
|
|
45
45
|
current: { account_id: '123456789' },
|
|
46
46
|
accounts: {
|
|
@@ -54,7 +54,7 @@ test('WhatsAppBotConfigSchema validates with current account', () => {
|
|
|
54
54
|
expect(result.success).toBe(true)
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
it('WhatsAppBotConfigSchema validates with current null and empty accounts', () => {
|
|
58
58
|
const result = WhatsAppBotConfigSchema.safeParse({
|
|
59
59
|
current: null,
|
|
60
60
|
accounts: {},
|
|
@@ -62,7 +62,7 @@ test('WhatsAppBotConfigSchema validates with current null and empty accounts', (
|
|
|
62
62
|
expect(result.success).toBe(true)
|
|
63
63
|
})
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
it('WhatsAppBotConfigSchema validates with multiple accounts', () => {
|
|
66
66
|
const result = WhatsAppBotConfigSchema.safeParse({
|
|
67
67
|
current: { account_id: 'phone-1' },
|
|
68
68
|
accounts: {
|
|
@@ -73,21 +73,21 @@ test('WhatsAppBotConfigSchema validates with multiple accounts', () => {
|
|
|
73
73
|
expect(result.success).toBe(true)
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
it('WhatsAppBotConfigSchema rejects missing accounts field', () => {
|
|
77
77
|
const result = WhatsAppBotConfigSchema.safeParse({
|
|
78
78
|
current: null,
|
|
79
79
|
})
|
|
80
80
|
expect(result.success).toBe(false)
|
|
81
81
|
})
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
it('WhatsAppBotConfigSchema rejects missing current field', () => {
|
|
84
84
|
const result = WhatsAppBotConfigSchema.safeParse({
|
|
85
85
|
accounts: {},
|
|
86
86
|
})
|
|
87
87
|
expect(result.success).toBe(false)
|
|
88
88
|
})
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
it('WhatsAppBotCredentialsSchema validates correct data', () => {
|
|
91
91
|
const result = WhatsAppBotCredentialsSchema.safeParse({
|
|
92
92
|
phone_number_id: '123456789',
|
|
93
93
|
account_name: 'Test Business',
|
|
@@ -96,7 +96,7 @@ test('WhatsAppBotCredentialsSchema validates correct data', () => {
|
|
|
96
96
|
expect(result.success).toBe(true)
|
|
97
97
|
})
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
it('WhatsAppBotCredentialsSchema rejects missing phone_number_id', () => {
|
|
100
100
|
const result = WhatsAppBotCredentialsSchema.safeParse({
|
|
101
101
|
account_name: 'Test Business',
|
|
102
102
|
access_token: 'EAAtest123',
|
|
@@ -104,7 +104,7 @@ test('WhatsAppBotCredentialsSchema rejects missing phone_number_id', () => {
|
|
|
104
104
|
expect(result.success).toBe(false)
|
|
105
105
|
})
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
it('WhatsAppBotCredentialsSchema rejects missing account_name', () => {
|
|
108
108
|
const result = WhatsAppBotCredentialsSchema.safeParse({
|
|
109
109
|
phone_number_id: '123456789',
|
|
110
110
|
access_token: 'EAAtest123',
|
|
@@ -112,7 +112,7 @@ test('WhatsAppBotCredentialsSchema rejects missing account_name', () => {
|
|
|
112
112
|
expect(result.success).toBe(false)
|
|
113
113
|
})
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
it('WhatsAppBotCredentialsSchema rejects missing access_token', () => {
|
|
116
116
|
const result = WhatsAppBotCredentialsSchema.safeParse({
|
|
117
117
|
phone_number_id: '123456789',
|
|
118
118
|
account_name: 'Test Business',
|
|
@@ -120,22 +120,22 @@ test('WhatsAppBotCredentialsSchema rejects missing access_token', () => {
|
|
|
120
120
|
expect(result.success).toBe(false)
|
|
121
121
|
})
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
it('WhatsAppBotError has correct name', () => {
|
|
124
124
|
const error = new WhatsAppBotError('Test error', 'TEST_CODE')
|
|
125
125
|
expect(error.name).toBe('WhatsAppBotError')
|
|
126
126
|
})
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
it('WhatsAppBotError has correct message', () => {
|
|
129
129
|
const error = new WhatsAppBotError('Test error', 'TEST_CODE')
|
|
130
130
|
expect(error.message).toBe('Test error')
|
|
131
131
|
})
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
it('WhatsAppBotError has correct code', () => {
|
|
134
134
|
const error = new WhatsAppBotError('Test error', 'TEST_CODE')
|
|
135
135
|
expect(error.code).toBe('TEST_CODE')
|
|
136
136
|
})
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
it('WhatsAppBotError is instance of Error', () => {
|
|
139
139
|
const error = new WhatsAppBotError('Test error', 'TEST_CODE')
|
|
140
140
|
expect(error instanceof Error).toBe(true)
|
|
141
141
|
})
|