@meltstudio/meltctl 4.30.0 → 4.31.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.
- package/dist/commands/audit.test.js +94 -1
- package/package.json +1 -1
|
@@ -3,6 +3,8 @@ vi.mock('fs-extra', () => ({
|
|
|
3
3
|
default: {
|
|
4
4
|
pathExists: vi.fn(),
|
|
5
5
|
readFile: vi.fn(),
|
|
6
|
+
ensureDir: vi.fn(),
|
|
7
|
+
writeFile: vi.fn(),
|
|
6
8
|
},
|
|
7
9
|
}));
|
|
8
10
|
vi.mock('../utils/api.js', () => ({
|
|
@@ -19,7 +21,7 @@ vi.mock('../utils/git.js', () => ({
|
|
|
19
21
|
import fs from 'fs-extra';
|
|
20
22
|
import { getToken, tokenFetch } from '../utils/api.js';
|
|
21
23
|
import { getGitBranch, getGitCommit, getGitRepository, getProjectName, findMdFiles, } from '../utils/git.js';
|
|
22
|
-
import { auditSubmitCommand, auditListCommand } from './audit.js';
|
|
24
|
+
import { auditSubmitCommand, auditListCommand, auditViewCommand } from './audit.js';
|
|
23
25
|
beforeEach(() => {
|
|
24
26
|
vi.clearAllMocks();
|
|
25
27
|
vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
@@ -320,3 +322,94 @@ describe('auditListCommand', () => {
|
|
|
320
322
|
expect(errorCalls.some((msg) => typeof msg === 'string' && msg.includes('No audits found'))).toBe(true);
|
|
321
323
|
});
|
|
322
324
|
});
|
|
325
|
+
describe('auditViewCommand', () => {
|
|
326
|
+
const sampleAudit = {
|
|
327
|
+
id: 'audit-abc123',
|
|
328
|
+
type: 'ux-audit',
|
|
329
|
+
project: 'my-project',
|
|
330
|
+
repository: 'Org/Repo',
|
|
331
|
+
author: 'dev@meltstudio.co',
|
|
332
|
+
branch: 'main',
|
|
333
|
+
commit: 'abc1234',
|
|
334
|
+
content: '# UX Audit\n\nFindings here.',
|
|
335
|
+
createdAt: '2026-03-25T10:00:00Z',
|
|
336
|
+
};
|
|
337
|
+
it('exits with "Access denied" on 403 response', async () => {
|
|
338
|
+
;
|
|
339
|
+
getToken.mockResolvedValue('test-token');
|
|
340
|
+
tokenFetch.mockResolvedValue({
|
|
341
|
+
ok: false,
|
|
342
|
+
status: 403,
|
|
343
|
+
statusText: 'Forbidden',
|
|
344
|
+
});
|
|
345
|
+
await expect(auditViewCommand('audit-abc123', {})).rejects.toThrow('process.exit(1)');
|
|
346
|
+
const errorCalls = console.error.mock.calls.map((c) => String(c[0]));
|
|
347
|
+
expect(errorCalls.some((msg) => msg.includes('Access denied'))).toBe(true);
|
|
348
|
+
});
|
|
349
|
+
it('exits with "Audit not found" on 404 response', async () => {
|
|
350
|
+
;
|
|
351
|
+
getToken.mockResolvedValue('test-token');
|
|
352
|
+
tokenFetch.mockResolvedValue({
|
|
353
|
+
ok: false,
|
|
354
|
+
status: 404,
|
|
355
|
+
statusText: 'Not Found',
|
|
356
|
+
});
|
|
357
|
+
await expect(auditViewCommand('nonexistent-id', {})).rejects.toThrow('process.exit(1)');
|
|
358
|
+
const errorCalls = console.error.mock.calls.map((c) => String(c[0]));
|
|
359
|
+
expect(errorCalls.some((msg) => msg.includes('Audit not found'))).toBe(true);
|
|
360
|
+
});
|
|
361
|
+
it('exits with error from body on non-ok response', async () => {
|
|
362
|
+
;
|
|
363
|
+
getToken.mockResolvedValue('test-token');
|
|
364
|
+
tokenFetch.mockResolvedValue({
|
|
365
|
+
ok: false,
|
|
366
|
+
status: 500,
|
|
367
|
+
statusText: 'Internal Server Error',
|
|
368
|
+
json: vi.fn().mockResolvedValue({ error: 'Database unavailable' }),
|
|
369
|
+
});
|
|
370
|
+
await expect(auditViewCommand('audit-abc123', {})).rejects.toThrow('process.exit(1)');
|
|
371
|
+
const errorCalls = console.error.mock.calls.map((c) => String(c[0]));
|
|
372
|
+
expect(errorCalls.some((msg) => msg.includes('Database unavailable'))).toBe(true);
|
|
373
|
+
});
|
|
374
|
+
it('prints audit content with header when no --output flag', async () => {
|
|
375
|
+
;
|
|
376
|
+
getToken.mockResolvedValue('test-token');
|
|
377
|
+
tokenFetch.mockResolvedValue({
|
|
378
|
+
ok: true,
|
|
379
|
+
status: 200,
|
|
380
|
+
json: vi.fn().mockResolvedValue(sampleAudit),
|
|
381
|
+
});
|
|
382
|
+
await auditViewCommand('audit-abc123', {});
|
|
383
|
+
const logCalls = console.log.mock.calls.map((c) => String(c[0]));
|
|
384
|
+
// Header should contain type label, repo, author, and date
|
|
385
|
+
expect(logCalls.some((msg) => msg.includes('UX Audit'))).toBe(true);
|
|
386
|
+
expect(logCalls.some((msg) => msg.includes('Org/Repo'))).toBe(true);
|
|
387
|
+
expect(logCalls.some((msg) => msg.includes('dev@meltstudio.co'))).toBe(true);
|
|
388
|
+
// Content should be printed
|
|
389
|
+
expect(logCalls.some((msg) => msg.includes('# UX Audit'))).toBe(true);
|
|
390
|
+
});
|
|
391
|
+
it('writes content to file with --output flag', async () => {
|
|
392
|
+
;
|
|
393
|
+
getToken.mockResolvedValue('test-token');
|
|
394
|
+
tokenFetch.mockResolvedValue({
|
|
395
|
+
ok: true,
|
|
396
|
+
status: 200,
|
|
397
|
+
json: vi.fn().mockResolvedValue(sampleAudit),
|
|
398
|
+
});
|
|
399
|
+
fs.ensureDir.mockResolvedValue(undefined);
|
|
400
|
+
fs.writeFile.mockResolvedValue(undefined);
|
|
401
|
+
await auditViewCommand('audit-abc123', { output: 'output/audit.md' });
|
|
402
|
+
expect(fs.ensureDir).toHaveBeenCalled();
|
|
403
|
+
expect(fs.writeFile).toHaveBeenCalledWith(expect.stringContaining('audit.md'), '# UX Audit\n\nFindings here.', 'utf-8');
|
|
404
|
+
const logCalls = console.log.mock.calls.map((c) => String(c[0]));
|
|
405
|
+
expect(logCalls.some((msg) => msg.includes('Audit saved to'))).toBe(true);
|
|
406
|
+
});
|
|
407
|
+
it('exits with error message on network error', async () => {
|
|
408
|
+
;
|
|
409
|
+
getToken.mockResolvedValue('test-token');
|
|
410
|
+
tokenFetch.mockRejectedValue(new Error('Network error'));
|
|
411
|
+
await expect(auditViewCommand('audit-abc123', {})).rejects.toThrow('process.exit(1)');
|
|
412
|
+
const errorCalls = console.error.mock.calls.map((c) => String(c[0]));
|
|
413
|
+
expect(errorCalls.some((msg) => msg.includes('Network error'))).toBe(true);
|
|
414
|
+
});
|
|
415
|
+
});
|
package/package.json
CHANGED