Skip to content

Commit 50254b9

Browse files
committed
test(cli): add more unit tests for constants modules
Add test coverage for additional CLI constants: - reporting.mts: Fold setting and report level constants - socket.mts: API URLs, config files, scan types, tokens - packages.mts: Package names, binary names, descriptions
1 parent 895be5b commit 50254b9

File tree

3 files changed

+383
-0
lines changed

3 files changed

+383
-0
lines changed
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
/**
2+
* Unit tests for package constants.
3+
*
4+
* Purpose:
5+
* Tests the package and binary name constants for Socket CLI.
6+
*
7+
* Test Coverage:
8+
* - Package manifest file constants
9+
* - Directory name constants
10+
* - File extension constants
11+
* - Package name constants
12+
* - Binary name constants
13+
*
14+
* Related Files:
15+
* - constants/packages.mts (implementation)
16+
*/
17+
18+
import { describe, expect, it } from 'vitest'
19+
20+
import {
21+
BLESSED,
22+
BLESSED_CONTRIB,
23+
EXT_LOCK,
24+
EXT_LOCKB,
25+
NODE_MODULES,
26+
NPM_BUGGY_OVERRIDES_PATCHED_VERSION,
27+
PACKAGE_JSON,
28+
PACKAGE_LOCK_JSON,
29+
PNPM_LOCK_YAML,
30+
PYTHON_MIN_VERSION,
31+
SENTRY_NODE,
32+
SOCKET_CLI_BIN_NAME,
33+
SOCKET_CLI_BIN_NAME_ALIAS,
34+
SOCKET_CLI_LEGACY_PACKAGE_NAME,
35+
SOCKET_CLI_NPM_BIN_NAME,
36+
SOCKET_CLI_NPX_BIN_NAME,
37+
SOCKET_CLI_PACKAGE_NAME,
38+
SOCKET_CLI_PNPM_BIN_NAME,
39+
SOCKET_CLI_SENTRY_BIN_NAME,
40+
SOCKET_CLI_SENTRY_BIN_NAME_ALIAS,
41+
SOCKET_CLI_SENTRY_NPM_BIN_NAME,
42+
SOCKET_CLI_SENTRY_NPX_BIN_NAME,
43+
SOCKET_CLI_SENTRY_PACKAGE_NAME,
44+
SOCKET_CLI_SENTRY_PNPM_BIN_NAME,
45+
SOCKET_CLI_SENTRY_YARN_BIN_NAME,
46+
SOCKET_CLI_YARN_BIN_NAME,
47+
SOCKET_DESCRIPTION,
48+
SOCKET_DESCRIPTION_WITH_SENTRY,
49+
SOCKET_SECURITY_REGISTRY,
50+
YARN_LOCK,
51+
} from '../../../src/constants/packages.mts'
52+
53+
describe('packages constants', () => {
54+
describe('package manifest file constants', () => {
55+
it('has PACKAGE_JSON constant', () => {
56+
expect(PACKAGE_JSON).toBe('package.json')
57+
})
58+
59+
it('has PACKAGE_LOCK_JSON constant', () => {
60+
expect(PACKAGE_LOCK_JSON).toBe('package-lock.json')
61+
})
62+
63+
it('has PNPM_LOCK_YAML constant', () => {
64+
expect(PNPM_LOCK_YAML).toBe('pnpm-lock.yaml')
65+
})
66+
67+
it('has YARN_LOCK constant', () => {
68+
expect(YARN_LOCK).toBe('yarn.lock')
69+
})
70+
})
71+
72+
describe('directory name constants', () => {
73+
it('has NODE_MODULES constant', () => {
74+
expect(NODE_MODULES).toBe('node_modules')
75+
})
76+
})
77+
78+
describe('file extension constants', () => {
79+
it('has EXT_LOCK constant', () => {
80+
expect(EXT_LOCK).toBe('.lock')
81+
})
82+
83+
it('has EXT_LOCKB constant', () => {
84+
expect(EXT_LOCKB).toBe('.lockb')
85+
})
86+
})
87+
88+
describe('npm version constants', () => {
89+
it('has NPM_BUGGY_OVERRIDES_PATCHED_VERSION constant', () => {
90+
expect(NPM_BUGGY_OVERRIDES_PATCHED_VERSION).toBe('11.2.0')
91+
})
92+
})
93+
94+
describe('external package name constants', () => {
95+
it('has BLESSED constant', () => {
96+
expect(BLESSED).toBe('blessed')
97+
})
98+
99+
it('has BLESSED_CONTRIB constant', () => {
100+
expect(BLESSED_CONTRIB).toBe('blessed-contrib')
101+
})
102+
103+
it('has SENTRY_NODE constant', () => {
104+
expect(SENTRY_NODE).toBe('@sentry/node')
105+
})
106+
107+
it('has SOCKET_SECURITY_REGISTRY constant', () => {
108+
expect(SOCKET_SECURITY_REGISTRY).toBe('@socketsecurity/registry')
109+
})
110+
})
111+
112+
describe('Socket CLI package name constants', () => {
113+
it('has SOCKET_CLI_PACKAGE_NAME constant', () => {
114+
expect(SOCKET_CLI_PACKAGE_NAME).toBe('socket')
115+
})
116+
117+
it('has SOCKET_CLI_LEGACY_PACKAGE_NAME constant', () => {
118+
expect(SOCKET_CLI_LEGACY_PACKAGE_NAME).toBe('socket-npm')
119+
})
120+
121+
it('has SOCKET_CLI_SENTRY_PACKAGE_NAME constant', () => {
122+
expect(SOCKET_CLI_SENTRY_PACKAGE_NAME).toBe(
123+
'@socketsecurity/cli-with-sentry',
124+
)
125+
})
126+
})
127+
128+
describe('Socket CLI binary name constants', () => {
129+
it('has SOCKET_CLI_BIN_NAME constant', () => {
130+
expect(SOCKET_CLI_BIN_NAME).toBe('socket')
131+
})
132+
133+
it('has SOCKET_CLI_BIN_NAME_ALIAS constant', () => {
134+
expect(SOCKET_CLI_BIN_NAME_ALIAS).toBe('socket-dev')
135+
})
136+
137+
it('has SOCKET_CLI_NPM_BIN_NAME constant', () => {
138+
expect(SOCKET_CLI_NPM_BIN_NAME).toBe('socket-npm')
139+
})
140+
141+
it('has SOCKET_CLI_NPX_BIN_NAME constant', () => {
142+
expect(SOCKET_CLI_NPX_BIN_NAME).toBe('socket-npx')
143+
})
144+
145+
it('has SOCKET_CLI_PNPM_BIN_NAME constant', () => {
146+
expect(SOCKET_CLI_PNPM_BIN_NAME).toBe('socket-pnpm')
147+
})
148+
149+
it('has SOCKET_CLI_YARN_BIN_NAME constant', () => {
150+
expect(SOCKET_CLI_YARN_BIN_NAME).toBe('socket-yarn')
151+
})
152+
})
153+
154+
describe('Socket CLI Sentry binary name constants', () => {
155+
it('has SOCKET_CLI_SENTRY_BIN_NAME constant', () => {
156+
expect(SOCKET_CLI_SENTRY_BIN_NAME).toBe('@socketsecurity/cli-with-sentry')
157+
})
158+
159+
it('has SOCKET_CLI_SENTRY_BIN_NAME_ALIAS constant', () => {
160+
expect(SOCKET_CLI_SENTRY_BIN_NAME_ALIAS).toBe('socket-dev-with-sentry')
161+
})
162+
163+
it('has SOCKET_CLI_SENTRY_NPM_BIN_NAME constant', () => {
164+
expect(SOCKET_CLI_SENTRY_NPM_BIN_NAME).toBe(
165+
'@socketsecurity/cli-with-sentry-npm',
166+
)
167+
})
168+
169+
it('has SOCKET_CLI_SENTRY_NPX_BIN_NAME constant', () => {
170+
expect(SOCKET_CLI_SENTRY_NPX_BIN_NAME).toBe(
171+
'@socketsecurity/cli-with-sentry-npx',
172+
)
173+
})
174+
175+
it('has SOCKET_CLI_SENTRY_PNPM_BIN_NAME constant', () => {
176+
expect(SOCKET_CLI_SENTRY_PNPM_BIN_NAME).toBe(
177+
'@socketsecurity/cli-with-sentry-pnpm',
178+
)
179+
})
180+
181+
it('has SOCKET_CLI_SENTRY_YARN_BIN_NAME constant', () => {
182+
expect(SOCKET_CLI_SENTRY_YARN_BIN_NAME).toBe(
183+
'@socketsecurity/cli-with-sentry-yarn',
184+
)
185+
})
186+
})
187+
188+
describe('description constants', () => {
189+
it('has SOCKET_DESCRIPTION constant', () => {
190+
expect(SOCKET_DESCRIPTION).toBe('CLI for Socket.dev')
191+
})
192+
193+
it('has SOCKET_DESCRIPTION_WITH_SENTRY constant', () => {
194+
expect(SOCKET_DESCRIPTION_WITH_SENTRY).toContain(SOCKET_DESCRIPTION)
195+
expect(SOCKET_DESCRIPTION_WITH_SENTRY).toContain('Sentry')
196+
})
197+
})
198+
199+
describe('Python version constants', () => {
200+
it('has PYTHON_MIN_VERSION constant', () => {
201+
expect(PYTHON_MIN_VERSION).toBe('3.9.0')
202+
})
203+
})
204+
})
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Unit tests for reporting constants.
3+
*
4+
* Purpose:
5+
* Tests the report level constants for security issue severity.
6+
*
7+
* Test Coverage:
8+
* - Fold setting constants
9+
* - Report level constants
10+
*
11+
* Related Files:
12+
* - constants/reporting.mts (implementation)
13+
*/
14+
15+
import { describe, expect, it } from 'vitest'
16+
17+
import {
18+
FOLD_SETTING_VERSION,
19+
REPORT_LEVEL_DEFER,
20+
REPORT_LEVEL_ERROR,
21+
REPORT_LEVEL_IGNORE,
22+
REPORT_LEVEL_MONITOR,
23+
REPORT_LEVEL_WARN,
24+
} from '../../../src/constants/reporting.mts'
25+
26+
describe('reporting constants', () => {
27+
describe('fold setting constants', () => {
28+
it('has FOLD_SETTING_VERSION constant', () => {
29+
expect(FOLD_SETTING_VERSION).toBe('version')
30+
})
31+
})
32+
33+
describe('report level constants', () => {
34+
it('has REPORT_LEVEL_DEFER constant', () => {
35+
expect(REPORT_LEVEL_DEFER).toBe('defer')
36+
})
37+
38+
it('has REPORT_LEVEL_ERROR constant', () => {
39+
expect(REPORT_LEVEL_ERROR).toBe('error')
40+
})
41+
42+
it('has REPORT_LEVEL_IGNORE constant', () => {
43+
expect(REPORT_LEVEL_IGNORE).toBe('ignore')
44+
})
45+
46+
it('has REPORT_LEVEL_MONITOR constant', () => {
47+
expect(REPORT_LEVEL_MONITOR).toBe('monitor')
48+
})
49+
50+
it('has REPORT_LEVEL_WARN constant', () => {
51+
expect(REPORT_LEVEL_WARN).toBe('warn')
52+
})
53+
})
54+
55+
describe('report level severity order', () => {
56+
it('all report levels are lowercase strings', () => {
57+
const levels = [
58+
REPORT_LEVEL_DEFER,
59+
REPORT_LEVEL_ERROR,
60+
REPORT_LEVEL_IGNORE,
61+
REPORT_LEVEL_MONITOR,
62+
REPORT_LEVEL_WARN,
63+
]
64+
for (const level of levels) {
65+
expect(level).toBe(level.toLowerCase())
66+
}
67+
})
68+
})
69+
})
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* Unit tests for Socket constants.
3+
*
4+
* Purpose:
5+
* Tests the Socket.dev specific constants for the CLI.
6+
*
7+
* Test Coverage:
8+
* - API URL constants
9+
* - Configuration file constants
10+
* - Repository metadata constants
11+
* - Scan type constants
12+
* - Token constants
13+
*
14+
* Related Files:
15+
* - constants/socket.mts (implementation)
16+
*/
17+
18+
import { describe, expect, it } from 'vitest'
19+
20+
import {
21+
API_V0_URL,
22+
NPM_REGISTRY_URL,
23+
SCAN_TYPE_SOCKET,
24+
SCAN_TYPE_SOCKET_TIER1,
25+
SOCKET_CLI_ISSUES_URL,
26+
SOCKET_DEFAULT_BRANCH,
27+
SOCKET_DEFAULT_REPOSITORY,
28+
SOCKET_JSON,
29+
SOCKET_WEBSITE_URL,
30+
SOCKET_YAML,
31+
SOCKET_YML,
32+
TOKEN_PREFIX,
33+
TOKEN_PREFIX_LENGTH,
34+
V1_MIGRATION_GUIDE_URL,
35+
} from '../../../src/constants/socket.mts'
36+
37+
describe('socket constants', () => {
38+
describe('API URL constants', () => {
39+
it('has API_V0_URL constant', () => {
40+
expect(API_V0_URL).toBe('https://api.socket.dev/v0/')
41+
})
42+
43+
it('has SOCKET_WEBSITE_URL constant', () => {
44+
expect(SOCKET_WEBSITE_URL).toBe('https://socket.dev')
45+
})
46+
47+
it('has NPM_REGISTRY_URL constant', () => {
48+
expect(NPM_REGISTRY_URL).toContain('registry')
49+
expect(NPM_REGISTRY_URL).toContain('npm')
50+
})
51+
})
52+
53+
describe('configuration file constants', () => {
54+
it('has SOCKET_JSON constant', () => {
55+
expect(SOCKET_JSON).toBe('socket.json')
56+
})
57+
58+
it('has SOCKET_YAML constant', () => {
59+
expect(SOCKET_YAML).toBe('socket.yaml')
60+
})
61+
62+
it('has SOCKET_YML constant', () => {
63+
expect(SOCKET_YML).toBe('socket.yml')
64+
})
65+
})
66+
67+
describe('repository metadata constants', () => {
68+
it('has SOCKET_DEFAULT_BRANCH constant', () => {
69+
expect(SOCKET_DEFAULT_BRANCH).toBe('socket-default-branch')
70+
})
71+
72+
it('has SOCKET_DEFAULT_REPOSITORY constant', () => {
73+
expect(SOCKET_DEFAULT_REPOSITORY).toBe('socket-default-repository')
74+
})
75+
})
76+
77+
describe('scan type constants', () => {
78+
it('has SCAN_TYPE_SOCKET constant', () => {
79+
expect(SCAN_TYPE_SOCKET).toBe('socket')
80+
})
81+
82+
it('has SCAN_TYPE_SOCKET_TIER1 constant', () => {
83+
expect(SCAN_TYPE_SOCKET_TIER1).toBe('socket_tier1')
84+
})
85+
})
86+
87+
describe('token constants', () => {
88+
it('has TOKEN_PREFIX constant', () => {
89+
expect(TOKEN_PREFIX).toBe('sktsec_')
90+
})
91+
92+
it('has TOKEN_PREFIX_LENGTH constant', () => {
93+
expect(TOKEN_PREFIX_LENGTH).toBe(TOKEN_PREFIX.length)
94+
expect(TOKEN_PREFIX_LENGTH).toBe(7)
95+
})
96+
})
97+
98+
describe('documentation constants', () => {
99+
it('has V1_MIGRATION_GUIDE_URL constant', () => {
100+
expect(V1_MIGRATION_GUIDE_URL).toContain('docs.socket.dev')
101+
expect(V1_MIGRATION_GUIDE_URL).toContain('migration')
102+
})
103+
104+
it('has SOCKET_CLI_ISSUES_URL constant', () => {
105+
expect(SOCKET_CLI_ISSUES_URL).toContain('github.com')
106+
expect(SOCKET_CLI_ISSUES_URL).toContain('socket-cli')
107+
expect(SOCKET_CLI_ISSUES_URL).toContain('issues')
108+
})
109+
})
110+
})

0 commit comments

Comments
 (0)