Skip to content

Commit 495db2f

Browse files
authored
fix(test): validate list status before client setup (#152)
1 parent 06d2c4d commit 495db2f

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

src/commands/test.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,34 @@ describe('runList', () => {
475475
).rejects.toMatchObject({ code: 'VALIDATION_ERROR', details: { field: 'page-size' } });
476476
});
477477

478+
it('rejects invalid --status before requiring credentials', async () => {
479+
const credentialsPath = join(mkdtempSync(join(tmpdir(), 'cli-list-status-')), 'credentials');
480+
const fetchImpl = vi.fn();
481+
482+
await expect(
483+
runList(
484+
{
485+
profile: 'default',
486+
output: 'json',
487+
debug: false,
488+
projectId: 'project_alice',
489+
status: 'notastatus',
490+
},
491+
{
492+
credentialsPath,
493+
fetchImpl: fetchImpl as unknown as typeof fetch,
494+
stdout: () => undefined,
495+
},
496+
),
497+
).rejects.toMatchObject({
498+
code: 'VALIDATION_ERROR',
499+
exitCode: 5,
500+
details: { field: 'status' },
501+
});
502+
503+
expect(fetchImpl).not.toHaveBeenCalled();
504+
});
505+
478506
it('forwards a server-side VALIDATION_ERROR envelope as ApiError exit 5', async () => {
479507
const { credentialsPath } = makeCreds();
480508
const fetchImpl = makeFetch(() => ({

src/commands/test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ export async function runList(opts: ListOptions, deps: TestDeps = {}): Promise<P
452452
maxItems: opts.maxItems,
453453
});
454454

455+
// M2.1 piece 2: validate `--status` tokens client-side before
456+
// sending. Friendlier error than waiting for the server's 400 with
457+
// a list of accepted tokens — and lets the user fix typos without
458+
// a round trip.
459+
validateStatusFilter(opts.status);
460+
455461
const out = makeOutput(opts.output, deps);
456462
const client = makeClient(opts, deps);
457463

@@ -460,12 +466,6 @@ export async function runList(opts: ListOptions, deps: TestDeps = {}): Promise<P
460466
// huge project.
461467
const useSinglePage = opts.pageSize !== undefined && opts.maxItems === undefined;
462468

463-
// M2.1 piece 2: validate `--status` tokens client-side before
464-
// sending. Friendlier error than waiting for the server's 400 with
465-
// a list of accepted tokens — and lets the user fix typos without
466-
// a round trip.
467-
validateStatusFilter(opts.status);
468-
469469
const baseQuery: Record<string, string | number | boolean | undefined> = {
470470
projectId: opts.projectId,
471471
type: opts.type,

0 commit comments

Comments
 (0)