Skip to content

Commit 0fb0f34

Browse files
committed
test(ci): fix git and scan test mock paths and debug imports (3 tests)
Fixed two test files with incorrect mock paths and debug function usage: - utils/git/git.test.mts (1 test): Split combined constants mock into separate mocks for env.mts, cli.mts, and socket.mts; updated ENV references from constants.default.ENV to ENV.default - commands/scan/fetch-scan.test.mts (2 tests): Added missing @socketsecurity/lib/debug mock with correct exports (debug, debugDir, isDebug); fixed test expectations to match actual implementation signatures Total fixes: 121 tests (previous 118 + 3 new)
1 parent 14524b1 commit 0fb0f34

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

packages/cli/src/commands/scan/fetch-scan.test.mts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ vi.mock('../../utils/socket/api.mjs', () => ({
66
queryApiSafeText: vi.fn(),
77
}))
88

9+
vi.mock('@socketsecurity/lib/debug', () => ({
10+
debug: vi.fn(),
11+
debugDir: vi.fn(),
12+
isDebug: vi.fn(() => false),
13+
}))
14+
915
describe('fetchScan', () => {
1016
it('fetches scan successfully', async () => {
1117
const { fetchScan } = await import('./fetch-scan.mts')
@@ -58,9 +64,9 @@ describe('fetchScan', () => {
5864
it('handles invalid JSON in scan data', async () => {
5965
const { fetchScan } = await import('./fetch-scan.mts')
6066
const { queryApiSafeText } = await import('../../utils/socket/api.mjs')
61-
const { debugDir, debugFn } = await import('@socketsecurity/lib/debug')
67+
const { debug, debugDir } = await import('@socketsecurity/lib/debug')
6268
const mockQueryApiText = vi.mocked(queryApiSafeText)
63-
const mockDebugFn = vi.mocked(debugFn)
69+
const mockDebug = vi.mocked(debug)
6470
const mockDebugDir = vi.mocked(debugDir)
6571

6672
const invalidJson = [
@@ -76,11 +82,10 @@ describe('fetchScan', () => {
7682

7783
const result = await fetchScan('test-org', 'scan-123')
7884

79-
expect(mockDebugFn).toHaveBeenCalledWith(
80-
'error',
85+
expect(mockDebug).toHaveBeenCalledWith(
8186
'Failed to parse scan result line as JSON',
8287
)
83-
expect(mockDebugDir).toHaveBeenCalledWith('error', {
88+
expect(mockDebugDir).toHaveBeenCalledWith({
8489
error: expect.any(SyntaxError),
8590
line: '{"invalid":json}',
8691
})

packages/cli/src/utils/git/git.test.mts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,25 @@ vi.mock('@socketsecurity/lib/spawn', () => ({
2121
}))
2222

2323
// Mock constants.
24-
vi.mock('../constants.mts', () => ({
24+
vi.mock('../../constants/env.mts', () => ({
2525
default: {
26-
ENV: {
27-
GITHUB_BASE_REF: undefined,
28-
GITHUB_REF_NAME: undefined,
29-
GITHUB_REF_TYPE: undefined,
30-
SOCKET_CLI_GIT_USER_EMAIL: undefined,
31-
SOCKET_CLI_GIT_USER_NAME: undefined,
32-
},
33-
SOCKET_DEFAULT_BRANCH: 'main',
34-
SOCKET_DEFAULT_REPOSITORY: 'default-repo',
26+
GITHUB_BASE_REF: undefined,
27+
GITHUB_REF_NAME: undefined,
28+
GITHUB_REF_TYPE: undefined,
29+
SOCKET_CLI_GIT_USER_EMAIL: undefined,
30+
SOCKET_CLI_GIT_USER_NAME: undefined,
3531
},
32+
}))
33+
34+
vi.mock('../../constants/cli.mts', () => ({
3635
FLAG_QUIET: '--quiet',
3736
}))
3837

38+
vi.mock('../../constants/socket.mts', () => ({
39+
SOCKET_DEFAULT_BRANCH: 'main',
40+
SOCKET_DEFAULT_REPOSITORY: 'default-repo',
41+
}))
42+
3943
// Mock debug.
4044
vi.mock('./debug.mts', () => ({
4145
debugGit: vi.fn(),
@@ -86,25 +90,25 @@ describe('git utilities', () => {
8690

8791
describe('getBaseBranch', () => {
8892
it('returns GITHUB_BASE_REF when in PR', async () => {
89-
const constants = await import('../constants.mts')
90-
constants.default.ENV.GITHUB_BASE_REF = 'main'
93+
const ENV = vi.mocked(await import('../../constants/env.mts')).default
94+
ENV.GITHUB_BASE_REF = 'main'
9195

9296
const result = await getBaseBranch()
9397
expect(result).toBe('main')
9498

95-
constants.default.ENV.GITHUB_BASE_REF = undefined
99+
ENV.GITHUB_BASE_REF = undefined
96100
})
97101

98102
it('returns GITHUB_REF_NAME when it is a branch', async () => {
99-
const constants = await import('../constants.mts')
100-
constants.default.ENV.GITHUB_REF_TYPE = 'branch'
101-
constants.default.ENV.GITHUB_REF_NAME = 'feature-branch'
103+
const ENV = vi.mocked(await import('../../constants/env.mts')).default
104+
ENV.GITHUB_REF_TYPE = 'branch'
105+
ENV.GITHUB_REF_NAME = 'feature-branch'
102106

103107
const result = await getBaseBranch()
104108
expect(result).toBe('feature-branch')
105109

106-
constants.default.ENV.GITHUB_REF_TYPE = undefined
107-
constants.default.ENV.GITHUB_REF_NAME = undefined
110+
ENV.GITHUB_REF_TYPE = undefined
111+
ENV.GITHUB_REF_NAME = undefined
108112
})
109113

110114
it('calls detectDefaultBranch when no GitHub env vars', async () => {

0 commit comments

Comments
 (0)