superacli 1.1.5 → 1.1.6

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.
Files changed (191) hide show
  1. package/__tests__/resend-plugin.test.js +22 -1
  2. package/package.json +1 -1
  3. package/plugins/plugins.json +2 -2
  4. package/plugins/resend/plugin.json +279 -2
  5. package/plugins/resend/skills/quickstart/SKILL.md +32 -13
  6. package/temp_resend_cli/repo/.github/scripts/pr-title-check.js +34 -0
  7. package/temp_resend_cli/repo/.github/workflows/ci.yml +67 -0
  8. package/temp_resend_cli/repo/.github/workflows/post-release.yml +51 -0
  9. package/temp_resend_cli/repo/.github/workflows/pr-title-check.yml +13 -0
  10. package/temp_resend_cli/repo/.github/workflows/release.yml +175 -0
  11. package/temp_resend_cli/repo/.github/workflows/test-install-unix.yml +34 -0
  12. package/temp_resend_cli/repo/.github/workflows/test-install-windows.yml +48 -0
  13. package/temp_resend_cli/repo/CHANGELOG.md +31 -0
  14. package/temp_resend_cli/repo/LICENSE +21 -0
  15. package/temp_resend_cli/repo/README.md +450 -0
  16. package/temp_resend_cli/repo/biome.json +36 -0
  17. package/temp_resend_cli/repo/install.ps1 +141 -0
  18. package/temp_resend_cli/repo/install.sh +301 -0
  19. package/temp_resend_cli/repo/package.json +61 -0
  20. package/temp_resend_cli/repo/pnpm-lock.yaml +2439 -0
  21. package/temp_resend_cli/repo/renovate.json +4 -0
  22. package/temp_resend_cli/repo/src/cli.ts +98 -0
  23. package/temp_resend_cli/repo/src/commands/api-keys/create.ts +114 -0
  24. package/temp_resend_cli/repo/src/commands/api-keys/delete.ts +47 -0
  25. package/temp_resend_cli/repo/src/commands/api-keys/index.ts +26 -0
  26. package/temp_resend_cli/repo/src/commands/api-keys/list.ts +35 -0
  27. package/temp_resend_cli/repo/src/commands/api-keys/utils.ts +8 -0
  28. package/temp_resend_cli/repo/src/commands/auth/index.ts +20 -0
  29. package/temp_resend_cli/repo/src/commands/auth/login.ts +234 -0
  30. package/temp_resend_cli/repo/src/commands/auth/logout.ts +105 -0
  31. package/temp_resend_cli/repo/src/commands/broadcasts/create.ts +196 -0
  32. package/temp_resend_cli/repo/src/commands/broadcasts/delete.ts +46 -0
  33. package/temp_resend_cli/repo/src/commands/broadcasts/get.ts +59 -0
  34. package/temp_resend_cli/repo/src/commands/broadcasts/index.ts +43 -0
  35. package/temp_resend_cli/repo/src/commands/broadcasts/list.ts +60 -0
  36. package/temp_resend_cli/repo/src/commands/broadcasts/send.ts +56 -0
  37. package/temp_resend_cli/repo/src/commands/broadcasts/update.ts +95 -0
  38. package/temp_resend_cli/repo/src/commands/broadcasts/utils.ts +35 -0
  39. package/temp_resend_cli/repo/src/commands/contact-properties/create.ts +118 -0
  40. package/temp_resend_cli/repo/src/commands/contact-properties/delete.ts +48 -0
  41. package/temp_resend_cli/repo/src/commands/contact-properties/get.ts +46 -0
  42. package/temp_resend_cli/repo/src/commands/contact-properties/index.ts +48 -0
  43. package/temp_resend_cli/repo/src/commands/contact-properties/list.ts +68 -0
  44. package/temp_resend_cli/repo/src/commands/contact-properties/update.ts +88 -0
  45. package/temp_resend_cli/repo/src/commands/contact-properties/utils.ts +17 -0
  46. package/temp_resend_cli/repo/src/commands/contacts/add-segment.ts +78 -0
  47. package/temp_resend_cli/repo/src/commands/contacts/create.ts +122 -0
  48. package/temp_resend_cli/repo/src/commands/contacts/delete.ts +49 -0
  49. package/temp_resend_cli/repo/src/commands/contacts/get.ts +53 -0
  50. package/temp_resend_cli/repo/src/commands/contacts/index.ts +58 -0
  51. package/temp_resend_cli/repo/src/commands/contacts/list.ts +57 -0
  52. package/temp_resend_cli/repo/src/commands/contacts/remove-segment.ts +48 -0
  53. package/temp_resend_cli/repo/src/commands/contacts/segments.ts +39 -0
  54. package/temp_resend_cli/repo/src/commands/contacts/topics.ts +45 -0
  55. package/temp_resend_cli/repo/src/commands/contacts/update-topics.ts +90 -0
  56. package/temp_resend_cli/repo/src/commands/contacts/update.ts +77 -0
  57. package/temp_resend_cli/repo/src/commands/contacts/utils.ts +119 -0
  58. package/temp_resend_cli/repo/src/commands/doctor.ts +216 -0
  59. package/temp_resend_cli/repo/src/commands/domains/create.ts +83 -0
  60. package/temp_resend_cli/repo/src/commands/domains/delete.ts +42 -0
  61. package/temp_resend_cli/repo/src/commands/domains/get.ts +47 -0
  62. package/temp_resend_cli/repo/src/commands/domains/index.ts +35 -0
  63. package/temp_resend_cli/repo/src/commands/domains/list.ts +53 -0
  64. package/temp_resend_cli/repo/src/commands/domains/update.ts +75 -0
  65. package/temp_resend_cli/repo/src/commands/domains/utils.ts +44 -0
  66. package/temp_resend_cli/repo/src/commands/domains/verify.ts +38 -0
  67. package/temp_resend_cli/repo/src/commands/emails/batch.ts +140 -0
  68. package/temp_resend_cli/repo/src/commands/emails/get.ts +44 -0
  69. package/temp_resend_cli/repo/src/commands/emails/index.ts +30 -0
  70. package/temp_resend_cli/repo/src/commands/emails/list.ts +84 -0
  71. package/temp_resend_cli/repo/src/commands/emails/receiving/attachment.ts +55 -0
  72. package/temp_resend_cli/repo/src/commands/emails/receiving/attachments.ts +68 -0
  73. package/temp_resend_cli/repo/src/commands/emails/receiving/get.ts +58 -0
  74. package/temp_resend_cli/repo/src/commands/emails/receiving/index.ts +28 -0
  75. package/temp_resend_cli/repo/src/commands/emails/receiving/list.ts +59 -0
  76. package/temp_resend_cli/repo/src/commands/emails/receiving/utils.ts +38 -0
  77. package/temp_resend_cli/repo/src/commands/emails/send.ts +189 -0
  78. package/temp_resend_cli/repo/src/commands/open.ts +27 -0
  79. package/temp_resend_cli/repo/src/commands/segments/create.ts +50 -0
  80. package/temp_resend_cli/repo/src/commands/segments/delete.ts +47 -0
  81. package/temp_resend_cli/repo/src/commands/segments/get.ts +38 -0
  82. package/temp_resend_cli/repo/src/commands/segments/index.ts +36 -0
  83. package/temp_resend_cli/repo/src/commands/segments/list.ts +58 -0
  84. package/temp_resend_cli/repo/src/commands/segments/utils.ts +7 -0
  85. package/temp_resend_cli/repo/src/commands/teams/index.ts +10 -0
  86. package/temp_resend_cli/repo/src/commands/teams/list.ts +35 -0
  87. package/temp_resend_cli/repo/src/commands/teams/remove.ts +86 -0
  88. package/temp_resend_cli/repo/src/commands/teams/switch.ts +76 -0
  89. package/temp_resend_cli/repo/src/commands/topics/create.ts +73 -0
  90. package/temp_resend_cli/repo/src/commands/topics/delete.ts +47 -0
  91. package/temp_resend_cli/repo/src/commands/topics/get.ts +42 -0
  92. package/temp_resend_cli/repo/src/commands/topics/index.ts +42 -0
  93. package/temp_resend_cli/repo/src/commands/topics/list.ts +34 -0
  94. package/temp_resend_cli/repo/src/commands/topics/update.ts +59 -0
  95. package/temp_resend_cli/repo/src/commands/topics/utils.ts +16 -0
  96. package/temp_resend_cli/repo/src/commands/webhooks/create.ts +128 -0
  97. package/temp_resend_cli/repo/src/commands/webhooks/delete.ts +49 -0
  98. package/temp_resend_cli/repo/src/commands/webhooks/get.ts +42 -0
  99. package/temp_resend_cli/repo/src/commands/webhooks/index.ts +42 -0
  100. package/temp_resend_cli/repo/src/commands/webhooks/list.ts +55 -0
  101. package/temp_resend_cli/repo/src/commands/webhooks/listen.ts +379 -0
  102. package/temp_resend_cli/repo/src/commands/webhooks/update.ts +83 -0
  103. package/temp_resend_cli/repo/src/commands/webhooks/utils.ts +36 -0
  104. package/temp_resend_cli/repo/src/commands/whoami.ts +71 -0
  105. package/temp_resend_cli/repo/src/lib/actions.ts +157 -0
  106. package/temp_resend_cli/repo/src/lib/client.ts +37 -0
  107. package/temp_resend_cli/repo/src/lib/config.ts +217 -0
  108. package/temp_resend_cli/repo/src/lib/files.ts +15 -0
  109. package/temp_resend_cli/repo/src/lib/help-text.ts +38 -0
  110. package/temp_resend_cli/repo/src/lib/output.ts +56 -0
  111. package/temp_resend_cli/repo/src/lib/pagination.ts +36 -0
  112. package/temp_resend_cli/repo/src/lib/prompts.ts +149 -0
  113. package/temp_resend_cli/repo/src/lib/spinner.ts +100 -0
  114. package/temp_resend_cli/repo/src/lib/table.ts +57 -0
  115. package/temp_resend_cli/repo/src/lib/tty.ts +28 -0
  116. package/temp_resend_cli/repo/src/lib/update-check.ts +169 -0
  117. package/temp_resend_cli/repo/src/lib/version.ts +4 -0
  118. package/temp_resend_cli/repo/tests/commands/api-keys/create.test.ts +196 -0
  119. package/temp_resend_cli/repo/tests/commands/api-keys/delete.test.ts +157 -0
  120. package/temp_resend_cli/repo/tests/commands/api-keys/list.test.ts +134 -0
  121. package/temp_resend_cli/repo/tests/commands/auth/login.test.ts +153 -0
  122. package/temp_resend_cli/repo/tests/commands/auth/logout.test.ts +153 -0
  123. package/temp_resend_cli/repo/tests/commands/broadcasts/create.test.ts +454 -0
  124. package/temp_resend_cli/repo/tests/commands/broadcasts/delete.test.ts +183 -0
  125. package/temp_resend_cli/repo/tests/commands/broadcasts/get.test.ts +147 -0
  126. package/temp_resend_cli/repo/tests/commands/broadcasts/list.test.ts +199 -0
  127. package/temp_resend_cli/repo/tests/commands/broadcasts/send.test.ts +162 -0
  128. package/temp_resend_cli/repo/tests/commands/broadcasts/update.test.ts +288 -0
  129. package/temp_resend_cli/repo/tests/commands/contact-properties/create.test.ts +251 -0
  130. package/temp_resend_cli/repo/tests/commands/contact-properties/delete.test.ts +184 -0
  131. package/temp_resend_cli/repo/tests/commands/contact-properties/get.test.ts +145 -0
  132. package/temp_resend_cli/repo/tests/commands/contact-properties/list.test.ts +181 -0
  133. package/temp_resend_cli/repo/tests/commands/contact-properties/update.test.ts +217 -0
  134. package/temp_resend_cli/repo/tests/commands/contacts/add-segment.test.ts +189 -0
  135. package/temp_resend_cli/repo/tests/commands/contacts/create.test.ts +271 -0
  136. package/temp_resend_cli/repo/tests/commands/contacts/delete.test.ts +193 -0
  137. package/temp_resend_cli/repo/tests/commands/contacts/get.test.ts +149 -0
  138. package/temp_resend_cli/repo/tests/commands/contacts/list.test.ts +176 -0
  139. package/temp_resend_cli/repo/tests/commands/contacts/remove-segment.test.ts +167 -0
  140. package/temp_resend_cli/repo/tests/commands/contacts/segments.test.ts +168 -0
  141. package/temp_resend_cli/repo/tests/commands/contacts/topics.test.ts +164 -0
  142. package/temp_resend_cli/repo/tests/commands/contacts/update-topics.test.ts +248 -0
  143. package/temp_resend_cli/repo/tests/commands/contacts/update.test.ts +206 -0
  144. package/temp_resend_cli/repo/tests/commands/doctor.test.ts +164 -0
  145. package/temp_resend_cli/repo/tests/commands/domains/create.test.ts +193 -0
  146. package/temp_resend_cli/repo/tests/commands/domains/delete.test.ts +157 -0
  147. package/temp_resend_cli/repo/tests/commands/domains/get.test.ts +138 -0
  148. package/temp_resend_cli/repo/tests/commands/domains/list.test.ts +165 -0
  149. package/temp_resend_cli/repo/tests/commands/domains/update.test.ts +224 -0
  150. package/temp_resend_cli/repo/tests/commands/domains/verify.test.ts +118 -0
  151. package/temp_resend_cli/repo/tests/commands/emails/batch.test.ts +324 -0
  152. package/temp_resend_cli/repo/tests/commands/emails/get.test.ts +132 -0
  153. package/temp_resend_cli/repo/tests/commands/emails/receiving/attachment.test.ts +141 -0
  154. package/temp_resend_cli/repo/tests/commands/emails/receiving/attachments.test.ts +169 -0
  155. package/temp_resend_cli/repo/tests/commands/emails/receiving/get.test.ts +141 -0
  156. package/temp_resend_cli/repo/tests/commands/emails/receiving/list.test.ts +182 -0
  157. package/temp_resend_cli/repo/tests/commands/emails/send.test.ts +312 -0
  158. package/temp_resend_cli/repo/tests/commands/segments/create.test.ts +164 -0
  159. package/temp_resend_cli/repo/tests/commands/segments/delete.test.ts +183 -0
  160. package/temp_resend_cli/repo/tests/commands/segments/get.test.ts +138 -0
  161. package/temp_resend_cli/repo/tests/commands/segments/list.test.ts +174 -0
  162. package/temp_resend_cli/repo/tests/commands/teams/list.test.ts +62 -0
  163. package/temp_resend_cli/repo/tests/commands/teams/remove.test.ts +110 -0
  164. package/temp_resend_cli/repo/tests/commands/teams/switch.test.ts +103 -0
  165. package/temp_resend_cli/repo/tests/commands/topics/create.test.ts +192 -0
  166. package/temp_resend_cli/repo/tests/commands/topics/delete.test.ts +157 -0
  167. package/temp_resend_cli/repo/tests/commands/topics/get.test.ts +126 -0
  168. package/temp_resend_cli/repo/tests/commands/topics/list.test.ts +125 -0
  169. package/temp_resend_cli/repo/tests/commands/topics/update.test.ts +178 -0
  170. package/temp_resend_cli/repo/tests/commands/webhooks/create.test.ts +225 -0
  171. package/temp_resend_cli/repo/tests/commands/webhooks/delete.test.ts +157 -0
  172. package/temp_resend_cli/repo/tests/commands/webhooks/get.test.ts +126 -0
  173. package/temp_resend_cli/repo/tests/commands/webhooks/list.test.ts +178 -0
  174. package/temp_resend_cli/repo/tests/commands/webhooks/update.test.ts +207 -0
  175. package/temp_resend_cli/repo/tests/commands/whoami.test.ts +98 -0
  176. package/temp_resend_cli/repo/tests/e2e/smoke.test.ts +93 -0
  177. package/temp_resend_cli/repo/tests/helpers.ts +86 -0
  178. package/temp_resend_cli/repo/tests/lib/client.test.ts +71 -0
  179. package/temp_resend_cli/repo/tests/lib/config.test.ts +451 -0
  180. package/temp_resend_cli/repo/tests/lib/files.test.ts +73 -0
  181. package/temp_resend_cli/repo/tests/lib/help-text.test.ts +97 -0
  182. package/temp_resend_cli/repo/tests/lib/output.test.ts +136 -0
  183. package/temp_resend_cli/repo/tests/lib/prompts.test.ts +185 -0
  184. package/temp_resend_cli/repo/tests/lib/spinner.test.ts +166 -0
  185. package/temp_resend_cli/repo/tests/lib/table.test.ts +63 -0
  186. package/temp_resend_cli/repo/tests/lib/tty.test.ts +89 -0
  187. package/temp_resend_cli/repo/tests/lib/update-check.test.ts +179 -0
  188. package/temp_resend_cli/repo/tsconfig.json +14 -0
  189. package/temp_resend_cli/repo/vitest.config.e2e.ts +8 -0
  190. package/temp_resend_cli/repo/vitest.config.ts +10 -0
  191. package/tests/test-resend-smoke.sh +7 -3
@@ -0,0 +1,454 @@
1
+ import {
2
+ afterEach,
3
+ beforeEach,
4
+ describe,
5
+ expect,
6
+ type MockInstance,
7
+ test,
8
+ vi,
9
+ } from 'vitest';
10
+ import * as files from '../../../src/lib/files';
11
+ import {
12
+ captureTestEnv,
13
+ expectExit1,
14
+ mockExitThrow,
15
+ mockSdkError,
16
+ setNonInteractive,
17
+ setupOutputSpies,
18
+ } from '../../helpers';
19
+
20
+ const mockCreate = vi.fn(async () => ({
21
+ data: { id: 'd1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6' },
22
+ error: null,
23
+ }));
24
+
25
+ vi.mock('resend', () => ({
26
+ Resend: class MockResend {
27
+ constructor(public key: string) {}
28
+ broadcasts = { create: mockCreate };
29
+ },
30
+ }));
31
+
32
+ describe('broadcasts create command', () => {
33
+ const restoreEnv = captureTestEnv();
34
+ let spies: ReturnType<typeof setupOutputSpies> | undefined;
35
+ let errorSpy: MockInstance | undefined;
36
+ let stderrSpy: MockInstance | undefined;
37
+ let exitSpy: MockInstance | undefined;
38
+ let readFileSpy: MockInstance | undefined;
39
+
40
+ beforeEach(() => {
41
+ process.env.RESEND_API_KEY = 're_test_key';
42
+ mockCreate.mockClear();
43
+ });
44
+
45
+ afterEach(() => {
46
+ restoreEnv();
47
+ errorSpy?.mockRestore();
48
+ stderrSpy?.mockRestore();
49
+ exitSpy?.mockRestore();
50
+ readFileSpy?.mockRestore();
51
+ spies = undefined;
52
+ errorSpy = undefined;
53
+ stderrSpy = undefined;
54
+ exitSpy = undefined;
55
+ readFileSpy = undefined;
56
+ });
57
+
58
+ test('creates broadcast with required flags', async () => {
59
+ spies = setupOutputSpies();
60
+
61
+ const { createBroadcastCommand } = await import(
62
+ '../../../src/commands/broadcasts/create'
63
+ );
64
+ await createBroadcastCommand.parseAsync(
65
+ [
66
+ '--from',
67
+ 'hello@domain.com',
68
+ '--subject',
69
+ 'Weekly Update',
70
+ '--segment-id',
71
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
72
+ '--html',
73
+ '<p>Hi</p>',
74
+ ],
75
+ { from: 'user' },
76
+ );
77
+
78
+ expect(mockCreate).toHaveBeenCalledTimes(1);
79
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
80
+ expect(args.from).toBe('hello@domain.com');
81
+ expect(args.subject).toBe('Weekly Update');
82
+ expect(args.segmentId).toBe('7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d');
83
+ expect(args.html).toBe('<p>Hi</p>');
84
+ });
85
+
86
+ test('outputs JSON id when non-interactive', async () => {
87
+ spies = setupOutputSpies();
88
+
89
+ const { createBroadcastCommand } = await import(
90
+ '../../../src/commands/broadcasts/create'
91
+ );
92
+ await createBroadcastCommand.parseAsync(
93
+ [
94
+ '--from',
95
+ 'hello@domain.com',
96
+ '--subject',
97
+ 'News',
98
+ '--segment-id',
99
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
100
+ '--text',
101
+ 'Hello!',
102
+ ],
103
+ { from: 'user' },
104
+ );
105
+
106
+ const output = spies.logSpy.mock.calls[0][0] as string;
107
+ const parsed = JSON.parse(output);
108
+ expect(parsed.id).toBe('d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6');
109
+ });
110
+
111
+ test('passes --send flag to SDK', async () => {
112
+ spies = setupOutputSpies();
113
+
114
+ const { createBroadcastCommand } = await import(
115
+ '../../../src/commands/broadcasts/create'
116
+ );
117
+ await createBroadcastCommand.parseAsync(
118
+ [
119
+ '--from',
120
+ 'hello@domain.com',
121
+ '--subject',
122
+ 'Go',
123
+ '--segment-id',
124
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
125
+ '--text',
126
+ 'Hi',
127
+ '--send',
128
+ ],
129
+ { from: 'user' },
130
+ );
131
+
132
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
133
+ expect(args.send).toBe(true);
134
+ });
135
+
136
+ test('passes --scheduled-at with --send to SDK', async () => {
137
+ spies = setupOutputSpies();
138
+
139
+ const { createBroadcastCommand } = await import(
140
+ '../../../src/commands/broadcasts/create'
141
+ );
142
+ await createBroadcastCommand.parseAsync(
143
+ [
144
+ '--from',
145
+ 'hello@domain.com',
146
+ '--subject',
147
+ 'Go',
148
+ '--segment-id',
149
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
150
+ '--text',
151
+ 'Hi',
152
+ '--send',
153
+ '--scheduled-at',
154
+ 'in 1 hour',
155
+ ],
156
+ { from: 'user' },
157
+ );
158
+
159
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
160
+ expect(args.scheduledAt).toBe('in 1 hour');
161
+ });
162
+
163
+ test('passes optional flags to SDK', async () => {
164
+ spies = setupOutputSpies();
165
+
166
+ const { createBroadcastCommand } = await import(
167
+ '../../../src/commands/broadcasts/create'
168
+ );
169
+ await createBroadcastCommand.parseAsync(
170
+ [
171
+ '--from',
172
+ 'hello@domain.com',
173
+ '--subject',
174
+ 'News',
175
+ '--segment-id',
176
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
177
+ '--html',
178
+ '<p>Hi</p>',
179
+ '--name',
180
+ 'Q1 Newsletter',
181
+ '--reply-to',
182
+ 'reply@domain.com',
183
+ '--preview-text',
184
+ 'Read the news',
185
+ '--topic-id',
186
+ 'topic_xyz',
187
+ ],
188
+ { from: 'user' },
189
+ );
190
+
191
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
192
+ expect(args.name).toBe('Q1 Newsletter');
193
+ expect(args.replyTo).toBe('reply@domain.com');
194
+ expect(args.previewText).toBe('Read the news');
195
+ expect(args.topicId).toBe('topic_xyz');
196
+ });
197
+
198
+ test('errors with missing_from when --from absent in non-interactive mode', async () => {
199
+ setNonInteractive();
200
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
201
+ exitSpy = mockExitThrow();
202
+
203
+ const { createBroadcastCommand } = await import(
204
+ '../../../src/commands/broadcasts/create'
205
+ );
206
+ await expectExit1(() =>
207
+ createBroadcastCommand.parseAsync(
208
+ [
209
+ '--subject',
210
+ 'News',
211
+ '--segment-id',
212
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
213
+ '--html',
214
+ '<p>Hi</p>',
215
+ ],
216
+ { from: 'user' },
217
+ ),
218
+ );
219
+
220
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
221
+ expect(output).toContain('missing_from');
222
+ });
223
+
224
+ test('errors with missing_subject when --subject absent in non-interactive mode', async () => {
225
+ setNonInteractive();
226
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
227
+ exitSpy = mockExitThrow();
228
+
229
+ const { createBroadcastCommand } = await import(
230
+ '../../../src/commands/broadcasts/create'
231
+ );
232
+ await expectExit1(() =>
233
+ createBroadcastCommand.parseAsync(
234
+ [
235
+ '--from',
236
+ 'hello@domain.com',
237
+ '--segment-id',
238
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
239
+ '--html',
240
+ '<p>Hi</p>',
241
+ ],
242
+ { from: 'user' },
243
+ ),
244
+ );
245
+
246
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
247
+ expect(output).toContain('missing_subject');
248
+ });
249
+
250
+ test('errors with missing_segment when --segment-id absent in non-interactive mode', async () => {
251
+ setNonInteractive();
252
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
253
+ exitSpy = mockExitThrow();
254
+
255
+ const { createBroadcastCommand } = await import(
256
+ '../../../src/commands/broadcasts/create'
257
+ );
258
+ await expectExit1(() =>
259
+ createBroadcastCommand.parseAsync(
260
+ [
261
+ '--from',
262
+ 'hello@domain.com',
263
+ '--subject',
264
+ 'News',
265
+ '--html',
266
+ '<p>Hi</p>',
267
+ ],
268
+ { from: 'user' },
269
+ ),
270
+ );
271
+
272
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
273
+ expect(output).toContain('missing_segment');
274
+ });
275
+
276
+ test('errors with missing_body when no body flag in non-interactive mode', async () => {
277
+ setNonInteractive();
278
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
279
+ exitSpy = mockExitThrow();
280
+
281
+ const { createBroadcastCommand } = await import(
282
+ '../../../src/commands/broadcasts/create'
283
+ );
284
+ await expectExit1(() =>
285
+ createBroadcastCommand.parseAsync(
286
+ [
287
+ '--from',
288
+ 'hello@domain.com',
289
+ '--subject',
290
+ 'News',
291
+ '--segment-id',
292
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
293
+ ],
294
+ { from: 'user' },
295
+ ),
296
+ );
297
+
298
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
299
+ expect(output).toContain('missing_body');
300
+ });
301
+
302
+ test('errors with auth_error when no API key', async () => {
303
+ setNonInteractive();
304
+ delete process.env.RESEND_API_KEY;
305
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
306
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
307
+ exitSpy = mockExitThrow();
308
+
309
+ const { createBroadcastCommand } = await import(
310
+ '../../../src/commands/broadcasts/create'
311
+ );
312
+ await expectExit1(() =>
313
+ createBroadcastCommand.parseAsync(
314
+ [
315
+ '--from',
316
+ 'hello@domain.com',
317
+ '--subject',
318
+ 'News',
319
+ '--segment-id',
320
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
321
+ '--html',
322
+ '<p>Hi</p>',
323
+ ],
324
+ { from: 'user' },
325
+ ),
326
+ );
327
+
328
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
329
+ expect(output).toContain('auth_error');
330
+ });
331
+
332
+ test('errors with create_error when SDK returns an error', async () => {
333
+ setNonInteractive();
334
+ mockCreate.mockResolvedValueOnce(
335
+ mockSdkError('Segment not found', 'not_found'),
336
+ );
337
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
338
+ stderrSpy = vi
339
+ .spyOn(process.stderr, 'write')
340
+ .mockImplementation(() => true);
341
+ exitSpy = mockExitThrow();
342
+
343
+ const { createBroadcastCommand } = await import(
344
+ '../../../src/commands/broadcasts/create'
345
+ );
346
+ await expectExit1(() =>
347
+ createBroadcastCommand.parseAsync(
348
+ [
349
+ '--from',
350
+ 'hello@domain.com',
351
+ '--subject',
352
+ 'News',
353
+ '--segment-id',
354
+ '00000000-0000-0000-0000-000000000bad',
355
+ '--html',
356
+ '<p>Hi</p>',
357
+ ],
358
+ { from: 'user' },
359
+ ),
360
+ );
361
+
362
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
363
+ expect(output).toContain('create_error');
364
+ });
365
+
366
+ test('does not call SDK when validation fails', async () => {
367
+ setNonInteractive();
368
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
369
+ exitSpy = mockExitThrow();
370
+
371
+ const { createBroadcastCommand } = await import(
372
+ '../../../src/commands/broadcasts/create'
373
+ );
374
+ await expectExit1(() =>
375
+ createBroadcastCommand.parseAsync([], { from: 'user' }),
376
+ );
377
+
378
+ expect(mockCreate).not.toHaveBeenCalled();
379
+ });
380
+
381
+ test('reads html body from --html-file and passes it to SDK', async () => {
382
+ spies = setupOutputSpies();
383
+ readFileSpy = vi
384
+ .spyOn(files, 'readFile')
385
+ .mockReturnValue('<p>From file</p>');
386
+
387
+ const { createBroadcastCommand } = await import(
388
+ '../../../src/commands/broadcasts/create'
389
+ );
390
+ await createBroadcastCommand.parseAsync(
391
+ [
392
+ '--from',
393
+ 'hello@domain.com',
394
+ '--subject',
395
+ 'News',
396
+ '--segment-id',
397
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
398
+ '--html-file',
399
+ '/fake/email.html',
400
+ ],
401
+ { from: 'user' },
402
+ );
403
+
404
+ expect(readFileSpy).toHaveBeenCalledTimes(1);
405
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
406
+ expect(args.html).toBe('<p>From file</p>');
407
+ });
408
+
409
+ test('errors with file_read_error when --html-file path is unreadable', async () => {
410
+ setNonInteractive();
411
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
412
+ stderrSpy = vi
413
+ .spyOn(process.stderr, 'write')
414
+ .mockImplementation(() => true);
415
+ exitSpy = mockExitThrow();
416
+
417
+ const { outputError } = await import('../../../src/lib/output');
418
+ readFileSpy = vi
419
+ .spyOn(files, 'readFile')
420
+ .mockImplementation(
421
+ (filePath: string, globalOpts: { json?: boolean }) => {
422
+ outputError(
423
+ {
424
+ message: `Failed to read file: ${filePath}`,
425
+ code: 'file_read_error',
426
+ },
427
+ { json: globalOpts.json },
428
+ );
429
+ },
430
+ );
431
+
432
+ const { createBroadcastCommand } = await import(
433
+ '../../../src/commands/broadcasts/create'
434
+ );
435
+ await expectExit1(() =>
436
+ createBroadcastCommand.parseAsync(
437
+ [
438
+ '--from',
439
+ 'hello@domain.com',
440
+ '--subject',
441
+ 'News',
442
+ '--segment-id',
443
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
444
+ '--html-file',
445
+ '/nonexistent/file.html',
446
+ ],
447
+ { from: 'user' },
448
+ ),
449
+ );
450
+
451
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
452
+ expect(output).toContain('file_read_error');
453
+ });
454
+ });
@@ -0,0 +1,183 @@
1
+ import {
2
+ afterEach,
3
+ beforeEach,
4
+ describe,
5
+ expect,
6
+ type MockInstance,
7
+ test,
8
+ vi,
9
+ } from 'vitest';
10
+ import {
11
+ captureTestEnv,
12
+ expectExit1,
13
+ mockExitThrow,
14
+ mockSdkError,
15
+ setNonInteractive,
16
+ setupOutputSpies,
17
+ } from '../../helpers';
18
+
19
+ const mockRemove = vi.fn(async () => ({
20
+ data: {
21
+ object: 'broadcast' as const,
22
+ id: 'd1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
23
+ deleted: true,
24
+ },
25
+ error: null,
26
+ }));
27
+
28
+ vi.mock('resend', () => ({
29
+ Resend: class MockResend {
30
+ constructor(public key: string) {}
31
+ broadcasts = { remove: mockRemove };
32
+ },
33
+ }));
34
+
35
+ describe('broadcasts delete command', () => {
36
+ const restoreEnv = captureTestEnv();
37
+ let spies: ReturnType<typeof setupOutputSpies> | undefined;
38
+ let errorSpy: MockInstance | undefined;
39
+ let stderrSpy: MockInstance | undefined;
40
+ let exitSpy: MockInstance | undefined;
41
+
42
+ beforeEach(() => {
43
+ process.env.RESEND_API_KEY = 're_test_key';
44
+ mockRemove.mockClear();
45
+ });
46
+
47
+ afterEach(() => {
48
+ restoreEnv();
49
+ errorSpy?.mockRestore();
50
+ stderrSpy?.mockRestore();
51
+ exitSpy?.mockRestore();
52
+ spies = undefined;
53
+ errorSpy = undefined;
54
+ stderrSpy = undefined;
55
+ exitSpy = undefined;
56
+ });
57
+
58
+ test('deletes broadcast with --yes flag', async () => {
59
+ spies = setupOutputSpies();
60
+
61
+ const { deleteBroadcastCommand } = await import(
62
+ '../../../src/commands/broadcasts/delete'
63
+ );
64
+ await deleteBroadcastCommand.parseAsync(
65
+ ['d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6', '--yes'],
66
+ {
67
+ from: 'user',
68
+ },
69
+ );
70
+
71
+ expect(mockRemove).toHaveBeenCalledTimes(1);
72
+ expect(mockRemove.mock.calls[0][0]).toBe(
73
+ 'd1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
74
+ );
75
+ });
76
+
77
+ test('outputs JSON result when non-interactive', async () => {
78
+ spies = setupOutputSpies();
79
+
80
+ const { deleteBroadcastCommand } = await import(
81
+ '../../../src/commands/broadcasts/delete'
82
+ );
83
+ await deleteBroadcastCommand.parseAsync(
84
+ ['d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6', '--yes'],
85
+ {
86
+ from: 'user',
87
+ },
88
+ );
89
+
90
+ const output = spies.logSpy.mock.calls[0][0] as string;
91
+ const parsed = JSON.parse(output);
92
+ expect(parsed.deleted).toBe(true);
93
+ expect(parsed.id).toBe('d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6');
94
+ expect(parsed.object).toBe('broadcast');
95
+ });
96
+
97
+ test('errors with confirmation_required when --yes absent in non-interactive mode', async () => {
98
+ setNonInteractive();
99
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
100
+ exitSpy = mockExitThrow();
101
+
102
+ const { deleteBroadcastCommand } = await import(
103
+ '../../../src/commands/broadcasts/delete'
104
+ );
105
+ await expectExit1(() =>
106
+ deleteBroadcastCommand.parseAsync(
107
+ ['d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6'],
108
+ { from: 'user' },
109
+ ),
110
+ );
111
+
112
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
113
+ expect(output).toContain('confirmation_required');
114
+ });
115
+
116
+ test('does not call SDK when confirmation_required error is raised', async () => {
117
+ setNonInteractive();
118
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
119
+ exitSpy = mockExitThrow();
120
+
121
+ const { deleteBroadcastCommand } = await import(
122
+ '../../../src/commands/broadcasts/delete'
123
+ );
124
+ await expectExit1(() =>
125
+ deleteBroadcastCommand.parseAsync(
126
+ ['d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6'],
127
+ { from: 'user' },
128
+ ),
129
+ );
130
+
131
+ expect(mockRemove).not.toHaveBeenCalled();
132
+ });
133
+
134
+ test('errors with auth_error when no API key', async () => {
135
+ setNonInteractive();
136
+ delete process.env.RESEND_API_KEY;
137
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
138
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
139
+ exitSpy = mockExitThrow();
140
+
141
+ const { deleteBroadcastCommand } = await import(
142
+ '../../../src/commands/broadcasts/delete'
143
+ );
144
+ await expectExit1(() =>
145
+ deleteBroadcastCommand.parseAsync(
146
+ ['d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6', '--yes'],
147
+ {
148
+ from: 'user',
149
+ },
150
+ ),
151
+ );
152
+
153
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
154
+ expect(output).toContain('auth_error');
155
+ });
156
+
157
+ test('errors with delete_error when SDK returns an error', async () => {
158
+ setNonInteractive();
159
+ mockRemove.mockResolvedValueOnce(
160
+ mockSdkError('Cannot delete sent broadcast', 'validation_error'),
161
+ );
162
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
163
+ stderrSpy = vi
164
+ .spyOn(process.stderr, 'write')
165
+ .mockImplementation(() => true);
166
+ exitSpy = mockExitThrow();
167
+
168
+ const { deleteBroadcastCommand } = await import(
169
+ '../../../src/commands/broadcasts/delete'
170
+ );
171
+ await expectExit1(() =>
172
+ deleteBroadcastCommand.parseAsync(
173
+ ['s1e2n3t4-5a6b-7c8d-9e0f-a1b2c3d4e5f6', '--yes'],
174
+ {
175
+ from: 'user',
176
+ },
177
+ ),
178
+ );
179
+
180
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
181
+ expect(output).toContain('delete_error');
182
+ });
183
+ });