Skip to content

Commit 736ed2a

Browse files
committed
chore(test/helpers): delete fixtures.mts + slim mocks.mts (-295 LOC)
fixtures.mts (entire file, 175 LOC): 10 unused exports (OUTPUT_KINDS, TEST_REPOS, TEST_ORGS, TEST_SCANS, TEST_SDK_OPTIONS, TEST_QUOTA, TEST_ANALYTICS, TEST_ERRORS, createTestErrorResult, createTestSuccessResult — never adopted by any test). mocks.mts (-120 LOC): drop 7 dead functions (createLoggerMocks, createOutputMocks, createSdkMocks, setupApiCallFailure, setupOutputModuleMocks, setupSdkModuleMocks, setupSuccessfulSdkChain) + colocate ErrorOptions type (internal use). helpers/index.mts: drops the fixtures.mts barrel re-export.
1 parent 5900658 commit 736ed2a

3 files changed

Lines changed: 1 addition & 297 deletions

File tree

packages/cli/test/helpers/fixtures.mts

Lines changed: 0 additions & 175 deletions
This file was deleted.

packages/cli/test/helpers/index.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
export * from './cli-execution.mts'
77
export * from './constants.mts'
88
export * from './environment.mts'
9-
export * from './fixtures.mts'
109
export * from './generate-report-test-helpers.mts'
1110
export * from './handle-test-helpers.mts'
1211
export * from './mock-setup.mts'

packages/cli/test/helpers/mocks.mts

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { SocketSdk } from '@socketsecurity/sdk-stable'
1111
/**
1212
* Error options for creating error results.
1313
*/
14-
export type ErrorOptions = {
14+
type ErrorOptions = {
1515
code?: number | undefined
1616
cause?: string | undefined
1717
}
@@ -35,17 +35,6 @@ export function createErrorResult(
3535
/**
3636
* Creates mock logger functions.
3737
*/
38-
export function createLoggerMocks() {
39-
return {
40-
log: vi.fn(),
41-
info: vi.fn(),
42-
warn: vi.fn(),
43-
error: vi.fn(),
44-
fail: vi.fn(),
45-
success: vi.fn(),
46-
}
47-
}
48-
4938
/**
5039
* Creates a mock Socket SDK with common methods.
5140
*/
@@ -71,27 +60,6 @@ export function createMockSdk(overrides: Partial<SocketSdk> = {}): SocketSdk {
7160
} as unknown as SocketSdk
7261
}
7362

74-
/**
75-
* Creates mock output utility functions.
76-
*/
77-
export function createOutputMocks() {
78-
return {
79-
failMsgWithBadge: vi.fn((msg, cause) => `${msg}: ${cause}`),
80-
serializeResultJson: vi.fn(result => JSON.stringify(result)),
81-
}
82-
}
83-
84-
/**
85-
* Creates mock functions for SDK and API utilities.
86-
*/
87-
export function createSdkMocks() {
88-
return {
89-
handleApiCall: vi.fn(),
90-
setupSdk: vi.fn(),
91-
withSdk: vi.fn(),
92-
}
93-
}
94-
9563
/**
9664
* Creates a successful CResult.
9765
*/
@@ -102,74 +70,6 @@ export function createSuccessResult<T>(data: T): CResult<T> {
10270
}
10371
}
10472

105-
/**
106-
* Setup API call failure mock.
107-
*/
108-
export async function setupApiCallFailure(
109-
sdkMethod: string,
110-
error: Error | string,
111-
code = 404,
112-
): Promise<void> {
113-
const { handleApiCall } = await import('../../src/util/socket/api.mts')
114-
const { setupSdk } = await import('../../src/util/socket/sdk.mts')
115-
116-
const errorObj = typeof error === 'string' ? new Error(error) : error
117-
const mockSdk = createMockSdk({
118-
[sdkMethod]: vi.fn().mockRejectedValue(errorObj),
119-
})
120-
121-
vi.mocked(setupSdk).mockResolvedValue(createSuccessResult(mockSdk))
122-
vi.mocked(handleApiCall).mockResolvedValue(
123-
createErrorResult(errorObj.message, { code }),
124-
)
125-
}
126-
127-
/**
128-
* Setup common module mocks for output operations.
129-
*/
130-
export function setupOutputModuleMocks() {
131-
vi.mock('@socketsecurity/lib-stable/logger', () => ({
132-
getDefaultLogger: vi.fn(() => ({
133-
fail: vi.fn(),
134-
log: vi.fn(),
135-
info: vi.fn(),
136-
warn: vi.fn(),
137-
error: vi.fn(),
138-
success: vi.fn(),
139-
})),
140-
logger: {
141-
fail: vi.fn(),
142-
log: vi.fn(),
143-
info: vi.fn(),
144-
warn: vi.fn(),
145-
error: vi.fn(),
146-
success: vi.fn(),
147-
},
148-
}))
149-
150-
vi.mock('../../src/util/error/fail-msg-with-badge.mts', () => ({
151-
failMsgWithBadge: vi.fn((msg, cause) => `${msg}: ${cause}`),
152-
}))
153-
154-
vi.mock('../../src/util/output/result-json.mts', () => ({
155-
serializeResultJson: vi.fn(result => JSON.stringify(result)),
156-
}))
157-
}
158-
159-
/**
160-
* Setup common module mocks for SDK operations.
161-
*/
162-
export function setupSdkModuleMocks() {
163-
vi.mock('../../src/util/socket/api.mts', () => ({
164-
handleApiCall: vi.fn(),
165-
}))
166-
167-
vi.mock('../../src/util/socket/sdk.mts', () => ({
168-
setupSdk: vi.fn(),
169-
withSdk: vi.fn(),
170-
}))
171-
}
172-
17373
/**
17474
* Setup SDK setup failure mock.
17575
*/
@@ -182,23 +82,3 @@ export async function setupSdkSetupFailure(
18282
vi.mocked(setupSdk).mockResolvedValue(createErrorResult(message, options))
18383
}
18484

185-
/**
186-
* Setup successful SDK mock chain.
187-
*/
188-
export async function setupSuccessfulSdkChain(
189-
sdkMethod: string,
190-
mockData: unknown,
191-
): Promise<void> {
192-
const { handleApiCall } = await import('../../src/util/socket/api.mts')
193-
const { setupSdk } = await import('../../src/util/socket/sdk.mts')
194-
195-
const mockSdk = createMockSdk({
196-
[sdkMethod]: vi.fn().mockResolvedValue({
197-
success: true,
198-
data: mockData,
199-
}),
200-
})
201-
202-
vi.mocked(setupSdk).mockResolvedValue(createSuccessResult(mockSdk))
203-
vi.mocked(handleApiCall).mockResolvedValue(createSuccessResult(mockData))
204-
}

0 commit comments

Comments
 (0)