Skip to content

Commit 9feeacb

Browse files
test: address review — dry-run whoami uses offline client; fix whitespace env key expectation
1 parent 0a1ef36 commit 9feeacb

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/commands/auth.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,6 @@ describe('runWhoami', () => {
858858
...deps,
859859
env: { TESTSPRITE_API_URL: ' ' },
860860
credentialsPath,
861-
fetchImpl: makeFetch(meResponse()),
862861
},
863862
);
864863
const out = capture.stdout.join('\n');

src/lib/client-factory.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ describe('makeHttpClient - API key validation', () => {
339339
['smart dash', 'sk-user-abc\u2013def'],
340340
['smart quote', 'sk-user-\u201cabc\u201d'],
341341
['emoji', 'sk-user-abc\u{1f600}'],
342-
['whitespace-only', ' '],
343342
])('rejects a malformed configured API key with %s before fetch/retry', (_label, apiKey) => {
344343
const fetchImpl = vi.fn();
345344
let caught: unknown;
@@ -362,6 +361,26 @@ describe('makeHttpClient - API key validation', () => {
362361
expect(apiErr.exitCode).toBe(5);
363362
expect(apiErr.nextAction).toContain('api-key');
364363
});
364+
365+
it('treats a whitespace-only TESTSPRITE_API_KEY env var as unset (AUTH_REQUIRED)', () => {
366+
const fetchImpl = vi.fn();
367+
let caught: unknown;
368+
try {
369+
makeHttpClient(
370+
{ profile: 'default', output: 'json', debug: false, dryRun: false },
371+
{
372+
env: { TESTSPRITE_API_KEY: ' ' } as NodeJS.ProcessEnv,
373+
credentialsPath: NO_CREDS_PATH,
374+
fetchImpl,
375+
},
376+
);
377+
} catch (err) {
378+
caught = err;
379+
}
380+
expect(fetchImpl).not.toHaveBeenCalled();
381+
expect(caught).toBeInstanceOf(ApiError);
382+
expect((caught as ApiError).code).toBe('AUTH_REQUIRED');
383+
});
365384
});
366385

367386
describe('assertValidApiKeyHeaderValue', () => {

0 commit comments

Comments
 (0)