Skip to content

Commit 6697a7c

Browse files
committed
Rebase fallout
1 parent 4573602 commit 6697a7c

File tree

7 files changed

+67
-49
lines changed

7 files changed

+67
-49
lines changed

src/login/loginCoordinator.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ export class LoginCoordinator implements vscode.Disposable {
155155
executeFn: () => Promise<LoginResult>,
156156
): Promise<LoginResult> {
157157
const result = this.loginQueue.then(executeFn);
158-
this.loginQueue = result.catch(() => {}); // Keep chain going on error
158+
this.loginQueue = result.catch(() => {
159+
/* Keep chain going on error */
160+
});
159161
return result;
160162
}
161163

@@ -389,7 +391,7 @@ export class LoginCoordinator implements vscode.Disposable {
389391
const title = "OAuth authentication failed";
390392
this.logger.error(title, error);
391393
if (error instanceof CertificateError) {
392-
error.showNotification(title);
394+
void error.showNotification(title);
393395
} else {
394396
vscode.window.showErrorMessage(
395397
`${title}: ${getErrorMessage(error, "Unknown error")}`,

src/oauth/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function parseOAuthError(error: unknown): OAuthError | null {
116116
return null;
117117
}
118118

119-
const data = error.response?.data;
119+
const data: unknown = error.response?.data;
120120

121121
if (!isOAuthErrorResponse(data)) {
122122
return null;

test/mocks/testHelpers.ts

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import axios, { AxiosError, AxiosHeaders } from "axios";
1+
import axios, {
2+
AxiosError,
3+
AxiosHeaders,
4+
type AxiosAdapter,
5+
type AxiosResponse,
6+
type InternalAxiosRequestConfig,
7+
} from "axios";
28
import { vi } from "vitest";
39
import * as vscode from "vscode";
410

@@ -559,7 +565,7 @@ export class MockOAuthSessionManager {
559565
.mockResolvedValue({ access_token: "test-token" });
560566
readonly refreshIfAlmostExpired = vi.fn().mockResolvedValue(undefined);
561567
readonly revokeRefreshToken = vi.fn().mockResolvedValue(undefined);
562-
readonly isLoggedInWithOAuth = vi.fn().mockReturnValue(false);
568+
readonly isLoggedInWithOAuth = vi.fn().mockResolvedValue(false);
563569
readonly clearOAuthState = vi.fn().mockResolvedValue(undefined);
564570
readonly showReAuthenticationModal = vi.fn().mockResolvedValue(undefined);
565571
readonly dispose = vi.fn();
@@ -618,7 +624,7 @@ export function createAxiosError(
618624
return error;
619625
}
620626

621-
type MockAdapterFn = ReturnType<typeof vi.fn>;
627+
type MockAdapterFn = ReturnType<typeof vi.fn<AxiosAdapter>>;
622628

623629
const AXIOS_MOCK_SETUP_EXAMPLE = `
624630
vi.mock("axios", async () => {
@@ -680,40 +686,44 @@ export function setupAxiosMockRoutes(
680686
mockAdapter: MockAdapterFn,
681687
routes: Record<string, unknown>,
682688
): void {
683-
mockAdapter.mockImplementation(async (config: { url?: string }) => {
684-
for (const [pattern, value] of Object.entries(routes)) {
685-
if (config.url?.includes(pattern)) {
686-
if (value instanceof Error) {
687-
throw value;
689+
mockAdapter.mockImplementation(
690+
async (
691+
config: InternalAxiosRequestConfig,
692+
): Promise<AxiosResponse<unknown>> => {
693+
for (const [pattern, value] of Object.entries(routes)) {
694+
if (config.url?.includes(pattern)) {
695+
if (value instanceof Error) {
696+
throw value;
697+
}
698+
const data = typeof value === "function" ? await value() : value;
699+
return {
700+
data,
701+
status: 200,
702+
statusText: "OK",
703+
headers: new AxiosHeaders(),
704+
config,
705+
};
688706
}
689-
const data = typeof value === "function" ? await value() : value;
690-
return {
691-
data,
692-
status: 200,
693-
statusText: "OK",
694-
headers: {},
695-
config,
696-
};
697707
}
698-
}
699-
const error = new AxiosError(
700-
`Request failed with status code 404`,
701-
"ERR_BAD_REQUEST",
702-
undefined,
703-
undefined,
704-
{
705-
status: 404,
706-
statusText: "Not Found",
707-
headers: {},
708-
config: { headers: new AxiosHeaders() },
709-
data: {
710-
message: "Not found",
711-
detail: `No route matched: ${config.url}`,
708+
const error = new AxiosError(
709+
`Request failed with status code 404`,
710+
"ERR_BAD_REQUEST",
711+
undefined,
712+
undefined,
713+
{
714+
status: 404,
715+
statusText: "Not Found",
716+
headers: new AxiosHeaders(),
717+
config,
718+
data: {
719+
message: "Not found",
720+
detail: `No route matched: ${config.url}`,
721+
},
712722
},
713-
},
714-
);
715-
throw error;
716-
});
723+
);
724+
throw error;
725+
},
726+
);
717727
}
718728

719729
/**

test/unit/oauth/authorizer.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ import {
2020
TEST_URL,
2121
} from "./testUtils";
2222

23+
import type { CreateAxiosDefaults } from "axios";
24+
2325
vi.mock("axios", async () => {
2426
const actual = await vi.importActual<typeof import("axios")>("axios");
2527
const mockAdapter = vi.fn();
2628
return {
2729
...actual,
2830
default: {
2931
...actual.default,
30-
create: vi.fn((config) =>
32+
create: vi.fn((config?: CreateAxiosDefaults) =>
3133
actual.default.create({ ...config, adapter: mockAdapter }),
3234
),
3335
__mockAdapter: mockAdapter,

test/unit/oauth/axiosInterceptor.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ function createMockAxiosInstance(): AxiosInstance & {
3232
vi.spyOn(instance.interceptors.response, "use").mockImplementation(
3333
(_onFulfilled, onRejected) => {
3434
interceptorCount++;
35-
lastRejectedHandler = onRejected ?? ((e) => Promise.reject(e));
35+
lastRejectedHandler =
36+
onRejected ??
37+
((e): never => {
38+
throw e;
39+
});
3640
return interceptorCount;
3741
},
3842
);
@@ -47,7 +51,7 @@ function createMockAxiosInstance(): AxiosInstance & {
4751
return Object.assign(instance, {
4852
triggerResponseError: (error: unknown): Promise<unknown> => {
4953
if (!lastRejectedHandler) {
50-
return Promise.reject(error);
54+
return Promise.reject(new Error(String(error)));
5155
}
5256
return Promise.resolve(lastRejectedHandler(error));
5357
},
@@ -81,12 +85,10 @@ function createTestContext() {
8185
const mockOAuthManager = new MockOAuthSessionManager();
8286

8387
// Make isLoggedInWithOAuth check actual storage instead of returning a fixed value
84-
vi.spyOn(mockOAuthManager, "isLoggedInWithOAuth").mockImplementation(
85-
async () => {
86-
const auth = await secretsManager.getSessionAuth(TEST_HOSTNAME);
87-
return auth?.oauth !== undefined;
88-
},
89-
);
88+
mockOAuthManager.isLoggedInWithOAuth.mockImplementation(async () => {
89+
const auth = await secretsManager.getSessionAuth(TEST_HOSTNAME);
90+
return auth?.oauth !== undefined;
91+
});
9092

9193
/** Sets up OAuth tokens and creates interceptor */
9294
const setupOAuthInterceptor = async () => {

test/unit/oauth/sessionManager.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
TEST_URL,
2020
} from "./testUtils";
2121

22+
import type { AxiosRequestConfig } from "axios";
23+
2224
import type { ServiceContainer } from "@/core/container";
2325
import type { Deployment } from "@/deployment/types";
2426
import type { LoginCoordinator } from "@/login/loginCoordinator";
@@ -30,7 +32,7 @@ vi.mock("axios", async () => {
3032
...actual,
3133
default: {
3234
...actual.default,
33-
create: vi.fn((config) =>
35+
create: vi.fn((config?: AxiosRequestConfig) =>
3436
actual.default.create({ ...config, adapter: mockAdapter }),
3537
),
3638
__mockAdapter: mockAdapter,

test/unit/uri/uriHandler.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,11 @@ describe("uriHandler", () => {
323323
});
324324

325325
describe(CALLBACK_PATH, () => {
326-
type CallbackData = {
326+
interface CallbackData {
327327
state: string;
328328
code: string | null;
329329
error: string | null;
330-
};
330+
}
331331

332332
it("stores OAuth callback with code and state", async () => {
333333
const { handleUri, secretsManager } = createTestContext();

0 commit comments

Comments
 (0)