-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcmd-audit-log.test.ts
96 lines (80 loc) · 3.52 KB
/
cmd-audit-log.test.ts
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
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 audit-log', async () => {
// Lazily access constants.rootBinPath.
const entryPath = path.join(constants.rootBinPath, `${CLI}.js`)
cmdit(
['audit-log', '--help', '--config', '{}'],
'should support --help',
async cmd => {
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
expect(stdout).toMatchInlineSnapshot(
`
"Look up the audit log for an organization
Usage
$ socket audit-log <org slug>
This feature requires an Enterprise Plan. To learn more about getting access
to this feature and many more, please visit https://socket.dev/pricing
Options
--dryRun Do input validation for a command and exit 0 when input is ok
--help Print this help.
--json Output result as json
--markdown Output result as markdown
--page Page number - default is 1
--perPage Results per page - default is 30
--type Type of log event
Examples
$ socket audit-log FakeOrg"
`
)
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
"
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
|_____|___|___|_,_|___|_|.dev | Command: \`socket audit-log\`, cwd: <redacted>"
`)
expect(code, 'help should exit with code 2').toBe(2)
expect(stderr, 'banner includes base command').toContain(
'`socket audit-log`'
)
}
)
cmdit(
['audit-log', '--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 audit-log\`, 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:
- Org name should be the first arg (\\x1b[31mmissing\\x1b[39m)"
`)
expect(code, 'dry-run should exit with code 2 if missing input').toBe(2)
}
)
cmdit(
['audit-log', 'fakeorg', '--dry-run', '--config', '{}'],
'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 audit-log\`, cwd: <redacted>"
`)
expect(code, 'dry-run should exit with code 0 if input ok').toBe(0)
}
)
})