Skip to content

Commit 1751bde

Browse files
committed
Fix tests
1 parent d386e7f commit 1751bde

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

test/mocks/vscode.runtime.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export const TreeItemCollapsibleState = E({
2828
export const StatusBarAlignment = E({ Left: 1, Right: 2 });
2929
export const ExtensionMode = E({ Production: 1, Development: 2, Test: 3 });
3030
export const UIKind = E({ Desktop: 1, Web: 2 });
31+
export const InputBoxValidationSeverity = E({
32+
Info: 1,
33+
Warning: 2,
34+
Error: 3,
35+
});
3136

3237
export class Uri {
3338
constructor(
@@ -142,6 +147,7 @@ const vscode = {
142147
StatusBarAlignment,
143148
ExtensionMode,
144149
UIKind,
150+
InputBoxValidationSeverity,
145151
Uri,
146152
EventEmitter,
147153
window,

test/unit/login/loginCoordinator.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,15 @@ describe("LoginCoordinator", () => {
153153
createTestContext();
154154
const user = createMockUser();
155155

156-
// First call fails (no token), second succeeds after user enters token
157-
mockAdapter
158-
.mockRejectedValueOnce({
159-
response: { status: 401, data: { message: "Unauthorized" } },
160-
})
161-
.mockResolvedValueOnce({
162-
data: user,
163-
status: 200,
164-
statusText: "OK",
165-
headers: {},
166-
config: {},
167-
});
156+
// No stored token, so goes directly to input box flow
157+
// Mock succeeds when validateInput calls getAuthenticatedUser
158+
mockAdapter.mockResolvedValueOnce({
159+
data: user,
160+
status: 200,
161+
statusText: "OK",
162+
headers: {},
163+
config: {},
164+
});
168165

169166
// User enters a new token in the input box
170167
userInteraction.setInputBoxValue("new-token");
@@ -198,9 +195,12 @@ describe("LoginCoordinator", () => {
198195

199196
describe("same-window guard", () => {
200197
it("prevents duplicate login calls for same hostname", async () => {
201-
const { mockAdapter, coordinator } = createTestContext();
198+
const { mockAdapter, userInteraction, coordinator } = createTestContext();
202199
const user = createMockUser();
203200

201+
// User enters a token in the input box
202+
userInteraction.setInputBoxValue("new-token");
203+
204204
let resolveAuth: (value: unknown) => void;
205205
mockAdapter.mockReturnValue(
206206
new Promise((resolve) => {
@@ -220,7 +220,7 @@ describe("LoginCoordinator", () => {
220220
safeHostname: TEST_HOSTNAME,
221221
});
222222

223-
// Resolve the auth
223+
// Resolve the auth (this validates the token from input box)
224224
resolveAuth!({
225225
data: user,
226226
status: 200,
@@ -234,8 +234,8 @@ describe("LoginCoordinator", () => {
234234
expect(result1.success).toBe(true);
235235
expect(result1).toEqual(result2);
236236

237-
// Adapter should only be called once (guard prevents duplicate requests)
238-
expect(mockAdapter).toHaveBeenCalledTimes(1);
237+
// Input box should only be shown once (guard prevents duplicate prompts)
238+
expect(vscode.window.showInputBox).toHaveBeenCalledTimes(1);
239239
});
240240
});
241241

0 commit comments

Comments
 (0)