Skip to content

Commit aa9374f

Browse files
committed
fix: update mock-connector for new types
1 parent 639a866 commit aa9374f

4 files changed

Lines changed: 49 additions & 5 deletions

File tree

cli/src/mock-app.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,18 @@ function createMockConnectorApp(stateManager: MockConnectorStateManager) {
230230
requireAuth(event)
231231

232232
const body = await event.req.json().catch(() => ({}))
233-
const otp = (body as { otp?: string })?.otp
233+
const { otp } = body as { otp?: string; interactive?: boolean; openUrls?: boolean }
234234

235-
const { results, otpRequired } = stateManager.executeOperations({ otp })
235+
const { results, otpRequired, authFailure, urls } = stateManager.executeOperations({ otp })
236236

237237
return {
238238
success: true,
239-
data: { results, otpRequired },
239+
data: {
240+
results,
241+
otpRequired,
242+
authFailure,
243+
urls,
244+
},
240245
} satisfies ApiResponse<ConnectorEndpoints['POST /execute']['data']>
241246
})
242247

cli/src/mock-state.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export interface ExecuteOptions {
5858
export interface ExecuteResult {
5959
results: Array<{ id: string; result: OperationResult }>
6060
otpRequired?: boolean
61+
authFailure?: boolean
62+
urls?: string[]
6163
}
6264

6365
export function createMockConnectorState(config: MockConnectorConfig): MockConnectorStateData {
@@ -305,7 +307,15 @@ export class MockConnectorStateManager {
305307
}
306308
}
307309

308-
return { results }
310+
const authFailure = results.some(r => r.result.authFailure)
311+
const allUrls = results.flatMap(r => r.result.urls ?? [])
312+
const urls = [...new Set(allUrls)]
313+
314+
return {
315+
results,
316+
authFailure: authFailure || undefined,
317+
urls: urls.length > 0 ? urls : undefined,
318+
}
309319
}
310320

311321
/** Apply side effects of a completed operation. Param keys match schemas.ts. */

cli/src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export interface ExecuteResponseData {
9898
results: Array<{ id: string; result: OperationResult }>
9999
otpRequired?: boolean
100100
authFailure?: boolean
101+
urls?: string[]
101102
}
102103

103104
/** POST /approve-all response data */
@@ -133,7 +134,10 @@ export interface ConnectorEndpoints {
133134
'POST /approve': { body: never; data: PendingOperation }
134135
'POST /approve-all': { body: never; data: ApproveAllResponseData }
135136
'POST /retry': { body: never; data: PendingOperation }
136-
'POST /execute': { body: { otp?: string }; data: ExecuteResponseData }
137+
'POST /execute': {
138+
body: { otp?: string; interactive?: boolean; openUrls?: boolean }
139+
data: ExecuteResponseData
140+
}
137141
'GET /org/:org/users': { body: never; data: Record<string, OrgRole> }
138142
'GET /org/:org/teams': { body: never; data: string[] }
139143
'GET /team/:scopeTeam/users': { body: never; data: string[] }

test/nuxt/components/HeaderConnectorModal.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ function resetMockState() {
9999
error: null,
100100
lastExecutionTime: null,
101101
}
102+
mockSettings.value.connector = {
103+
webAuth: false,
104+
autoOpenURL: false,
105+
}
102106
}
103107

104108
function simulateConnect() {
@@ -112,6 +116,27 @@ vi.mock('~/composables/useConnector', () => ({
112116
useConnector: createMockUseConnector,
113117
}))
114118

119+
const mockSettings = ref({
120+
relativeDates: false,
121+
includeTypesInInstall: true,
122+
accentColorId: null,
123+
hidePlatformPackages: true,
124+
selectedLocale: null,
125+
preferredBackgroundTheme: null,
126+
searchProvider: 'npm',
127+
connector: {
128+
webAuth: false,
129+
autoOpenURL: false,
130+
},
131+
sidebar: {
132+
collapsed: [],
133+
},
134+
})
135+
136+
vi.mock('~/composables/useSettings', () => ({
137+
useSettings: () => ({ settings: mockSettings }),
138+
}))
139+
115140
vi.mock('~/composables/useSelectedPackageManager', () => ({
116141
useSelectedPackageManager: () => ref('npm'),
117142
}))

0 commit comments

Comments
 (0)