Skip to content

Commit c46df44

Browse files
committed
fix tests
1 parent f4664c7 commit c46df44

File tree

1 file changed

+64
-18
lines changed

1 file changed

+64
-18
lines changed

client/src/components/__tests__/AuthDebugger.test.tsx

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,25 @@ Object.defineProperty(window, "location", {
7777
});
7878

7979
describe("AuthDebugger", () => {
80+
const defaultAuthState = {
81+
isInitiatingAuth: false,
82+
oauthTokens: null,
83+
loading: false,
84+
oauthStep: "not_started" as const,
85+
oauthMetadata: null,
86+
oauthClientInfo: null,
87+
authorizationUrl: null,
88+
authorizationCode: "",
89+
latestError: null,
90+
statusMessage: null,
91+
validationError: null,
92+
};
93+
8094
const defaultProps = {
8195
sseUrl: "https://example.com",
8296
onBack: jest.fn(),
97+
authState: defaultAuthState,
98+
updateAuthState: jest.fn(),
8399
};
84100

85101
beforeEach(() => {
@@ -97,9 +113,14 @@ describe("AuthDebugger", () => {
97113
});
98114

99115
const renderAuthDebugger = (props = {}) => {
116+
const mergedProps = {
117+
...defaultProps,
118+
...props,
119+
authState: { ...defaultAuthState, ...props.authState },
120+
};
100121
return render(
101122
<TooltipProvider>
102-
<AuthDebugger {...defaultProps} {...props} />
123+
<AuthDebugger {...mergedProps} />
103124
</TooltipProvider>,
104125
);
105126
};
@@ -136,19 +157,21 @@ describe("AuthDebugger", () => {
136157
});
137158

138159
it("should show error when OAuth flow is started without sseUrl", async () => {
160+
const updateAuthState = jest.fn();
139161
await act(async () => {
140-
renderAuthDebugger({ sseUrl: "" });
162+
renderAuthDebugger({ sseUrl: "", updateAuthState });
141163
});
142164

143165
await act(async () => {
144166
fireEvent.click(screen.getByText("Guided OAuth Flow"));
145167
});
146168

147-
expect(mockToast).toHaveBeenCalledWith({
148-
title: "Error",
149-
description:
150-
"Please enter a server URL in the sidebar before authenticating",
151-
variant: "destructive",
169+
expect(updateAuthState).toHaveBeenCalledWith({
170+
statusMessage: {
171+
type: "error",
172+
message:
173+
"Please enter a server URL in the sidebar before authenticating",
174+
},
152175
});
153176
});
154177
});
@@ -164,7 +187,12 @@ describe("AuthDebugger", () => {
164187
});
165188

166189
await act(async () => {
167-
renderAuthDebugger();
190+
renderAuthDebugger({
191+
authState: {
192+
...defaultAuthState,
193+
oauthTokens: mockOAuthTokens
194+
}
195+
});
168196
});
169197

170198
await waitFor(() => {
@@ -199,6 +227,7 @@ describe("AuthDebugger", () => {
199227

200228
describe("OAuth State Management", () => {
201229
it("should clear OAuth state when Clear button is clicked", async () => {
230+
const updateAuthState = jest.fn();
202231
// Mock the session storage to return tokens for the specific key
203232
sessionStorageMock.getItem.mockImplementation((key) => {
204233
if (key === "[https://example.com] mcp_tokens") {
@@ -208,16 +237,30 @@ describe("AuthDebugger", () => {
208237
});
209238

210239
await act(async () => {
211-
renderAuthDebugger();
240+
renderAuthDebugger({
241+
authState: {
242+
...defaultAuthState,
243+
oauthTokens: mockOAuthTokens
244+
},
245+
updateAuthState
246+
});
212247
});
213248

214249
await act(async () => {
215250
fireEvent.click(screen.getByText("Clear OAuth State"));
216251
});
217252

218-
expect(mockToast).toHaveBeenCalledWith({
219-
title: "Success",
220-
description: "OAuth tokens cleared successfully",
253+
expect(updateAuthState).toHaveBeenCalledWith({
254+
oauthTokens: null,
255+
oauthStep: "not_started",
256+
latestError: null,
257+
oauthClientInfo: null,
258+
authorizationCode: "",
259+
validationError: null,
260+
statusMessage: {
261+
type: "success",
262+
message: "OAuth tokens cleared successfully",
263+
},
221264
});
222265

223266
// Verify session storage was cleared
@@ -227,13 +270,16 @@ describe("AuthDebugger", () => {
227270

228271
describe("OAuth Flow Steps", () => {
229272
it("should handle OAuth flow step progression", async () => {
273+
const updateAuthState = jest.fn();
230274
await act(async () => {
231-
renderAuthDebugger();
232-
});
233-
234-
// Start guided flow
235-
await act(async () => {
236-
fireEvent.click(screen.getByText("Guided OAuth Flow"));
275+
renderAuthDebugger({
276+
updateAuthState,
277+
authState: {
278+
...defaultAuthState,
279+
isInitiatingAuth: false, // Changed to false so button is enabled
280+
oauthStep: "metadata_discovery"
281+
}
282+
});
237283
});
238284

239285
// Verify metadata discovery step

0 commit comments

Comments
 (0)