Skip to content

Commit 25638a8

Browse files
committed
test(cli): add comprehensive --tmp flag tests for scan create
Add tests for the --tmp flag covering short flag (-t), interaction with --set-as-alerts-page, explicit --no-tmp, and default behavior.
1 parent 178c2c2 commit 25638a8

File tree

1 file changed

+90
-13
lines changed

1 file changed

+90
-13
lines changed

packages/cli/test/unit/commands/scan/cmd-scan-create.test.mts

Lines changed: 90 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -465,21 +465,98 @@ describe('cmd-scan-create', () => {
465465
expect(mockHandleCreateNewScan).not.toHaveBeenCalled()
466466
})
467467

468-
it('should pass --tmp flag to handleCreateNewScan', async () => {
469-
mockHasDefaultApiToken.mockReturnValueOnce(true)
468+
describe('--tmp flag', () => {
469+
it('should pass --tmp flag to handleCreateNewScan', async () => {
470+
mockHasDefaultApiToken.mockReturnValueOnce(true)
470471

471-
await cmdScanCreate.run(
472-
['--org', 'test-org', '--tmp', '.', '--no-interactive'],
473-
importMeta,
474-
context,
475-
)
472+
await cmdScanCreate.run(
473+
['--org', 'test-org', '--tmp', '.', '--no-interactive'],
474+
importMeta,
475+
context,
476+
)
476477

477-
expect(mockHandleCreateNewScan).toHaveBeenCalledWith(
478-
expect.objectContaining({
479-
tmp: true,
480-
pendingHead: false,
481-
}),
482-
)
478+
expect(mockHandleCreateNewScan).toHaveBeenCalledWith(
479+
expect.objectContaining({
480+
tmp: true,
481+
pendingHead: false,
482+
}),
483+
)
484+
})
485+
486+
it('should support -t short flag', async () => {
487+
mockHasDefaultApiToken.mockReturnValueOnce(true)
488+
489+
await cmdScanCreate.run(
490+
['--org', 'test-org', '-t', '.', '--no-interactive'],
491+
importMeta,
492+
context,
493+
)
494+
495+
expect(mockHandleCreateNewScan).toHaveBeenCalledWith(
496+
expect.objectContaining({
497+
tmp: true,
498+
pendingHead: false,
499+
}),
500+
)
501+
})
502+
503+
it('should force pendingHead=false even when --set-as-alerts-page is set', async () => {
504+
mockHasDefaultApiToken.mockReturnValueOnce(true)
505+
506+
await cmdScanCreate.run(
507+
[
508+
'--org',
509+
'test-org',
510+
'--tmp',
511+
'--set-as-alerts-page',
512+
'.',
513+
'--no-interactive',
514+
],
515+
importMeta,
516+
context,
517+
)
518+
519+
// --tmp overrides --set-as-alerts-page.
520+
expect(mockHandleCreateNewScan).toHaveBeenCalledWith(
521+
expect.objectContaining({
522+
tmp: true,
523+
pendingHead: false,
524+
}),
525+
)
526+
})
527+
528+
it('should support explicit --no-tmp', async () => {
529+
mockHasDefaultApiToken.mockReturnValueOnce(true)
530+
531+
await cmdScanCreate.run(
532+
['--org', 'test-org', '--no-tmp', '.', '--no-interactive'],
533+
importMeta,
534+
context,
535+
)
536+
537+
expect(mockHandleCreateNewScan).toHaveBeenCalledWith(
538+
expect.objectContaining({
539+
tmp: false,
540+
pendingHead: true,
541+
}),
542+
)
543+
})
544+
545+
it('should default tmp to false when not specified', async () => {
546+
mockHasDefaultApiToken.mockReturnValueOnce(true)
547+
548+
await cmdScanCreate.run(
549+
['--org', 'test-org', '.', '--no-interactive'],
550+
importMeta,
551+
context,
552+
)
553+
554+
expect(mockHandleCreateNewScan).toHaveBeenCalledWith(
555+
expect.objectContaining({
556+
tmp: false,
557+
}),
558+
)
559+
})
483560
})
484561

485562
it('should use socket.json defaults for branch', async () => {

0 commit comments

Comments
 (0)