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,288 @@
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 mockUpdate = 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 = { update: mockUpdate };
29
+ },
30
+ }));
31
+
32
+ describe('broadcasts update 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
+ mockUpdate.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('updates broadcast subject', async () => {
59
+ spies = setupOutputSpies();
60
+
61
+ const { updateBroadcastCommand } = await import(
62
+ '../../../src/commands/broadcasts/update'
63
+ );
64
+ await updateBroadcastCommand.parseAsync(
65
+ ['d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6', '--subject', 'Updated Subject'],
66
+ { from: 'user' },
67
+ );
68
+
69
+ expect(mockUpdate).toHaveBeenCalledTimes(1);
70
+ expect(mockUpdate.mock.calls[0][0]).toBe(
71
+ 'd1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
72
+ );
73
+ const payload = mockUpdate.mock.calls[0][1] as Record<string, unknown>;
74
+ expect(payload.subject).toBe('Updated Subject');
75
+ });
76
+
77
+ test('passes all update flags to SDK', async () => {
78
+ spies = setupOutputSpies();
79
+
80
+ const { updateBroadcastCommand } = await import(
81
+ '../../../src/commands/broadcasts/update'
82
+ );
83
+ await updateBroadcastCommand.parseAsync(
84
+ [
85
+ 'd1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
86
+ '--from',
87
+ 'new@domain.com',
88
+ '--subject',
89
+ 'New Subject',
90
+ '--text',
91
+ 'New body',
92
+ '--name',
93
+ 'New Label',
94
+ ],
95
+ { from: 'user' },
96
+ );
97
+
98
+ const payload = mockUpdate.mock.calls[0][1] as Record<string, unknown>;
99
+ expect(payload.from).toBe('new@domain.com');
100
+ expect(payload.subject).toBe('New Subject');
101
+ expect(payload.text).toBe('New body');
102
+ expect(payload.name).toBe('New Label');
103
+ });
104
+
105
+ test('outputs JSON id when non-interactive', async () => {
106
+ spies = setupOutputSpies();
107
+
108
+ const { updateBroadcastCommand } = await import(
109
+ '../../../src/commands/broadcasts/update'
110
+ );
111
+ await updateBroadcastCommand.parseAsync(
112
+ ['d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6', '--subject', 'Updated'],
113
+ { from: 'user' },
114
+ );
115
+
116
+ const output = spies.logSpy.mock.calls[0][0] as string;
117
+ const parsed = JSON.parse(output);
118
+ expect(parsed.id).toBe('d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6');
119
+ });
120
+
121
+ test('omits undefined fields from SDK payload', async () => {
122
+ spies = setupOutputSpies();
123
+
124
+ const { updateBroadcastCommand } = await import(
125
+ '../../../src/commands/broadcasts/update'
126
+ );
127
+ await updateBroadcastCommand.parseAsync(
128
+ ['d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6', '--name', 'Only Name'],
129
+ { from: 'user' },
130
+ );
131
+
132
+ const payload = mockUpdate.mock.calls[0][1] as Record<string, unknown>;
133
+ expect(payload.name).toBe('Only Name');
134
+ expect(payload.from).toBeUndefined();
135
+ expect(payload.subject).toBeUndefined();
136
+ });
137
+
138
+ test('errors with no_changes when no flags are provided', async () => {
139
+ setNonInteractive();
140
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
141
+ exitSpy = mockExitThrow();
142
+
143
+ const { updateBroadcastCommand } = await import(
144
+ '../../../src/commands/broadcasts/update'
145
+ );
146
+ await expectExit1(() =>
147
+ updateBroadcastCommand.parseAsync(
148
+ ['d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6'],
149
+ { from: 'user' },
150
+ ),
151
+ );
152
+
153
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
154
+ expect(output).toContain('no_changes');
155
+ });
156
+
157
+ test('does not call SDK when no_changes error is raised', async () => {
158
+ setNonInteractive();
159
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
160
+ exitSpy = mockExitThrow();
161
+
162
+ const { updateBroadcastCommand } = await import(
163
+ '../../../src/commands/broadcasts/update'
164
+ );
165
+ await expectExit1(() =>
166
+ updateBroadcastCommand.parseAsync(
167
+ ['d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6'],
168
+ { from: 'user' },
169
+ ),
170
+ );
171
+
172
+ expect(mockUpdate).not.toHaveBeenCalled();
173
+ });
174
+
175
+ test('errors with auth_error when no API key', async () => {
176
+ setNonInteractive();
177
+ delete process.env.RESEND_API_KEY;
178
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
179
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
180
+ exitSpy = mockExitThrow();
181
+
182
+ const { updateBroadcastCommand } = await import(
183
+ '../../../src/commands/broadcasts/update'
184
+ );
185
+ await expectExit1(() =>
186
+ updateBroadcastCommand.parseAsync(
187
+ ['d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6', '--subject', 'X'],
188
+ {
189
+ from: 'user',
190
+ },
191
+ ),
192
+ );
193
+
194
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
195
+ expect(output).toContain('auth_error');
196
+ });
197
+
198
+ test('errors with update_error when SDK returns an error', async () => {
199
+ setNonInteractive();
200
+ mockUpdate.mockResolvedValueOnce(
201
+ mockSdkError('Cannot update sent broadcast', 'validation_error'),
202
+ );
203
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
204
+ stderrSpy = vi
205
+ .spyOn(process.stderr, 'write')
206
+ .mockImplementation(() => true);
207
+ exitSpy = mockExitThrow();
208
+
209
+ const { updateBroadcastCommand } = await import(
210
+ '../../../src/commands/broadcasts/update'
211
+ );
212
+ await expectExit1(() =>
213
+ updateBroadcastCommand.parseAsync(
214
+ ['s1e2n3t4-5a6b-7c8d-9e0f-a1b2c3d4e5f6', '--subject', 'New'],
215
+ {
216
+ from: 'user',
217
+ },
218
+ ),
219
+ );
220
+
221
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
222
+ expect(output).toContain('update_error');
223
+ });
224
+
225
+ test('reads html body from --html-file and passes it to SDK', async () => {
226
+ spies = setupOutputSpies();
227
+ readFileSpy = vi
228
+ .spyOn(files, 'readFile')
229
+ .mockReturnValue('<p>Updated from file</p>');
230
+
231
+ const { updateBroadcastCommand } = await import(
232
+ '../../../src/commands/broadcasts/update'
233
+ );
234
+ await updateBroadcastCommand.parseAsync(
235
+ [
236
+ 'd1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
237
+ '--html-file',
238
+ '/fake/email.html',
239
+ ],
240
+ { from: 'user' },
241
+ );
242
+
243
+ expect(readFileSpy).toHaveBeenCalledTimes(1);
244
+ const payload = mockUpdate.mock.calls[0][1] as Record<string, unknown>;
245
+ expect(payload.html).toBe('<p>Updated from file</p>');
246
+ });
247
+
248
+ test('errors with file_read_error when --html-file path is unreadable', async () => {
249
+ setNonInteractive();
250
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
251
+ stderrSpy = vi
252
+ .spyOn(process.stderr, 'write')
253
+ .mockImplementation(() => true);
254
+ exitSpy = mockExitThrow();
255
+
256
+ const { outputError } = await import('../../../src/lib/output');
257
+ readFileSpy = vi
258
+ .spyOn(files, 'readFile')
259
+ .mockImplementation(
260
+ (filePath: string, globalOpts: { json?: boolean }) => {
261
+ outputError(
262
+ {
263
+ message: `Failed to read file: ${filePath}`,
264
+ code: 'file_read_error',
265
+ },
266
+ { json: globalOpts.json },
267
+ );
268
+ },
269
+ );
270
+
271
+ const { updateBroadcastCommand } = await import(
272
+ '../../../src/commands/broadcasts/update'
273
+ );
274
+ await expectExit1(() =>
275
+ updateBroadcastCommand.parseAsync(
276
+ [
277
+ 'd1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
278
+ '--html-file',
279
+ '/nonexistent/file.html',
280
+ ],
281
+ { from: 'user' },
282
+ ),
283
+ );
284
+
285
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
286
+ expect(output).toContain('file_read_error');
287
+ });
288
+ });
@@ -0,0 +1,251 @@
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 mockCreate = vi.fn(async () => ({
20
+ data: {
21
+ object: 'contact_property' as const,
22
+ id: 'b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d',
23
+ },
24
+ error: null,
25
+ }));
26
+
27
+ vi.mock('resend', () => ({
28
+ Resend: class MockResend {
29
+ constructor(public key: string) {}
30
+ contactProperties = { create: mockCreate };
31
+ },
32
+ }));
33
+
34
+ describe('contact-properties create command', () => {
35
+ const restoreEnv = captureTestEnv();
36
+ let spies: ReturnType<typeof setupOutputSpies> | undefined;
37
+ let errorSpy: MockInstance | undefined;
38
+ let stderrSpy: MockInstance | undefined;
39
+ let exitSpy: MockInstance | undefined;
40
+
41
+ beforeEach(() => {
42
+ process.env.RESEND_API_KEY = 're_test_key';
43
+ mockCreate.mockClear();
44
+ });
45
+
46
+ afterEach(() => {
47
+ restoreEnv();
48
+ errorSpy?.mockRestore();
49
+ stderrSpy?.mockRestore();
50
+ exitSpy?.mockRestore();
51
+ spies = undefined;
52
+ errorSpy = undefined;
53
+ stderrSpy = undefined;
54
+ exitSpy = undefined;
55
+ });
56
+
57
+ test('creates property with --key and --type', async () => {
58
+ spies = setupOutputSpies();
59
+
60
+ const { createContactPropertyCommand } = await import(
61
+ '../../../src/commands/contact-properties/create'
62
+ );
63
+ await createContactPropertyCommand.parseAsync(
64
+ ['--key', 'company_name', '--type', 'string'],
65
+ { from: 'user' },
66
+ );
67
+
68
+ expect(mockCreate).toHaveBeenCalledTimes(1);
69
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
70
+ expect(args.key).toBe('company_name');
71
+ expect(args.type).toBe('string');
72
+ });
73
+
74
+ test('creates number-type property', async () => {
75
+ spies = setupOutputSpies();
76
+
77
+ const { createContactPropertyCommand } = await import(
78
+ '../../../src/commands/contact-properties/create'
79
+ );
80
+ await createContactPropertyCommand.parseAsync(
81
+ ['--key', 'score', '--type', 'number'],
82
+ { from: 'user' },
83
+ );
84
+
85
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
86
+ expect(args.key).toBe('score');
87
+ expect(args.type).toBe('number');
88
+ });
89
+
90
+ test('passes string fallback-value to SDK', async () => {
91
+ spies = setupOutputSpies();
92
+
93
+ const { createContactPropertyCommand } = await import(
94
+ '../../../src/commands/contact-properties/create'
95
+ );
96
+ await createContactPropertyCommand.parseAsync(
97
+ [
98
+ '--key',
99
+ 'company_name',
100
+ '--type',
101
+ 'string',
102
+ '--fallback-value',
103
+ 'Unknown',
104
+ ],
105
+ { from: 'user' },
106
+ );
107
+
108
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
109
+ expect(args.fallbackValue).toBe('Unknown');
110
+ });
111
+
112
+ test('coerces fallback-value to number for number-type properties', async () => {
113
+ spies = setupOutputSpies();
114
+
115
+ const { createContactPropertyCommand } = await import(
116
+ '../../../src/commands/contact-properties/create'
117
+ );
118
+ await createContactPropertyCommand.parseAsync(
119
+ ['--key', 'score', '--type', 'number', '--fallback-value', '42'],
120
+ { from: 'user' },
121
+ );
122
+
123
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
124
+ expect(args.fallbackValue).toBe(42);
125
+ });
126
+
127
+ test('outputs JSON id when non-interactive', async () => {
128
+ spies = setupOutputSpies();
129
+
130
+ const { createContactPropertyCommand } = await import(
131
+ '../../../src/commands/contact-properties/create'
132
+ );
133
+ await createContactPropertyCommand.parseAsync(
134
+ ['--key', 'plan', '--type', 'string'],
135
+ { from: 'user' },
136
+ );
137
+
138
+ const output = spies.logSpy.mock.calls[0][0] as string;
139
+ const parsed = JSON.parse(output);
140
+ expect(parsed.object).toBe('contact_property');
141
+ expect(parsed.id).toBe('b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d');
142
+ });
143
+
144
+ test('errors with missing_key in non-interactive mode', async () => {
145
+ setNonInteractive();
146
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
147
+ exitSpy = mockExitThrow();
148
+
149
+ const { createContactPropertyCommand } = await import(
150
+ '../../../src/commands/contact-properties/create'
151
+ );
152
+ await expectExit1(() =>
153
+ createContactPropertyCommand.parseAsync(['--type', 'string'], {
154
+ from: 'user',
155
+ }),
156
+ );
157
+
158
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
159
+ expect(output).toContain('missing_key');
160
+ });
161
+
162
+ test('errors with missing_type in non-interactive mode', async () => {
163
+ setNonInteractive();
164
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
165
+ exitSpy = mockExitThrow();
166
+
167
+ const { createContactPropertyCommand } = await import(
168
+ '../../../src/commands/contact-properties/create'
169
+ );
170
+ await expectExit1(() =>
171
+ createContactPropertyCommand.parseAsync(['--key', 'company_name'], {
172
+ from: 'user',
173
+ }),
174
+ );
175
+
176
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
177
+ expect(output).toContain('missing_type');
178
+ });
179
+
180
+ test('errors with invalid_fallback_value when number-type gets a non-numeric fallback', async () => {
181
+ setNonInteractive();
182
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
183
+ exitSpy = mockExitThrow();
184
+
185
+ const { createContactPropertyCommand } = await import(
186
+ '../../../src/commands/contact-properties/create'
187
+ );
188
+ await expectExit1(() =>
189
+ createContactPropertyCommand.parseAsync(
190
+ [
191
+ '--key',
192
+ 'score',
193
+ '--type',
194
+ 'number',
195
+ '--fallback-value',
196
+ 'not-a-number',
197
+ ],
198
+ { from: 'user' },
199
+ ),
200
+ );
201
+
202
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
203
+ expect(output).toContain('invalid_fallback_value');
204
+ });
205
+
206
+ test('errors with auth_error when no API key', async () => {
207
+ setNonInteractive();
208
+ delete process.env.RESEND_API_KEY;
209
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
210
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
211
+ exitSpy = mockExitThrow();
212
+
213
+ const { createContactPropertyCommand } = await import(
214
+ '../../../src/commands/contact-properties/create'
215
+ );
216
+ await expectExit1(() =>
217
+ createContactPropertyCommand.parseAsync(
218
+ ['--key', 'company_name', '--type', 'string'],
219
+ { from: 'user' },
220
+ ),
221
+ );
222
+
223
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
224
+ expect(output).toContain('auth_error');
225
+ });
226
+
227
+ test('errors with create_error when SDK returns an error', async () => {
228
+ setNonInteractive();
229
+ mockCreate.mockResolvedValueOnce(
230
+ mockSdkError('Key already exists', 'validation_error'),
231
+ );
232
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
233
+ stderrSpy = vi
234
+ .spyOn(process.stderr, 'write')
235
+ .mockImplementation(() => true);
236
+ exitSpy = mockExitThrow();
237
+
238
+ const { createContactPropertyCommand } = await import(
239
+ '../../../src/commands/contact-properties/create'
240
+ );
241
+ await expectExit1(() =>
242
+ createContactPropertyCommand.parseAsync(
243
+ ['--key', 'company_name', '--type', 'string'],
244
+ { from: 'user' },
245
+ ),
246
+ );
247
+
248
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
249
+ expect(output).toContain('create_error');
250
+ });
251
+ });