Skip to content

Commit e4dbb52

Browse files
committed
Lint nits
1 parent ae89a3b commit e4dbb52

File tree

3 files changed

+52
-22
lines changed

3 files changed

+52
-22
lines changed

src/commands/optimize/cmd-optimize.test.mts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,21 @@ const pnpmFixtureDir = path.join(fixtureBaseDir, PNPM)
3333
async function revertFixtureChanges() {
3434
// Reset only the package.json and pnpm-lock.yaml files that tests modify.
3535
try {
36+
// Git needs the paths relative to the repository root.
37+
const relativePackageJson = path.relative(
38+
process.cwd(),
39+
path.join(pnpmFixtureDir, PACKAGE_JSON),
40+
)
41+
const relativePnpmLock = path.relative(
42+
process.cwd(),
43+
path.join(pnpmFixtureDir, PNPM_LOCK_YAML),
44+
)
45+
3646
await spawn(
3747
'git',
38-
['checkout', 'HEAD', '--', PACKAGE_JSON, PNPM_LOCK_YAML],
48+
['checkout', 'HEAD', '--', relativePackageJson, relativePnpmLock],
3949
{
40-
cwd: pnpmFixtureDir,
50+
cwd: process.cwd(),
4151
stdio: 'ignore',
4252
},
4353
)

src/test/json-output-validation.mts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export type SocketJsonError = {
2121
code?: number
2222
}
2323

24-
export type SocketJsonResponse<T = unknown> = SocketJsonSuccess<T> | SocketJsonError
24+
export type SocketJsonResponse<T = unknown> =
25+
| SocketJsonSuccess<T>
26+
| SocketJsonError
2527

2628
/**
2729
* Validates that a string contains valid JSON matching Socket CLI response format.
@@ -31,7 +33,7 @@ export type SocketJsonResponse<T = unknown> = SocketJsonSuccess<T> | SocketJsonE
3133
*/
3234
export function validateSocketJson<T = unknown>(
3335
jsonString: string,
34-
expectedExitCode: number
36+
expectedExitCode: number,
3537
): SocketJsonResponse<T> {
3638
let parsed: any
3739

@@ -44,29 +46,41 @@ export function validateSocketJson<T = unknown>(
4446

4547
// Check for required ok field.
4648
if (typeof parsed.ok !== 'boolean') {
47-
throw new Error(`JSON output missing required 'ok' boolean field: ${jsonString}`)
49+
throw new Error(
50+
`JSON output missing required 'ok' boolean field: ${jsonString}`,
51+
)
4852
}
4953

5054
// Validate based on exit code expectation.
5155
if (expectedExitCode === 0) {
5256
if (parsed.ok !== true) {
53-
throw new Error(`JSON output 'ok' should be true when exit code is 0: ${jsonString}`)
57+
throw new Error(
58+
`JSON output 'ok' should be true when exit code is 0: ${jsonString}`,
59+
)
5460
}
5561
// Success response must have data field.
5662
if (parsed.data === undefined || parsed.data === null) {
57-
throw new Error(`JSON output missing required 'data' field when ok is true: ${jsonString}`)
63+
throw new Error(
64+
`JSON output missing required 'data' field when ok is true: ${jsonString}`,
65+
)
5866
}
5967
} else {
6068
if (parsed.ok !== false) {
61-
throw new Error(`JSON output 'ok' should be false when exit code is non-zero: ${jsonString}`)
69+
throw new Error(
70+
`JSON output 'ok' should be false when exit code is non-zero: ${jsonString}`,
71+
)
6272
}
6373
// Error response must have message field.
6474
if (typeof parsed.message !== 'string' || parsed.message.length === 0) {
65-
throw new Error(`JSON output missing required 'message' field when ok is false: ${jsonString}`)
75+
throw new Error(
76+
`JSON output missing required 'message' field when ok is false: ${jsonString}`,
77+
)
6678
}
6779
// If code exists, it must be a number.
6880
if (parsed.code !== undefined && typeof parsed.code !== 'number') {
69-
throw new Error(`JSON output 'code' field must be a number: ${jsonString}`)
81+
throw new Error(
82+
`JSON output 'code' field must be a number: ${jsonString}`,
83+
)
7084
}
7185
}
7286

@@ -77,7 +91,7 @@ export function validateSocketJson<T = unknown>(
7791
* Helper to check if response is a success response.
7892
*/
7993
export function isSocketJsonSuccess<T = unknown>(
80-
response: SocketJsonResponse<T>
94+
response: SocketJsonResponse<T>,
8195
): response is SocketJsonSuccess<T> {
8296
return response.ok === true
8397
}
@@ -86,7 +100,7 @@ export function isSocketJsonSuccess<T = unknown>(
86100
* Helper to check if response is an error response.
87101
*/
88102
export function isSocketJsonError<T = unknown>(
89-
response: SocketJsonResponse<T>
103+
response: SocketJsonResponse<T>,
90104
): response is SocketJsonError {
91105
return response.ok === false
92-
}
106+
}

src/test/mocks/socket-auth.mts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ export function mockConfigStorage() {
7070
/**
7171
* Mock API client with authentication.
7272
*/
73-
export function mockAuthenticatedApiClient(options?: { isAuthenticated?: boolean }) {
73+
export function mockAuthenticatedApiClient(options?: {
74+
isAuthenticated?: boolean
75+
}) {
7476
const { isAuthenticated = true } = options || {}
7577

7678
return {
@@ -79,11 +81,11 @@ export function mockAuthenticatedApiClient(options?: { isAuthenticated?: boolean
7981
setToken: vi.fn(),
8082
clearToken: vi.fn(),
8183
validateToken: vi.fn().mockResolvedValue(isAuthenticated),
82-
getOrganizations: vi.fn().mockResolvedValue(
83-
isAuthenticated
84-
? [{ id: MOCK_ORG_ID, name: MOCK_ORG_NAME }]
85-
: []
86-
),
84+
getOrganizations: vi
85+
.fn()
86+
.mockResolvedValue(
87+
isAuthenticated ? [{ id: MOCK_ORG_ID, name: MOCK_ORG_NAME }] : [],
88+
),
8789
}
8890
}
8991

@@ -132,9 +134,13 @@ export function setupLoginMocks(options?: {
132134
const { authenticated = false, loginShouldSucceed = true } = options || {}
133135

134136
const configMock = mockConfigStorage()
135-
const apiClientMock = mockAuthenticatedApiClient({ isAuthenticated: authenticated })
137+
const apiClientMock = mockAuthenticatedApiClient({
138+
isAuthenticated: authenticated,
139+
})
136140
const browserMock = mockBrowserOpener()
137-
const authFlowMock = mockInteractiveLogin({ shouldSucceed: loginShouldSucceed })
141+
const authFlowMock = mockInteractiveLogin({
142+
shouldSucceed: loginShouldSucceed,
143+
})
138144

139145
// Pre-populate config if authenticated.
140146
if (authenticated) {
@@ -156,4 +162,4 @@ export function setupLoginMocks(options?: {
156162
expect(configMock.unset).toHaveBeenCalledWith('apiToken')
157163
},
158164
}
159-
}
165+
}

0 commit comments

Comments
 (0)