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.
- package/__tests__/resend-plugin.test.js +22 -1
- package/package.json +1 -1
- package/plugins/plugins.json +2 -2
- package/plugins/resend/plugin.json +279 -2
- package/plugins/resend/skills/quickstart/SKILL.md +32 -13
- package/temp_resend_cli/repo/.github/scripts/pr-title-check.js +34 -0
- package/temp_resend_cli/repo/.github/workflows/ci.yml +67 -0
- package/temp_resend_cli/repo/.github/workflows/post-release.yml +51 -0
- package/temp_resend_cli/repo/.github/workflows/pr-title-check.yml +13 -0
- package/temp_resend_cli/repo/.github/workflows/release.yml +175 -0
- package/temp_resend_cli/repo/.github/workflows/test-install-unix.yml +34 -0
- package/temp_resend_cli/repo/.github/workflows/test-install-windows.yml +48 -0
- package/temp_resend_cli/repo/CHANGELOG.md +31 -0
- package/temp_resend_cli/repo/LICENSE +21 -0
- package/temp_resend_cli/repo/README.md +450 -0
- package/temp_resend_cli/repo/biome.json +36 -0
- package/temp_resend_cli/repo/install.ps1 +141 -0
- package/temp_resend_cli/repo/install.sh +301 -0
- package/temp_resend_cli/repo/package.json +61 -0
- package/temp_resend_cli/repo/pnpm-lock.yaml +2439 -0
- package/temp_resend_cli/repo/renovate.json +4 -0
- package/temp_resend_cli/repo/src/cli.ts +98 -0
- package/temp_resend_cli/repo/src/commands/api-keys/create.ts +114 -0
- package/temp_resend_cli/repo/src/commands/api-keys/delete.ts +47 -0
- package/temp_resend_cli/repo/src/commands/api-keys/index.ts +26 -0
- package/temp_resend_cli/repo/src/commands/api-keys/list.ts +35 -0
- package/temp_resend_cli/repo/src/commands/api-keys/utils.ts +8 -0
- package/temp_resend_cli/repo/src/commands/auth/index.ts +20 -0
- package/temp_resend_cli/repo/src/commands/auth/login.ts +234 -0
- package/temp_resend_cli/repo/src/commands/auth/logout.ts +105 -0
- package/temp_resend_cli/repo/src/commands/broadcasts/create.ts +196 -0
- package/temp_resend_cli/repo/src/commands/broadcasts/delete.ts +46 -0
- package/temp_resend_cli/repo/src/commands/broadcasts/get.ts +59 -0
- package/temp_resend_cli/repo/src/commands/broadcasts/index.ts +43 -0
- package/temp_resend_cli/repo/src/commands/broadcasts/list.ts +60 -0
- package/temp_resend_cli/repo/src/commands/broadcasts/send.ts +56 -0
- package/temp_resend_cli/repo/src/commands/broadcasts/update.ts +95 -0
- package/temp_resend_cli/repo/src/commands/broadcasts/utils.ts +35 -0
- package/temp_resend_cli/repo/src/commands/contact-properties/create.ts +118 -0
- package/temp_resend_cli/repo/src/commands/contact-properties/delete.ts +48 -0
- package/temp_resend_cli/repo/src/commands/contact-properties/get.ts +46 -0
- package/temp_resend_cli/repo/src/commands/contact-properties/index.ts +48 -0
- package/temp_resend_cli/repo/src/commands/contact-properties/list.ts +68 -0
- package/temp_resend_cli/repo/src/commands/contact-properties/update.ts +88 -0
- package/temp_resend_cli/repo/src/commands/contact-properties/utils.ts +17 -0
- package/temp_resend_cli/repo/src/commands/contacts/add-segment.ts +78 -0
- package/temp_resend_cli/repo/src/commands/contacts/create.ts +122 -0
- package/temp_resend_cli/repo/src/commands/contacts/delete.ts +49 -0
- package/temp_resend_cli/repo/src/commands/contacts/get.ts +53 -0
- package/temp_resend_cli/repo/src/commands/contacts/index.ts +58 -0
- package/temp_resend_cli/repo/src/commands/contacts/list.ts +57 -0
- package/temp_resend_cli/repo/src/commands/contacts/remove-segment.ts +48 -0
- package/temp_resend_cli/repo/src/commands/contacts/segments.ts +39 -0
- package/temp_resend_cli/repo/src/commands/contacts/topics.ts +45 -0
- package/temp_resend_cli/repo/src/commands/contacts/update-topics.ts +90 -0
- package/temp_resend_cli/repo/src/commands/contacts/update.ts +77 -0
- package/temp_resend_cli/repo/src/commands/contacts/utils.ts +119 -0
- package/temp_resend_cli/repo/src/commands/doctor.ts +216 -0
- package/temp_resend_cli/repo/src/commands/domains/create.ts +83 -0
- package/temp_resend_cli/repo/src/commands/domains/delete.ts +42 -0
- package/temp_resend_cli/repo/src/commands/domains/get.ts +47 -0
- package/temp_resend_cli/repo/src/commands/domains/index.ts +35 -0
- package/temp_resend_cli/repo/src/commands/domains/list.ts +53 -0
- package/temp_resend_cli/repo/src/commands/domains/update.ts +75 -0
- package/temp_resend_cli/repo/src/commands/domains/utils.ts +44 -0
- package/temp_resend_cli/repo/src/commands/domains/verify.ts +38 -0
- package/temp_resend_cli/repo/src/commands/emails/batch.ts +140 -0
- package/temp_resend_cli/repo/src/commands/emails/get.ts +44 -0
- package/temp_resend_cli/repo/src/commands/emails/index.ts +30 -0
- package/temp_resend_cli/repo/src/commands/emails/list.ts +84 -0
- package/temp_resend_cli/repo/src/commands/emails/receiving/attachment.ts +55 -0
- package/temp_resend_cli/repo/src/commands/emails/receiving/attachments.ts +68 -0
- package/temp_resend_cli/repo/src/commands/emails/receiving/get.ts +58 -0
- package/temp_resend_cli/repo/src/commands/emails/receiving/index.ts +28 -0
- package/temp_resend_cli/repo/src/commands/emails/receiving/list.ts +59 -0
- package/temp_resend_cli/repo/src/commands/emails/receiving/utils.ts +38 -0
- package/temp_resend_cli/repo/src/commands/emails/send.ts +189 -0
- package/temp_resend_cli/repo/src/commands/open.ts +27 -0
- package/temp_resend_cli/repo/src/commands/segments/create.ts +50 -0
- package/temp_resend_cli/repo/src/commands/segments/delete.ts +47 -0
- package/temp_resend_cli/repo/src/commands/segments/get.ts +38 -0
- package/temp_resend_cli/repo/src/commands/segments/index.ts +36 -0
- package/temp_resend_cli/repo/src/commands/segments/list.ts +58 -0
- package/temp_resend_cli/repo/src/commands/segments/utils.ts +7 -0
- package/temp_resend_cli/repo/src/commands/teams/index.ts +10 -0
- package/temp_resend_cli/repo/src/commands/teams/list.ts +35 -0
- package/temp_resend_cli/repo/src/commands/teams/remove.ts +86 -0
- package/temp_resend_cli/repo/src/commands/teams/switch.ts +76 -0
- package/temp_resend_cli/repo/src/commands/topics/create.ts +73 -0
- package/temp_resend_cli/repo/src/commands/topics/delete.ts +47 -0
- package/temp_resend_cli/repo/src/commands/topics/get.ts +42 -0
- package/temp_resend_cli/repo/src/commands/topics/index.ts +42 -0
- package/temp_resend_cli/repo/src/commands/topics/list.ts +34 -0
- package/temp_resend_cli/repo/src/commands/topics/update.ts +59 -0
- package/temp_resend_cli/repo/src/commands/topics/utils.ts +16 -0
- package/temp_resend_cli/repo/src/commands/webhooks/create.ts +128 -0
- package/temp_resend_cli/repo/src/commands/webhooks/delete.ts +49 -0
- package/temp_resend_cli/repo/src/commands/webhooks/get.ts +42 -0
- package/temp_resend_cli/repo/src/commands/webhooks/index.ts +42 -0
- package/temp_resend_cli/repo/src/commands/webhooks/list.ts +55 -0
- package/temp_resend_cli/repo/src/commands/webhooks/listen.ts +379 -0
- package/temp_resend_cli/repo/src/commands/webhooks/update.ts +83 -0
- package/temp_resend_cli/repo/src/commands/webhooks/utils.ts +36 -0
- package/temp_resend_cli/repo/src/commands/whoami.ts +71 -0
- package/temp_resend_cli/repo/src/lib/actions.ts +157 -0
- package/temp_resend_cli/repo/src/lib/client.ts +37 -0
- package/temp_resend_cli/repo/src/lib/config.ts +217 -0
- package/temp_resend_cli/repo/src/lib/files.ts +15 -0
- package/temp_resend_cli/repo/src/lib/help-text.ts +38 -0
- package/temp_resend_cli/repo/src/lib/output.ts +56 -0
- package/temp_resend_cli/repo/src/lib/pagination.ts +36 -0
- package/temp_resend_cli/repo/src/lib/prompts.ts +149 -0
- package/temp_resend_cli/repo/src/lib/spinner.ts +100 -0
- package/temp_resend_cli/repo/src/lib/table.ts +57 -0
- package/temp_resend_cli/repo/src/lib/tty.ts +28 -0
- package/temp_resend_cli/repo/src/lib/update-check.ts +169 -0
- package/temp_resend_cli/repo/src/lib/version.ts +4 -0
- package/temp_resend_cli/repo/tests/commands/api-keys/create.test.ts +196 -0
- package/temp_resend_cli/repo/tests/commands/api-keys/delete.test.ts +157 -0
- package/temp_resend_cli/repo/tests/commands/api-keys/list.test.ts +134 -0
- package/temp_resend_cli/repo/tests/commands/auth/login.test.ts +153 -0
- package/temp_resend_cli/repo/tests/commands/auth/logout.test.ts +153 -0
- package/temp_resend_cli/repo/tests/commands/broadcasts/create.test.ts +454 -0
- package/temp_resend_cli/repo/tests/commands/broadcasts/delete.test.ts +183 -0
- package/temp_resend_cli/repo/tests/commands/broadcasts/get.test.ts +147 -0
- package/temp_resend_cli/repo/tests/commands/broadcasts/list.test.ts +199 -0
- package/temp_resend_cli/repo/tests/commands/broadcasts/send.test.ts +162 -0
- package/temp_resend_cli/repo/tests/commands/broadcasts/update.test.ts +288 -0
- package/temp_resend_cli/repo/tests/commands/contact-properties/create.test.ts +251 -0
- package/temp_resend_cli/repo/tests/commands/contact-properties/delete.test.ts +184 -0
- package/temp_resend_cli/repo/tests/commands/contact-properties/get.test.ts +145 -0
- package/temp_resend_cli/repo/tests/commands/contact-properties/list.test.ts +181 -0
- package/temp_resend_cli/repo/tests/commands/contact-properties/update.test.ts +217 -0
- package/temp_resend_cli/repo/tests/commands/contacts/add-segment.test.ts +189 -0
- package/temp_resend_cli/repo/tests/commands/contacts/create.test.ts +271 -0
- package/temp_resend_cli/repo/tests/commands/contacts/delete.test.ts +193 -0
- package/temp_resend_cli/repo/tests/commands/contacts/get.test.ts +149 -0
- package/temp_resend_cli/repo/tests/commands/contacts/list.test.ts +176 -0
- package/temp_resend_cli/repo/tests/commands/contacts/remove-segment.test.ts +167 -0
- package/temp_resend_cli/repo/tests/commands/contacts/segments.test.ts +168 -0
- package/temp_resend_cli/repo/tests/commands/contacts/topics.test.ts +164 -0
- package/temp_resend_cli/repo/tests/commands/contacts/update-topics.test.ts +248 -0
- package/temp_resend_cli/repo/tests/commands/contacts/update.test.ts +206 -0
- package/temp_resend_cli/repo/tests/commands/doctor.test.ts +164 -0
- package/temp_resend_cli/repo/tests/commands/domains/create.test.ts +193 -0
- package/temp_resend_cli/repo/tests/commands/domains/delete.test.ts +157 -0
- package/temp_resend_cli/repo/tests/commands/domains/get.test.ts +138 -0
- package/temp_resend_cli/repo/tests/commands/domains/list.test.ts +165 -0
- package/temp_resend_cli/repo/tests/commands/domains/update.test.ts +224 -0
- package/temp_resend_cli/repo/tests/commands/domains/verify.test.ts +118 -0
- package/temp_resend_cli/repo/tests/commands/emails/batch.test.ts +324 -0
- package/temp_resend_cli/repo/tests/commands/emails/get.test.ts +132 -0
- package/temp_resend_cli/repo/tests/commands/emails/receiving/attachment.test.ts +141 -0
- package/temp_resend_cli/repo/tests/commands/emails/receiving/attachments.test.ts +169 -0
- package/temp_resend_cli/repo/tests/commands/emails/receiving/get.test.ts +141 -0
- package/temp_resend_cli/repo/tests/commands/emails/receiving/list.test.ts +182 -0
- package/temp_resend_cli/repo/tests/commands/emails/send.test.ts +312 -0
- package/temp_resend_cli/repo/tests/commands/segments/create.test.ts +164 -0
- package/temp_resend_cli/repo/tests/commands/segments/delete.test.ts +183 -0
- package/temp_resend_cli/repo/tests/commands/segments/get.test.ts +138 -0
- package/temp_resend_cli/repo/tests/commands/segments/list.test.ts +174 -0
- package/temp_resend_cli/repo/tests/commands/teams/list.test.ts +62 -0
- package/temp_resend_cli/repo/tests/commands/teams/remove.test.ts +110 -0
- package/temp_resend_cli/repo/tests/commands/teams/switch.test.ts +103 -0
- package/temp_resend_cli/repo/tests/commands/topics/create.test.ts +192 -0
- package/temp_resend_cli/repo/tests/commands/topics/delete.test.ts +157 -0
- package/temp_resend_cli/repo/tests/commands/topics/get.test.ts +126 -0
- package/temp_resend_cli/repo/tests/commands/topics/list.test.ts +125 -0
- package/temp_resend_cli/repo/tests/commands/topics/update.test.ts +178 -0
- package/temp_resend_cli/repo/tests/commands/webhooks/create.test.ts +225 -0
- package/temp_resend_cli/repo/tests/commands/webhooks/delete.test.ts +157 -0
- package/temp_resend_cli/repo/tests/commands/webhooks/get.test.ts +126 -0
- package/temp_resend_cli/repo/tests/commands/webhooks/list.test.ts +178 -0
- package/temp_resend_cli/repo/tests/commands/webhooks/update.test.ts +207 -0
- package/temp_resend_cli/repo/tests/commands/whoami.test.ts +98 -0
- package/temp_resend_cli/repo/tests/e2e/smoke.test.ts +93 -0
- package/temp_resend_cli/repo/tests/helpers.ts +86 -0
- package/temp_resend_cli/repo/tests/lib/client.test.ts +71 -0
- package/temp_resend_cli/repo/tests/lib/config.test.ts +451 -0
- package/temp_resend_cli/repo/tests/lib/files.test.ts +73 -0
- package/temp_resend_cli/repo/tests/lib/help-text.test.ts +97 -0
- package/temp_resend_cli/repo/tests/lib/output.test.ts +136 -0
- package/temp_resend_cli/repo/tests/lib/prompts.test.ts +185 -0
- package/temp_resend_cli/repo/tests/lib/spinner.test.ts +166 -0
- package/temp_resend_cli/repo/tests/lib/table.test.ts +63 -0
- package/temp_resend_cli/repo/tests/lib/tty.test.ts +89 -0
- package/temp_resend_cli/repo/tests/lib/update-check.test.ts +179 -0
- package/temp_resend_cli/repo/tsconfig.json +14 -0
- package/temp_resend_cli/repo/vitest.config.e2e.ts +8 -0
- package/temp_resend_cli/repo/vitest.config.ts +10 -0
- package/tests/test-resend-smoke.sh +7 -3
|
@@ -0,0 +1,178 @@
|
|
|
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 mockList = vi.fn(async () => ({
|
|
20
|
+
data: {
|
|
21
|
+
object: 'list' as const,
|
|
22
|
+
has_more: false,
|
|
23
|
+
data: [
|
|
24
|
+
{
|
|
25
|
+
id: 'wh_abc123',
|
|
26
|
+
endpoint: 'https://app.example.com/hooks/resend',
|
|
27
|
+
events: ['email.sent', 'email.bounced'] as string[],
|
|
28
|
+
status: 'enabled' as const,
|
|
29
|
+
created_at: '2026-01-01T00:00:00.000Z',
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
error: null,
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
vi.mock('resend', () => ({
|
|
37
|
+
Resend: class MockResend {
|
|
38
|
+
constructor(public key: string) {}
|
|
39
|
+
webhooks = { list: mockList };
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
describe('webhooks list command', () => {
|
|
44
|
+
const restoreEnv = captureTestEnv();
|
|
45
|
+
let spies: ReturnType<typeof setupOutputSpies> | undefined;
|
|
46
|
+
let errorSpy: MockInstance | undefined;
|
|
47
|
+
let stderrSpy: MockInstance | undefined;
|
|
48
|
+
let exitSpy: MockInstance | undefined;
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
process.env.RESEND_API_KEY = 're_test_key';
|
|
52
|
+
mockList.mockClear();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterEach(() => {
|
|
56
|
+
restoreEnv();
|
|
57
|
+
errorSpy?.mockRestore();
|
|
58
|
+
stderrSpy?.mockRestore();
|
|
59
|
+
exitSpy?.mockRestore();
|
|
60
|
+
spies = undefined;
|
|
61
|
+
errorSpy = undefined;
|
|
62
|
+
stderrSpy = undefined;
|
|
63
|
+
exitSpy = undefined;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('calls SDK list method with default pagination', async () => {
|
|
67
|
+
spies = setupOutputSpies();
|
|
68
|
+
|
|
69
|
+
const { listWebhooksCommand } = await import(
|
|
70
|
+
'../../../src/commands/webhooks/list'
|
|
71
|
+
);
|
|
72
|
+
await listWebhooksCommand.parseAsync([], { from: 'user' });
|
|
73
|
+
|
|
74
|
+
expect(mockList).toHaveBeenCalledTimes(1);
|
|
75
|
+
const args = mockList.mock.calls[0][0] as Record<string, unknown>;
|
|
76
|
+
expect(args.limit).toBe(10);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('passes --limit to pagination options', async () => {
|
|
80
|
+
spies = setupOutputSpies();
|
|
81
|
+
|
|
82
|
+
const { listWebhooksCommand } = await import(
|
|
83
|
+
'../../../src/commands/webhooks/list'
|
|
84
|
+
);
|
|
85
|
+
await listWebhooksCommand.parseAsync(['--limit', '5'], { from: 'user' });
|
|
86
|
+
|
|
87
|
+
const args = mockList.mock.calls[0][0] as Record<string, unknown>;
|
|
88
|
+
expect(args.limit).toBe(5);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('passes --after cursor to pagination options', async () => {
|
|
92
|
+
spies = setupOutputSpies();
|
|
93
|
+
|
|
94
|
+
const { listWebhooksCommand } = await import(
|
|
95
|
+
'../../../src/commands/webhooks/list'
|
|
96
|
+
);
|
|
97
|
+
await listWebhooksCommand.parseAsync(['--after', 'wh_cursor123'], {
|
|
98
|
+
from: 'user',
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const args = mockList.mock.calls[0][0] as Record<string, unknown>;
|
|
102
|
+
expect(args.after).toBe('wh_cursor123');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('outputs JSON list with webhook data when non-interactive', async () => {
|
|
106
|
+
spies = setupOutputSpies();
|
|
107
|
+
|
|
108
|
+
const { listWebhooksCommand } = await import(
|
|
109
|
+
'../../../src/commands/webhooks/list'
|
|
110
|
+
);
|
|
111
|
+
await listWebhooksCommand.parseAsync([], { from: 'user' });
|
|
112
|
+
|
|
113
|
+
const output = spies.logSpy.mock.calls[0][0] as string;
|
|
114
|
+
const parsed = JSON.parse(output);
|
|
115
|
+
expect(Array.isArray(parsed.data)).toBe(true);
|
|
116
|
+
expect(parsed.data[0].id).toBe('wh_abc123');
|
|
117
|
+
expect(parsed.data[0].endpoint).toBe(
|
|
118
|
+
'https://app.example.com/hooks/resend',
|
|
119
|
+
);
|
|
120
|
+
expect(parsed.has_more).toBe(false);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('errors with invalid_limit for out-of-range limit', async () => {
|
|
124
|
+
setNonInteractive();
|
|
125
|
+
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
126
|
+
exitSpy = mockExitThrow();
|
|
127
|
+
|
|
128
|
+
const { listWebhooksCommand } = await import(
|
|
129
|
+
'../../../src/commands/webhooks/list'
|
|
130
|
+
);
|
|
131
|
+
await expectExit1(() =>
|
|
132
|
+
listWebhooksCommand.parseAsync(['--limit', '200'], { from: 'user' }),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
|
|
136
|
+
expect(output).toContain('invalid_limit');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('errors with auth_error when no API key', async () => {
|
|
140
|
+
setNonInteractive();
|
|
141
|
+
delete process.env.RESEND_API_KEY;
|
|
142
|
+
process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
|
|
143
|
+
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
144
|
+
exitSpy = mockExitThrow();
|
|
145
|
+
|
|
146
|
+
const { listWebhooksCommand } = await import(
|
|
147
|
+
'../../../src/commands/webhooks/list'
|
|
148
|
+
);
|
|
149
|
+
await expectExit1(() =>
|
|
150
|
+
listWebhooksCommand.parseAsync([], { from: 'user' }),
|
|
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 list_error when SDK returns an error', async () => {
|
|
158
|
+
setNonInteractive();
|
|
159
|
+
mockList.mockResolvedValueOnce(
|
|
160
|
+
mockSdkError('Server error', 'server_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 { listWebhooksCommand } = await import(
|
|
169
|
+
'../../../src/commands/webhooks/list'
|
|
170
|
+
);
|
|
171
|
+
await expectExit1(() =>
|
|
172
|
+
listWebhooksCommand.parseAsync([], { from: 'user' }),
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
|
|
176
|
+
expect(output).toContain('list_error');
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -0,0 +1,207 @@
|
|
|
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 mockUpdate = vi.fn(async () => ({
|
|
20
|
+
data: { object: 'webhook' as const, id: 'wh_abc123' },
|
|
21
|
+
error: null,
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
vi.mock('resend', () => ({
|
|
25
|
+
Resend: class MockResend {
|
|
26
|
+
constructor(public key: string) {}
|
|
27
|
+
webhooks = { update: mockUpdate };
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
describe('webhooks update command', () => {
|
|
32
|
+
const restoreEnv = captureTestEnv();
|
|
33
|
+
let spies: ReturnType<typeof setupOutputSpies> | undefined;
|
|
34
|
+
let errorSpy: MockInstance | undefined;
|
|
35
|
+
let stderrSpy: MockInstance | undefined;
|
|
36
|
+
let exitSpy: MockInstance | undefined;
|
|
37
|
+
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
process.env.RESEND_API_KEY = 're_test_key';
|
|
40
|
+
mockUpdate.mockClear();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
restoreEnv();
|
|
45
|
+
errorSpy?.mockRestore();
|
|
46
|
+
stderrSpy?.mockRestore();
|
|
47
|
+
exitSpy?.mockRestore();
|
|
48
|
+
spies = undefined;
|
|
49
|
+
errorSpy = undefined;
|
|
50
|
+
stderrSpy = undefined;
|
|
51
|
+
exitSpy = undefined;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('updates endpoint with --endpoint flag', async () => {
|
|
55
|
+
spies = setupOutputSpies();
|
|
56
|
+
|
|
57
|
+
const { updateWebhookCommand } = await import(
|
|
58
|
+
'../../../src/commands/webhooks/update'
|
|
59
|
+
);
|
|
60
|
+
await updateWebhookCommand.parseAsync(
|
|
61
|
+
['wh_abc123', '--endpoint', 'https://new-app.example.com/hooks'],
|
|
62
|
+
{ from: 'user' },
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(mockUpdate).toHaveBeenCalledTimes(1);
|
|
66
|
+
expect(mockUpdate.mock.calls[0][0]).toBe('wh_abc123');
|
|
67
|
+
const payload = mockUpdate.mock.calls[0][1] as Record<string, unknown>;
|
|
68
|
+
expect(payload.endpoint).toBe('https://new-app.example.com/hooks');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('updates events with --events flag', async () => {
|
|
72
|
+
spies = setupOutputSpies();
|
|
73
|
+
|
|
74
|
+
const { updateWebhookCommand } = await import(
|
|
75
|
+
'../../../src/commands/webhooks/update'
|
|
76
|
+
);
|
|
77
|
+
await updateWebhookCommand.parseAsync(
|
|
78
|
+
['wh_abc123', '--events', 'email.sent', 'email.bounced'],
|
|
79
|
+
{ from: 'user' },
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const payload = mockUpdate.mock.calls[0][1] as Record<string, unknown>;
|
|
83
|
+
expect(payload.events).toEqual(['email.sent', 'email.bounced']);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('expands "all" shorthand in --events to 17 events', async () => {
|
|
87
|
+
spies = setupOutputSpies();
|
|
88
|
+
|
|
89
|
+
const { updateWebhookCommand } = await import(
|
|
90
|
+
'../../../src/commands/webhooks/update'
|
|
91
|
+
);
|
|
92
|
+
await updateWebhookCommand.parseAsync(['wh_abc123', '--events', 'all'], {
|
|
93
|
+
from: 'user',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const payload = mockUpdate.mock.calls[0][1] as Record<string, unknown>;
|
|
97
|
+
expect(payload.events).toHaveLength(17);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('updates status with --status flag', async () => {
|
|
101
|
+
spies = setupOutputSpies();
|
|
102
|
+
|
|
103
|
+
const { updateWebhookCommand } = await import(
|
|
104
|
+
'../../../src/commands/webhooks/update'
|
|
105
|
+
);
|
|
106
|
+
await updateWebhookCommand.parseAsync(
|
|
107
|
+
['wh_abc123', '--status', 'disabled'],
|
|
108
|
+
{ from: 'user' },
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const payload = mockUpdate.mock.calls[0][1] as Record<string, unknown>;
|
|
112
|
+
expect(payload.status).toBe('disabled');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('outputs JSON result when non-interactive', async () => {
|
|
116
|
+
spies = setupOutputSpies();
|
|
117
|
+
|
|
118
|
+
const { updateWebhookCommand } = await import(
|
|
119
|
+
'../../../src/commands/webhooks/update'
|
|
120
|
+
);
|
|
121
|
+
await updateWebhookCommand.parseAsync(
|
|
122
|
+
['wh_abc123', '--status', 'enabled'],
|
|
123
|
+
{ from: 'user' },
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const output = spies.logSpy.mock.calls[0][0] as string;
|
|
127
|
+
const parsed = JSON.parse(output);
|
|
128
|
+
expect(parsed.object).toBe('webhook');
|
|
129
|
+
expect(parsed.id).toBe('wh_abc123');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('errors with no_changes when no flags are provided', async () => {
|
|
133
|
+
setNonInteractive();
|
|
134
|
+
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
135
|
+
exitSpy = mockExitThrow();
|
|
136
|
+
|
|
137
|
+
const { updateWebhookCommand } = await import(
|
|
138
|
+
'../../../src/commands/webhooks/update'
|
|
139
|
+
);
|
|
140
|
+
await expectExit1(() =>
|
|
141
|
+
updateWebhookCommand.parseAsync(['wh_abc123'], { from: 'user' }),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
|
|
145
|
+
expect(output).toContain('no_changes');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('does not call SDK when no_changes error is raised', async () => {
|
|
149
|
+
setNonInteractive();
|
|
150
|
+
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
151
|
+
exitSpy = mockExitThrow();
|
|
152
|
+
|
|
153
|
+
const { updateWebhookCommand } = await import(
|
|
154
|
+
'../../../src/commands/webhooks/update'
|
|
155
|
+
);
|
|
156
|
+
await expectExit1(() =>
|
|
157
|
+
updateWebhookCommand.parseAsync(['wh_abc123'], { from: 'user' }),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
expect(mockUpdate).not.toHaveBeenCalled();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('errors with auth_error when no API key', async () => {
|
|
164
|
+
setNonInteractive();
|
|
165
|
+
delete process.env.RESEND_API_KEY;
|
|
166
|
+
process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
|
|
167
|
+
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
168
|
+
exitSpy = mockExitThrow();
|
|
169
|
+
|
|
170
|
+
const { updateWebhookCommand } = await import(
|
|
171
|
+
'../../../src/commands/webhooks/update'
|
|
172
|
+
);
|
|
173
|
+
await expectExit1(() =>
|
|
174
|
+
updateWebhookCommand.parseAsync(['wh_abc123', '--status', 'enabled'], {
|
|
175
|
+
from: 'user',
|
|
176
|
+
}),
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
|
|
180
|
+
expect(output).toContain('auth_error');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('errors with update_error when SDK returns an error', async () => {
|
|
184
|
+
setNonInteractive();
|
|
185
|
+
mockUpdate.mockResolvedValueOnce(
|
|
186
|
+
mockSdkError('Webhook not found', 'not_found'),
|
|
187
|
+
);
|
|
188
|
+
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
189
|
+
stderrSpy = vi
|
|
190
|
+
.spyOn(process.stderr, 'write')
|
|
191
|
+
.mockImplementation(() => true);
|
|
192
|
+
exitSpy = mockExitThrow();
|
|
193
|
+
|
|
194
|
+
const { updateWebhookCommand } = await import(
|
|
195
|
+
'../../../src/commands/webhooks/update'
|
|
196
|
+
);
|
|
197
|
+
await expectExit1(() =>
|
|
198
|
+
updateWebhookCommand.parseAsync(
|
|
199
|
+
['wh_nonexistent', '--status', 'disabled'],
|
|
200
|
+
{ from: 'user' },
|
|
201
|
+
),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
|
|
205
|
+
expect(output).toContain('update_error');
|
|
206
|
+
});
|
|
207
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import {
|
|
5
|
+
afterEach,
|
|
6
|
+
beforeEach,
|
|
7
|
+
describe,
|
|
8
|
+
expect,
|
|
9
|
+
type MockInstance,
|
|
10
|
+
test,
|
|
11
|
+
} from 'vitest';
|
|
12
|
+
import {
|
|
13
|
+
captureTestEnv,
|
|
14
|
+
expectExit1,
|
|
15
|
+
mockExitThrow,
|
|
16
|
+
setupOutputSpies,
|
|
17
|
+
} from '../helpers';
|
|
18
|
+
|
|
19
|
+
describe('whoami command', () => {
|
|
20
|
+
const restoreEnv = captureTestEnv();
|
|
21
|
+
let spies: ReturnType<typeof setupOutputSpies> | undefined;
|
|
22
|
+
let errorSpy: MockInstance | undefined;
|
|
23
|
+
let exitSpy: MockInstance | undefined;
|
|
24
|
+
let tmpDir: string;
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
tmpDir = join(
|
|
28
|
+
tmpdir(),
|
|
29
|
+
`resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
30
|
+
);
|
|
31
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
32
|
+
process.env.XDG_CONFIG_HOME = tmpDir;
|
|
33
|
+
delete process.env.RESEND_API_KEY;
|
|
34
|
+
delete process.env.RESEND_TEAM;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
restoreEnv();
|
|
39
|
+
spies = undefined;
|
|
40
|
+
errorSpy?.mockRestore();
|
|
41
|
+
errorSpy = undefined;
|
|
42
|
+
exitSpy?.mockRestore();
|
|
43
|
+
exitSpy = undefined;
|
|
44
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('exits 1 when not authenticated (non-interactive)', async () => {
|
|
48
|
+
spies = setupOutputSpies();
|
|
49
|
+
exitSpy = mockExitThrow();
|
|
50
|
+
|
|
51
|
+
const { whoamiCommand } = await import('../../src/commands/whoami');
|
|
52
|
+
await expectExit1(() => whoamiCommand.parseAsync([], { from: 'user' }));
|
|
53
|
+
|
|
54
|
+
const output = spies.logSpy.mock.calls[0]?.[0] as string | undefined;
|
|
55
|
+
if (output) {
|
|
56
|
+
const parsed = JSON.parse(output);
|
|
57
|
+
expect(parsed.authenticated).toBe(false);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('shows authenticated JSON when key exists in config', async () => {
|
|
62
|
+
const configDir = join(tmpDir, 'resend');
|
|
63
|
+
mkdirSync(configDir, { recursive: true });
|
|
64
|
+
writeFileSync(
|
|
65
|
+
join(configDir, 'credentials.json'),
|
|
66
|
+
JSON.stringify({
|
|
67
|
+
active_team: 'production',
|
|
68
|
+
teams: { production: { api_key: 're_test_key_abcd' } },
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
spies = setupOutputSpies();
|
|
73
|
+
|
|
74
|
+
const { whoamiCommand } = await import('../../src/commands/whoami');
|
|
75
|
+
await whoamiCommand.parseAsync([], { from: 'user' });
|
|
76
|
+
|
|
77
|
+
const output = spies.logSpy.mock.calls[0][0] as string;
|
|
78
|
+
const parsed = JSON.parse(output);
|
|
79
|
+
expect(parsed.authenticated).toBe(true);
|
|
80
|
+
expect(parsed.team).toBe('production');
|
|
81
|
+
expect(parsed.api_key).toBe('re_...abcd');
|
|
82
|
+
expect(parsed.source).toBe('config');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('shows env source when RESEND_API_KEY is set', async () => {
|
|
86
|
+
process.env.RESEND_API_KEY = 're_env_key_5678';
|
|
87
|
+
|
|
88
|
+
spies = setupOutputSpies();
|
|
89
|
+
|
|
90
|
+
const { whoamiCommand } = await import('../../src/commands/whoami');
|
|
91
|
+
await whoamiCommand.parseAsync([], { from: 'user' });
|
|
92
|
+
|
|
93
|
+
const output = spies.logSpy.mock.calls[0][0] as string;
|
|
94
|
+
const parsed = JSON.parse(output);
|
|
95
|
+
expect(parsed.authenticated).toBe(true);
|
|
96
|
+
expect(parsed.source).toBe('env');
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E2E smoke tests — runs real CLI commands against the Resend API.
|
|
3
|
+
*
|
|
4
|
+
* These are NOT part of the normal test suite. Run them manually:
|
|
5
|
+
*
|
|
6
|
+
* npm run test:e2e
|
|
7
|
+
*
|
|
8
|
+
* Requirements:
|
|
9
|
+
* - A valid API key via RESEND_API_KEY env var or `resend login`
|
|
10
|
+
*
|
|
11
|
+
* These tests are read-only — they list resources and validate the CLI
|
|
12
|
+
* can talk to the API and format responses. Nothing is created or deleted.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { execFileSync } from 'node:child_process';
|
|
16
|
+
import { resolve } from 'node:path';
|
|
17
|
+
import { describe, expect, test } from 'vitest';
|
|
18
|
+
|
|
19
|
+
const CLI = resolve(import.meta.dirname, '../../src/cli.ts');
|
|
20
|
+
|
|
21
|
+
function run(...args: string[]): { stdout: string; exitCode: number } {
|
|
22
|
+
try {
|
|
23
|
+
const stdout = execFileSync('npx', ['tsx', CLI, ...args, '--json', '-q'], {
|
|
24
|
+
encoding: 'utf-8',
|
|
25
|
+
timeout: 30_000,
|
|
26
|
+
env: { ...process.env, NO_COLOR: '1' },
|
|
27
|
+
});
|
|
28
|
+
return { stdout: stdout.trim(), exitCode: 0 };
|
|
29
|
+
} catch (err) {
|
|
30
|
+
const e = err as { stdout?: string; status?: number };
|
|
31
|
+
return {
|
|
32
|
+
stdout: (e.stdout ?? '').trim(),
|
|
33
|
+
exitCode: e.status ?? 1,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function parseJson(stdout: string): unknown {
|
|
39
|
+
const parsed = JSON.parse(stdout);
|
|
40
|
+
expect(parsed).toBeDefined();
|
|
41
|
+
return parsed;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('e2e smoke', () => {
|
|
45
|
+
test('doctor reports check results', () => {
|
|
46
|
+
const { stdout } = run('doctor');
|
|
47
|
+
const data = parseJson(stdout) as { checks: unknown[] };
|
|
48
|
+
expect(data.checks).toBeInstanceOf(Array);
|
|
49
|
+
expect(data.checks.length).toBeGreaterThan(0);
|
|
50
|
+
// If API key is valid, ok should be true; either way the shape is correct
|
|
51
|
+
expect(data).toHaveProperty('ok');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('domains list returns valid json', () => {
|
|
55
|
+
const { stdout, exitCode } = run('domains', 'list');
|
|
56
|
+
expect(exitCode).toBe(0);
|
|
57
|
+
const data = parseJson(stdout) as { object: string; data: unknown[] };
|
|
58
|
+
expect(data.object).toBe('list');
|
|
59
|
+
expect(data.data).toBeInstanceOf(Array);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('api-keys list returns valid json', () => {
|
|
63
|
+
const { stdout, exitCode } = run('api-keys', 'list');
|
|
64
|
+
expect(exitCode).toBe(0);
|
|
65
|
+
const data = parseJson(stdout) as { object: string; data: unknown[] };
|
|
66
|
+
expect(data.object).toBe('list');
|
|
67
|
+
expect(data.data).toBeInstanceOf(Array);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('broadcasts list returns valid json', () => {
|
|
71
|
+
const { stdout, exitCode } = run('broadcasts', 'list');
|
|
72
|
+
expect(exitCode).toBe(0);
|
|
73
|
+
const data = parseJson(stdout) as { object: string; data: unknown[] };
|
|
74
|
+
expect(data.object).toBe('list');
|
|
75
|
+
expect(data.data).toBeInstanceOf(Array);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('webhooks list returns valid json', () => {
|
|
79
|
+
const { stdout, exitCode } = run('webhooks', 'list');
|
|
80
|
+
expect(exitCode).toBe(0);
|
|
81
|
+
const data = parseJson(stdout) as { object: string; data: unknown[] };
|
|
82
|
+
expect(data.object).toBe('list');
|
|
83
|
+
expect(data.data).toBeInstanceOf(Array);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('topics list returns valid json', () => {
|
|
87
|
+
const { stdout, exitCode } = run('topics', 'list');
|
|
88
|
+
expect(exitCode).toBe(0);
|
|
89
|
+
const data = parseJson(stdout) as { object: string; data: unknown[] };
|
|
90
|
+
expect(data.object).toBe('list');
|
|
91
|
+
expect(data.data).toBeInstanceOf(Array);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { expect, type MockInstance, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
export class ExitError extends Error {
|
|
4
|
+
constructor(public code: number) {
|
|
5
|
+
super(`process.exit(${code})`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function setNonInteractive(): void {
|
|
10
|
+
Object.defineProperty(process.stdin, 'isTTY', {
|
|
11
|
+
value: undefined,
|
|
12
|
+
writable: true,
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(process.stdout, 'isTTY', {
|
|
15
|
+
value: undefined,
|
|
16
|
+
writable: true,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function mockExitThrow(): MockInstance {
|
|
21
|
+
return vi.spyOn(process, 'exit').mockImplementation((code?: number) => {
|
|
22
|
+
throw new ExitError(code ?? 0);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Captures current env and TTY state and returns a function that restores it.
|
|
28
|
+
* Call once at the top of a describe block (not inside beforeEach) so state
|
|
29
|
+
* is captured before any test runs.
|
|
30
|
+
*/
|
|
31
|
+
export function captureTestEnv(): () => void {
|
|
32
|
+
const originalEnv = { ...process.env };
|
|
33
|
+
const originalStdinIsTTY = process.stdin.isTTY;
|
|
34
|
+
const originalStdoutIsTTY = process.stdout.isTTY;
|
|
35
|
+
return () => {
|
|
36
|
+
process.env = { ...originalEnv };
|
|
37
|
+
Object.defineProperty(process.stdin, 'isTTY', {
|
|
38
|
+
value: originalStdinIsTTY,
|
|
39
|
+
writable: true,
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(process.stdout, 'isTTY', {
|
|
42
|
+
value: originalStdoutIsTTY,
|
|
43
|
+
writable: true,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Sets non-interactive mode and mocks console.log + process.stderr.write.
|
|
50
|
+
* Returns the spies and a restore() function. Use in happy-path tests.
|
|
51
|
+
*/
|
|
52
|
+
export function setupOutputSpies() {
|
|
53
|
+
setNonInteractive();
|
|
54
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
55
|
+
const stderrSpy = vi
|
|
56
|
+
.spyOn(process.stderr, 'write')
|
|
57
|
+
.mockImplementation(() => true);
|
|
58
|
+
return { logSpy, stderrSpy };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Asserts that fn throws ExitError with code 1.
|
|
63
|
+
* Eliminates the expect(true).toBe(false) anti-pattern in error-path tests.
|
|
64
|
+
*/
|
|
65
|
+
/**
|
|
66
|
+
* Returns a properly-typed SDK error response without needing `as any`.
|
|
67
|
+
*/
|
|
68
|
+
export function mockSdkError(message: string, name = 'error') {
|
|
69
|
+
return { data: null, error: { message, name }, headers: null };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function expectExit1(fn: () => Promise<unknown>): Promise<void> {
|
|
73
|
+
let threw = false;
|
|
74
|
+
try {
|
|
75
|
+
await fn();
|
|
76
|
+
} catch (err) {
|
|
77
|
+
threw = true;
|
|
78
|
+
expect(err).toBeInstanceOf(ExitError);
|
|
79
|
+
expect((err as ExitError).code).toBe(1);
|
|
80
|
+
}
|
|
81
|
+
if (!threw) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
'Expected command to exit with code 1 but it completed successfully',
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|