Skip to content

Commit 823ea64

Browse files
committed
test(coverage): cover getTokenOrigin config-flag + persisted-config branches
Adds tests using existing mocks for getConfigValueOrUndef + isConfigFromFlag to exercise both branches of line 56 in with-subcommands-banner.mts: - token from config + isConfigFromFlag=true → "(--config flag)" - token from persisted config + isConfigFromFlag=false → "(config)" with-subcommands-banner.mts: 92.16% → 94.11% statements.
1 parent 743a83c commit 823ea64

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

packages/cli/test/unit/utils/cli/with-subcommands.test.mts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,49 @@ describe('meow-with-subcommands', () => {
472472
}
473473
}
474474
})
475+
476+
it('returns "(--config flag)" when token from config-from-flag (line 56)', () => {
477+
const originalNo = process.env['SOCKET_CLI_NO_API_TOKEN']
478+
const original = process.env['SOCKET_CLI_API_TOKEN']
479+
delete process.env['SOCKET_CLI_NO_API_TOKEN']
480+
delete process.env['SOCKET_CLI_API_TOKEN']
481+
try {
482+
// Mock config returns a token AND isConfigFromFlag returns true.
483+
mockGetConfigValueOrUndef.mockReturnValueOnce('sktsec_flag_xxxxxxxxxxxx')
484+
mockIsConfigFromFlag.mockReturnValueOnce(true)
485+
const result = getTokenOrigin()
486+
expect(result).toBe('(--config flag)')
487+
} finally {
488+
if (originalNo !== undefined) {
489+
process.env['SOCKET_CLI_NO_API_TOKEN'] = originalNo
490+
}
491+
if (original !== undefined) {
492+
process.env['SOCKET_CLI_API_TOKEN'] = original
493+
}
494+
}
495+
})
496+
497+
it('returns "(config)" when token from persisted config (line 56)', () => {
498+
const originalNo = process.env['SOCKET_CLI_NO_API_TOKEN']
499+
const original = process.env['SOCKET_CLI_API_TOKEN']
500+
delete process.env['SOCKET_CLI_NO_API_TOKEN']
501+
delete process.env['SOCKET_CLI_API_TOKEN']
502+
try {
503+
mockGetConfigValueOrUndef.mockReturnValueOnce(
504+
'sktsec_persisted_xxxxxxxxxxxx',
505+
)
506+
mockIsConfigFromFlag.mockReturnValueOnce(false)
507+
const result = getTokenOrigin()
508+
expect(result).toBe('(config)')
509+
} finally {
510+
if (originalNo !== undefined) {
511+
process.env['SOCKET_CLI_NO_API_TOKEN'] = originalNo
512+
}
513+
if (original !== undefined) {
514+
process.env['SOCKET_CLI_API_TOKEN'] = original
515+
}
516+
}
517+
})
475518
})
476519

477520
describe('getLastSeenCommand', () => {

0 commit comments

Comments
 (0)