-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathcmd-diff-scan-get.test.ts
More file actions
113 lines (95 loc) · 4.36 KB
/
cmd-diff-scan-get.test.ts
File metadata and controls
113 lines (95 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import path from 'node:path'
import { describe, expect } from 'vitest'
import constants from '../../../dist/constants.js'
import { cmdit, invokeNpm } from '../../../test/utils'
const { CLI } = constants
describe('socket diff-scan get', async () => {
// Lazily access constants.rootBinPath.
const entryPath = path.join(constants.rootBinPath, `${CLI}.js`)
cmdit(
['diff-scan', 'get', '--help', '--config', '{}'],
'should support --help',
async cmd => {
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
expect(stdout).toMatchInlineSnapshot(
`
"Get a diff scan for an organization
Usage
$ socket diff-scan get <org slug> --before=<before> --after=<after>
This command displays the package changes between two scans. The full output
can be pretty large depending on the size of your repo and time range. It is
best stored to disk to be further analyzed by other tools.
Options
--after The scan ID of the head scan
--before The scan ID of the base scan
--depth Max depth of JSON to display before truncating, use zero for no limit (without --json/--file)
--dryRun Do input validation for a command and exit 0 when input is ok
--file Path to a local file where the output should be saved. Use \`-\` to force stdout.
--help Print this help.
--json Output result as json. This can be big. Use --file to store it to disk without truncation.
Examples
$ socket diff-scan get FakeCorp --before=aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 --after=aaa1aa1a-aaaa-1111-1a1a-1111111a11a1"
`
)
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
"
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
|_____|___|___|_,_|___|_|.dev | Command: \`socket diff-scan get\`, cwd: <redacted>"
`)
expect(code, 'help should exit with code 2').toBe(2)
expect(stderr, 'banner includes base command').toContain(
'`socket diff-scan get`'
)
}
)
cmdit(
['diff-scan', 'get', '--dry-run', '--config', '{}'],
'should require args with just dry-run',
async cmd => {
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
expect(stdout).toMatchInlineSnapshot(`""`)
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
"
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
|_____|___|___|_,_|___|_|.dev | Command: \`socket diff-scan get\`, cwd: <redacted>
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again\\x1b[22m
- Specify a before and after scan ID (\\x1b[31mmissing before and after\\x1b[39m)
The args are expecting a full \`aaa0aa0a-aaaa-0000-0a0a-0000000a00a0\` scan ID.
- Org name as the first argument (\\x1b[31mmissing\\x1b[39m)
- You need to be logged in to use this command. See \`socket login\`. (\\x1b[31mmissing API token\\x1b[39m)"
`)
expect(code, 'dry-run should exit with code 2 if missing input').toBe(2)
}
)
cmdit(
[
'diff-scan',
'get',
'fakeorg',
'--dry-run',
'--config',
'{"apiToken":"anything"}',
'--before',
'x',
'--after',
'y'
],
'should require args with just dry-run',
async cmd => {
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
"
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
|_____|___|___|_,_|___|_|.dev | Command: \`socket diff-scan get\`, cwd: <redacted>"
`)
expect(code, 'dry-run should exit with code 0 if input ok').toBe(0)
}
)
})