@meltstudio/meltctl 4.28.0 → 4.29.0

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 (38) hide show
  1. package/dist/commands/audit.d.ts +3 -0
  2. package/dist/commands/audit.js +48 -0
  3. package/dist/commands/audit.test.d.ts +1 -0
  4. package/dist/commands/audit.test.js +322 -0
  5. package/dist/commands/coins.test.d.ts +1 -0
  6. package/dist/commands/coins.test.js +133 -0
  7. package/dist/commands/feedback.test.d.ts +1 -0
  8. package/dist/commands/feedback.test.js +242 -0
  9. package/dist/commands/init.test.d.ts +1 -0
  10. package/dist/commands/init.test.js +476 -0
  11. package/dist/commands/login.test.d.ts +1 -0
  12. package/dist/commands/login.test.js +194 -0
  13. package/dist/commands/logout.test.d.ts +1 -0
  14. package/dist/commands/logout.test.js +59 -0
  15. package/dist/commands/plan.test.d.ts +1 -0
  16. package/dist/commands/plan.test.js +283 -0
  17. package/dist/commands/standup.test.d.ts +1 -0
  18. package/dist/commands/standup.test.js +252 -0
  19. package/dist/commands/templates.test.d.ts +1 -0
  20. package/dist/commands/templates.test.js +89 -0
  21. package/dist/commands/version.test.d.ts +1 -0
  22. package/dist/commands/version.test.js +86 -0
  23. package/dist/index.js +9 -1
  24. package/dist/utils/api.test.d.ts +1 -0
  25. package/dist/utils/api.test.js +96 -0
  26. package/dist/utils/auth.test.d.ts +1 -0
  27. package/dist/utils/auth.test.js +165 -0
  28. package/dist/utils/banner.test.d.ts +1 -0
  29. package/dist/utils/banner.test.js +34 -0
  30. package/dist/utils/git.test.d.ts +1 -0
  31. package/dist/utils/git.test.js +184 -0
  32. package/dist/utils/package-manager.test.d.ts +1 -0
  33. package/dist/utils/package-manager.test.js +76 -0
  34. package/dist/utils/templates.test.d.ts +1 -0
  35. package/dist/utils/templates.test.js +50 -0
  36. package/dist/utils/version-check.test.d.ts +1 -0
  37. package/dist/utils/version-check.test.js +135 -0
  38. package/package.json +2 -1
@@ -5,3 +5,6 @@ export declare function auditListCommand(options: {
5
5
  latest?: boolean;
6
6
  limit?: string;
7
7
  }): Promise<void>;
8
+ export declare function auditViewCommand(id: string, options: {
9
+ output?: string;
10
+ }): Promise<void>;
@@ -186,3 +186,51 @@ export async function auditListCommand(options) {
186
186
  process.exit(1);
187
187
  }
188
188
  }
189
+ export async function auditViewCommand(id, options) {
190
+ const token = await getToken();
191
+ try {
192
+ const res = await tokenFetch(token, `/audits/${id}`);
193
+ if (res.status === 403) {
194
+ console.error(chalk.red('Access denied. Only Team Managers can view audits.'));
195
+ process.exit(1);
196
+ }
197
+ if (res.status === 404) {
198
+ console.error(chalk.red(`Audit not found: ${id}`));
199
+ process.exit(1);
200
+ }
201
+ if (!res.ok) {
202
+ const body = (await res.json());
203
+ console.error(chalk.red(`Failed to fetch audit: ${body.error ?? res.statusText}`));
204
+ process.exit(1);
205
+ }
206
+ const audit = (await res.json());
207
+ if (options.output) {
208
+ const outputPath = path.resolve(options.output);
209
+ await fs.ensureDir(path.dirname(outputPath));
210
+ await fs.writeFile(outputPath, audit.content, 'utf-8');
211
+ console.log(chalk.green(`\n ✓ Audit saved to ${path.relative(process.cwd(), outputPath)}\n`));
212
+ }
213
+ else {
214
+ const typeLabels = {
215
+ audit: 'Tech Audit',
216
+ 'ux-audit': 'UX Audit',
217
+ 'security-audit': 'Security Audit',
218
+ };
219
+ const label = typeLabels[audit.type] ?? audit.type;
220
+ const date = new Date(audit.createdAt).toLocaleDateString('en-US', {
221
+ month: 'short',
222
+ day: 'numeric',
223
+ year: 'numeric',
224
+ });
225
+ const repo = audit.repository ?? audit.project;
226
+ console.log();
227
+ console.log(chalk.dim(` ${label} · ${repo} · ${audit.author} · ${date}`));
228
+ console.log();
229
+ console.log(audit.content);
230
+ }
231
+ }
232
+ catch (error) {
233
+ console.error(chalk.red(`Failed to fetch audit: ${error instanceof Error ? error.message : 'Unknown error'}`));
234
+ process.exit(1);
235
+ }
236
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,322 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ vi.mock('fs-extra', () => ({
3
+ default: {
4
+ pathExists: vi.fn(),
5
+ readFile: vi.fn(),
6
+ },
7
+ }));
8
+ vi.mock('../utils/api.js', () => ({
9
+ getToken: vi.fn(),
10
+ tokenFetch: vi.fn(),
11
+ }));
12
+ vi.mock('../utils/git.js', () => ({
13
+ getGitBranch: vi.fn(),
14
+ getGitCommit: vi.fn(),
15
+ getGitRepository: vi.fn(),
16
+ getProjectName: vi.fn(),
17
+ findMdFiles: vi.fn(),
18
+ }));
19
+ import fs from 'fs-extra';
20
+ import { getToken, tokenFetch } from '../utils/api.js';
21
+ import { getGitBranch, getGitCommit, getGitRepository, getProjectName, findMdFiles, } from '../utils/git.js';
22
+ import { auditSubmitCommand, auditListCommand } from './audit.js';
23
+ beforeEach(() => {
24
+ vi.clearAllMocks();
25
+ vi.spyOn(console, 'log').mockImplementation(() => { });
26
+ vi.spyOn(console, 'error').mockImplementation(() => { });
27
+ vi.spyOn(process, 'exit').mockImplementation((code) => {
28
+ throw new Error(`process.exit(${code})`);
29
+ });
30
+ });
31
+ describe('auditSubmitCommand', () => {
32
+ function setupGitMocks() {
33
+ ;
34
+ getToken.mockResolvedValue('test-token');
35
+ getGitBranch.mockReturnValue('main');
36
+ getGitCommit.mockReturnValue('abc1234');
37
+ getGitRepository.mockReturnValue({
38
+ slug: 'Org/Repo',
39
+ url: 'https://github.com/Org/Repo.git',
40
+ });
41
+ getProjectName.mockReturnValue('test-project');
42
+ }
43
+ it('submits audit with type "security-audit" when filename contains security-audit', async () => {
44
+ setupGitMocks();
45
+ fs.pathExists.mockResolvedValue(true);
46
+ fs.readFile.mockResolvedValue('# Security Audit\nFindings here.');
47
+ const mockResponse = {
48
+ ok: true,
49
+ json: vi.fn().mockResolvedValue({ id: 'audit-123' }),
50
+ };
51
+ tokenFetch.mockResolvedValue(mockResponse);
52
+ await auditSubmitCommand('2026-03-26-security-audit.md');
53
+ expect(tokenFetch).toHaveBeenCalledWith('test-token', '/audits', expect.objectContaining({
54
+ method: 'POST',
55
+ body: expect.stringContaining('"type":"security-audit"'),
56
+ }));
57
+ });
58
+ it('submits audit with type "ux-audit" when filename contains ux-audit', async () => {
59
+ setupGitMocks();
60
+ fs.pathExists.mockResolvedValue(true);
61
+ fs.readFile.mockResolvedValue('# UX Audit');
62
+ const mockResponse = {
63
+ ok: true,
64
+ json: vi.fn().mockResolvedValue({ id: 'audit-456' }),
65
+ };
66
+ tokenFetch.mockResolvedValue(mockResponse);
67
+ await auditSubmitCommand('UX-AUDIT.md');
68
+ expect(tokenFetch).toHaveBeenCalledWith('test-token', '/audits', expect.objectContaining({
69
+ method: 'POST',
70
+ body: expect.stringContaining('"type":"ux-audit"'),
71
+ }));
72
+ });
73
+ it('submits audit with type "audit" for generic audit filenames', async () => {
74
+ setupGitMocks();
75
+ fs.pathExists.mockResolvedValue(true);
76
+ fs.readFile.mockResolvedValue('# Audit');
77
+ const mockResponse = {
78
+ ok: true,
79
+ json: vi.fn().mockResolvedValue({ id: 'audit-789' }),
80
+ };
81
+ tokenFetch.mockResolvedValue(mockResponse);
82
+ await auditSubmitCommand('AUDIT.md');
83
+ expect(tokenFetch).toHaveBeenCalledWith('test-token', '/audits', expect.objectContaining({
84
+ method: 'POST',
85
+ body: expect.stringContaining('"type":"audit"'),
86
+ }));
87
+ });
88
+ it('submits audit with type "audit" for random filenames', async () => {
89
+ setupGitMocks();
90
+ fs.pathExists.mockResolvedValue(true);
91
+ fs.readFile.mockResolvedValue('# Random');
92
+ const mockResponse = {
93
+ ok: true,
94
+ json: vi.fn().mockResolvedValue({ id: 'audit-000' }),
95
+ };
96
+ tokenFetch.mockResolvedValue(mockResponse);
97
+ await auditSubmitCommand('random-file.md');
98
+ expect(tokenFetch).toHaveBeenCalledWith('test-token', '/audits', expect.objectContaining({
99
+ method: 'POST',
100
+ body: expect.stringContaining('"type":"audit"'),
101
+ }));
102
+ });
103
+ it('exits with error when file not found', async () => {
104
+ setupGitMocks();
105
+ fs.pathExists.mockResolvedValue(false);
106
+ await expect(auditSubmitCommand('nonexistent.md')).rejects.toThrow('process.exit(1)');
107
+ expect(console.error).toHaveBeenCalled();
108
+ });
109
+ it('sends correct payload fields', async () => {
110
+ setupGitMocks();
111
+ vi.mocked(fs.pathExists).mockResolvedValue(true);
112
+ vi.mocked(fs.readFile).mockResolvedValue('audit content here');
113
+ const mockResponse = {
114
+ ok: true,
115
+ json: vi.fn().mockResolvedValue({ id: 'audit-100' }),
116
+ };
117
+ tokenFetch.mockResolvedValue(mockResponse);
118
+ await auditSubmitCommand('AUDIT.md');
119
+ const call = tokenFetch.mock.calls[0];
120
+ const body = JSON.parse(call[2].body);
121
+ expect(body).toEqual({
122
+ type: 'audit',
123
+ project: 'test-project',
124
+ repository: 'Org/Repo',
125
+ repositoryUrl: 'https://github.com/Org/Repo.git',
126
+ branch: 'main',
127
+ commit: 'abc1234',
128
+ content: 'audit content here',
129
+ metadata: { filename: 'AUDIT.md' },
130
+ });
131
+ });
132
+ it('exits with error when API returns failure', async () => {
133
+ setupGitMocks();
134
+ fs.pathExists.mockResolvedValue(true);
135
+ fs.readFile.mockResolvedValue('content');
136
+ const mockResponse = {
137
+ ok: false,
138
+ statusText: 'Bad Request',
139
+ json: vi.fn().mockResolvedValue({ error: 'Invalid content' }),
140
+ };
141
+ tokenFetch.mockResolvedValue(mockResponse);
142
+ await expect(auditSubmitCommand('AUDIT.md')).rejects.toThrow('process.exit(1)');
143
+ });
144
+ it('auto-detects audit file from .audits/ directory when no file provided', async () => {
145
+ setupGitMocks();
146
+ findMdFiles.mockResolvedValue(['/project/.audits/2026-03-26-security-audit.md']);
147
+ fs.pathExists.mockResolvedValue(true);
148
+ fs.readFile.mockResolvedValue('auto-detected content');
149
+ const mockResponse = {
150
+ ok: true,
151
+ json: vi.fn().mockResolvedValue({ id: 'audit-auto' }),
152
+ };
153
+ tokenFetch.mockResolvedValue(mockResponse);
154
+ await auditSubmitCommand();
155
+ expect(tokenFetch).toHaveBeenCalledWith('test-token', '/audits', expect.objectContaining({
156
+ method: 'POST',
157
+ body: expect.stringContaining('"type":"security-audit"'),
158
+ }));
159
+ });
160
+ it('exits with error when no file provided and none auto-detected', async () => {
161
+ ;
162
+ getToken.mockResolvedValue('test-token');
163
+ findMdFiles.mockResolvedValue([]);
164
+ fs.pathExists.mockResolvedValue(false);
165
+ await expect(auditSubmitCommand()).rejects.toThrow('process.exit(1)');
166
+ expect(console.error).toHaveBeenCalled();
167
+ });
168
+ });
169
+ describe('auditListCommand', () => {
170
+ it('calls API with correct query params', async () => {
171
+ ;
172
+ getToken.mockResolvedValue('test-token');
173
+ const mockResponse = {
174
+ ok: true,
175
+ status: 200,
176
+ json: vi.fn().mockResolvedValue({ audits: [], count: 0 }),
177
+ };
178
+ tokenFetch.mockResolvedValue(mockResponse);
179
+ await auditListCommand({ type: 'ux-audit', repository: 'Org/Repo', limit: '5' });
180
+ expect(tokenFetch).toHaveBeenCalledWith('test-token', expect.stringContaining('/audits?'));
181
+ const url = tokenFetch.mock.calls[0][1];
182
+ expect(url).toContain('type=ux-audit');
183
+ expect(url).toContain('repository=Org%2FRepo');
184
+ expect(url).toContain('limit=5');
185
+ });
186
+ it('passes latest=true query param when option set', async () => {
187
+ ;
188
+ getToken.mockResolvedValue('test-token');
189
+ const mockResponse = {
190
+ ok: true,
191
+ status: 200,
192
+ json: vi.fn().mockResolvedValue({ audits: [], count: 0 }),
193
+ };
194
+ tokenFetch.mockResolvedValue(mockResponse);
195
+ await auditListCommand({ latest: true });
196
+ const url = tokenFetch.mock.calls[0][1];
197
+ expect(url).toContain('latest=true');
198
+ });
199
+ it('exits with error on 403 response', async () => {
200
+ ;
201
+ getToken.mockResolvedValue('test-token');
202
+ const mockResponse = {
203
+ ok: false,
204
+ status: 403,
205
+ statusText: 'Forbidden',
206
+ };
207
+ tokenFetch.mockResolvedValue(mockResponse);
208
+ await expect(auditListCommand({})).rejects.toThrow('process.exit(1)');
209
+ expect(console.error).toHaveBeenCalled();
210
+ });
211
+ it('displays audit list when audits exist', async () => {
212
+ ;
213
+ getToken.mockResolvedValue('test-token');
214
+ const mockResponse = {
215
+ ok: true,
216
+ status: 200,
217
+ json: vi.fn().mockResolvedValue({
218
+ audits: [
219
+ {
220
+ id: '1',
221
+ type: 'audit',
222
+ project: 'my-project',
223
+ repository: 'Org/Repo',
224
+ author: 'dev@meltstudio.co',
225
+ branch: 'main',
226
+ commit: 'abc1234',
227
+ createdAt: '2026-03-25T10:00:00Z',
228
+ },
229
+ ],
230
+ count: 1,
231
+ }),
232
+ };
233
+ tokenFetch.mockResolvedValue(mockResponse);
234
+ await auditListCommand({});
235
+ expect(console.log).toHaveBeenCalled();
236
+ });
237
+ it('displays age-colored output when latest option is set', async () => {
238
+ ;
239
+ getToken.mockResolvedValue('test-token');
240
+ const now = Date.now();
241
+ const threeDaysAgo = new Date(now - 3 * 24 * 60 * 60 * 1000).toISOString();
242
+ const fifteenDaysAgo = new Date(now - 15 * 24 * 60 * 60 * 1000).toISOString();
243
+ const sixtyDaysAgo = new Date(now - 60 * 24 * 60 * 60 * 1000).toISOString();
244
+ const mockResponse = {
245
+ ok: true,
246
+ status: 200,
247
+ json: vi.fn().mockResolvedValue({
248
+ audits: [
249
+ {
250
+ id: '1',
251
+ type: 'audit',
252
+ project: 'project-a',
253
+ repository: 'Org/RepoA',
254
+ author: 'dev1@meltstudio.co',
255
+ branch: 'main',
256
+ commit: 'aaa1111',
257
+ createdAt: threeDaysAgo,
258
+ created_at: threeDaysAgo,
259
+ },
260
+ {
261
+ id: '2',
262
+ type: 'ux-audit',
263
+ project: 'project-b',
264
+ repository: 'Org/RepoB',
265
+ author: 'dev2@meltstudio.co',
266
+ branch: 'main',
267
+ commit: 'bbb2222',
268
+ createdAt: fifteenDaysAgo,
269
+ created_at: fifteenDaysAgo,
270
+ },
271
+ {
272
+ id: '3',
273
+ type: 'security-audit',
274
+ project: 'project-c',
275
+ repository: 'Org/RepoC',
276
+ author: 'dev3@meltstudio.co',
277
+ branch: 'main',
278
+ commit: 'ccc3333',
279
+ createdAt: sixtyDaysAgo,
280
+ created_at: sixtyDaysAgo,
281
+ },
282
+ ],
283
+ count: 3,
284
+ }),
285
+ };
286
+ tokenFetch.mockResolvedValue(mockResponse);
287
+ await auditListCommand({ latest: true });
288
+ const logCalls = console.log.mock.calls.map((c) => String(c[0]));
289
+ // Should display "Latest Audits" header
290
+ expect(logCalls.some((msg) => msg.includes('Latest Audits'))).toBe(true);
291
+ // Should display AGE column header
292
+ expect(logCalls.some((msg) => msg.includes('AGE'))).toBe(true);
293
+ });
294
+ it('exits with error when auditListCommand tokenFetch throws', async () => {
295
+ ;
296
+ getToken.mockResolvedValue('test-token');
297
+ tokenFetch.mockRejectedValue(new Error('Network error'));
298
+ await expect(auditListCommand({})).rejects.toThrow('process.exit(1)');
299
+ const errorCalls = console.error.mock.calls.map((c) => String(c[0]));
300
+ expect(errorCalls.some((msg) => msg.includes('Network error'))).toBe(true);
301
+ });
302
+ it('exits with error when findMdFiles throws (e.g. .audits/ unreadable)', async () => {
303
+ ;
304
+ getToken.mockResolvedValue('test-token');
305
+ findMdFiles.mockRejectedValue(new Error('EACCES: permission denied'));
306
+ fs.pathExists.mockResolvedValue(false);
307
+ await expect(auditSubmitCommand()).rejects.toThrow();
308
+ });
309
+ it('shows "No audits found" when list is empty', async () => {
310
+ ;
311
+ getToken.mockResolvedValue('test-token');
312
+ const mockResponse = {
313
+ ok: true,
314
+ status: 200,
315
+ json: vi.fn().mockResolvedValue({ audits: [], count: 0 }),
316
+ };
317
+ tokenFetch.mockResolvedValue(mockResponse);
318
+ await auditListCommand({});
319
+ const errorCalls = console.log.mock.calls.map((c) => c[0]);
320
+ expect(errorCalls.some((msg) => typeof msg === 'string' && msg.includes('No audits found'))).toBe(true);
321
+ });
322
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,133 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ vi.mock('../utils/auth.js', () => ({
3
+ isAuthenticated: vi.fn(),
4
+ authenticatedFetch: vi.fn(),
5
+ }));
6
+ import { isAuthenticated, authenticatedFetch } from '../utils/auth.js';
7
+ import { coinsCommand } from './coins.js';
8
+ beforeEach(() => {
9
+ vi.clearAllMocks();
10
+ vi.spyOn(console, 'log').mockImplementation(() => { });
11
+ vi.spyOn(console, 'error').mockImplementation(() => { });
12
+ vi.spyOn(process, 'exit').mockImplementation((code) => {
13
+ throw new Error(`process.exit(${code})`);
14
+ });
15
+ });
16
+ describe('coinsCommand', () => {
17
+ describe('balance (default)', () => {
18
+ it('exits with error when not authenticated', async () => {
19
+ ;
20
+ isAuthenticated.mockResolvedValue(false);
21
+ await expect(coinsCommand({})).rejects.toThrow('process.exit(1)');
22
+ expect(console.error).toHaveBeenCalled();
23
+ });
24
+ it('displays coin balance on success', async () => {
25
+ ;
26
+ isAuthenticated.mockResolvedValue(true);
27
+ const mockResponse = {
28
+ ok: true,
29
+ json: vi.fn().mockResolvedValue({ coins: 5, period: '28d' }),
30
+ };
31
+ authenticatedFetch.mockResolvedValue(mockResponse);
32
+ await coinsCommand({});
33
+ expect(authenticatedFetch).toHaveBeenCalledWith('/coins');
34
+ const logCalls = console.log.mock.calls.map((c) => String(c[0]));
35
+ expect(logCalls.some((msg) => msg.includes('5'))).toBe(true);
36
+ });
37
+ it('displays singular coin text for 1 coin', async () => {
38
+ ;
39
+ isAuthenticated.mockResolvedValue(true);
40
+ authenticatedFetch.mockResolvedValue({
41
+ ok: true,
42
+ json: vi.fn().mockResolvedValue({ coins: 1, period: '28d' }),
43
+ });
44
+ await coinsCommand({});
45
+ const logCalls = console.log.mock.calls.map((c) => String(c[0]));
46
+ expect(logCalls.some((msg) => msg.includes('coin') && !msg.includes('coins'))).toBe(true);
47
+ });
48
+ it('displays plural coin text for multiple coins', async () => {
49
+ ;
50
+ isAuthenticated.mockResolvedValue(true);
51
+ authenticatedFetch.mockResolvedValue({
52
+ ok: true,
53
+ json: vi.fn().mockResolvedValue({ coins: 3, period: '28d' }),
54
+ });
55
+ await coinsCommand({});
56
+ const logCalls = console.log.mock.calls.map((c) => String(c[0]));
57
+ expect(logCalls.some((msg) => msg.includes('coins'))).toBe(true);
58
+ });
59
+ it('exits with error when API returns failure', async () => {
60
+ ;
61
+ isAuthenticated.mockResolvedValue(true);
62
+ const mockResponse = {
63
+ ok: false,
64
+ statusText: 'Internal Server Error',
65
+ json: vi.fn().mockResolvedValue({ error: 'Something went wrong' }),
66
+ };
67
+ authenticatedFetch.mockResolvedValue(mockResponse);
68
+ await expect(coinsCommand({})).rejects.toThrow('process.exit(1)');
69
+ const errorCalls = console.error.mock.calls.map((c) => String(c[0]));
70
+ expect(errorCalls.some((msg) => msg.includes('Something went wrong'))).toBe(true);
71
+ });
72
+ });
73
+ describe('leaderboard', () => {
74
+ it('exits with error when not authenticated', async () => {
75
+ ;
76
+ isAuthenticated.mockResolvedValue(false);
77
+ await expect(coinsCommand({ leaderboard: true })).rejects.toThrow('process.exit(1)');
78
+ });
79
+ it('displays leaderboard entries on success', async () => {
80
+ ;
81
+ isAuthenticated.mockResolvedValue(true);
82
+ const entries = [
83
+ { name: 'Alice', coins: 10 },
84
+ { name: 'Bob', coins: 7 },
85
+ { name: 'Charlie', coins: 3 },
86
+ ];
87
+ authenticatedFetch.mockResolvedValue({
88
+ ok: true,
89
+ json: vi.fn().mockResolvedValue(entries),
90
+ });
91
+ await coinsCommand({ leaderboard: true });
92
+ expect(authenticatedFetch).toHaveBeenCalledWith('/coins/leaderboard');
93
+ const logCalls = console.log.mock.calls.map((c) => String(c[0]));
94
+ expect(logCalls.some((msg) => msg.includes('Leaderboard'))).toBe(true);
95
+ expect(logCalls.some((msg) => msg.includes('Alice'))).toBe(true);
96
+ expect(logCalls.some((msg) => msg.includes('Bob'))).toBe(true);
97
+ });
98
+ it('shows message when no coins have been sent', async () => {
99
+ ;
100
+ isAuthenticated.mockResolvedValue(true);
101
+ authenticatedFetch.mockResolvedValue({
102
+ ok: true,
103
+ json: vi.fn().mockResolvedValue([]),
104
+ });
105
+ await coinsCommand({ leaderboard: true });
106
+ const logCalls = console.log.mock.calls.map((c) => String(c[0]));
107
+ expect(logCalls.some((msg) => msg.includes('No coins'))).toBe(true);
108
+ });
109
+ it('exits with error when leaderboard API fails', async () => {
110
+ ;
111
+ isAuthenticated.mockResolvedValue(true);
112
+ authenticatedFetch.mockResolvedValue({
113
+ ok: false,
114
+ statusText: 'Forbidden',
115
+ json: vi.fn().mockResolvedValue({ error: 'Access denied' }),
116
+ });
117
+ await expect(coinsCommand({ leaderboard: true })).rejects.toThrow('process.exit(1)');
118
+ const errorCalls = console.error.mock.calls.map((c) => String(c[0]));
119
+ expect(errorCalls.some((msg) => msg.includes('Access denied'))).toBe(true);
120
+ });
121
+ it('calls /coins/leaderboard endpoint not /coins', async () => {
122
+ ;
123
+ isAuthenticated.mockResolvedValue(true);
124
+ authenticatedFetch.mockResolvedValue({
125
+ ok: true,
126
+ json: vi.fn().mockResolvedValue([{ name: 'Test', coins: 1 }]),
127
+ });
128
+ await coinsCommand({ leaderboard: true });
129
+ expect(authenticatedFetch).toHaveBeenCalledWith('/coins/leaderboard');
130
+ expect(authenticatedFetch).not.toHaveBeenCalledWith('/coins');
131
+ });
132
+ });
133
+ });
@@ -0,0 +1 @@
1
+ export {};