-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathcmd-analytics.test.ts
More file actions
113 lines (95 loc) · 4.1 KB
/
cmd-analytics.test.ts
File metadata and controls
113 lines (95 loc) · 4.1 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 analytics', async () => {
// Lazily access constants.rootBinPath.
const entryPath = path.join(constants.rootBinPath, `${CLI}.js`)
cmdit(
['analytics', '--help', '--config', '{}'],
'should support --help',
async cmd => {
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
expect(stdout).toMatchInlineSnapshot(
`
"Look up analytics data
Usage
$ socket analytics --scope=<scope> --time=<time filter>
Default parameters are set to show the organization-level analytics over the
last 7 days.
Options
--dryRun Do input validation for a command and exit 0 when input is ok
--file Path to a local file to save the output. Only valid with --json/--markdown. Defaults to stdout.
--help Print this help.
--json Output result as json
--markdown Output result as markdown
--repo Name of the repository. Only valid when scope=repo
--scope Scope of the analytics data - either 'org' or 'repo', default: org
--time Time filter - either 7, 30 or 90, default: 7
Examples
$ socket analytics --scope=org --time=7
$ socket analytics --scope=org --time=30
$ socket analytics --scope=repo --repo=test-repo --time=30"
`
)
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
"
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
|_____|___|___|_,_|___|_|.dev | Command: \`socket analytics\`, cwd: <redacted>"
`)
expect(code, 'help should exit with code 2').toBe(2)
expect(stderr, 'banner includes base command').toContain(
'`socket analytics`'
)
}
)
cmdit(
['analytics', '--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 analytics\`, 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:
- Scope must be "repo" or "org" (\\x1b[32mok\\x1b[39m)
- The time filter must either be 7, 30 or 90 (\\x1b[32mok\\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(
[
'analytics',
'boo',
'--scope',
'org',
'--repo',
'bar',
'--dry-run',
'--config',
'{"apiToken":"anything"}'
],
'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 analytics\`, cwd: <redacted>"
`)
expect(code, 'dry-run should exit with code 0 if input ok').toBe(0)
}
)
})