Skip to content

Commit d1162be

Browse files
committed
Updated existing tests
1 parent 96887d4 commit d1162be

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

src/client/auth.test.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
refreshAuthorization,
66
registerClient,
77
} from "./auth.js";
8+
import {ServerError} from "../server/auth/errors.js";
89

910
// Mock fetch globally
1011
const mockFetch = jest.fn();
@@ -112,25 +113,23 @@ describe("OAuth Authorization", () => {
112113
});
113114

114115
it("throws on non-404 errors", async () => {
115-
mockFetch.mockResolvedValueOnce({
116-
ok: false,
117-
status: 500,
118-
});
116+
mockFetch.mockResolvedValueOnce(new Response(null, { status: 500 }));
119117

120118
await expect(
121119
discoverOAuthMetadata("https://auth.example.com")
122120
).rejects.toThrow("HTTP 500");
123121
});
124122

125123
it("validates metadata schema", async () => {
126-
mockFetch.mockResolvedValueOnce({
127-
ok: true,
128-
status: 200,
129-
json: async () => ({
130-
// Missing required fields
131-
issuer: "https://auth.example.com",
132-
}),
133-
});
124+
mockFetch.mockResolvedValueOnce(
125+
Response.json(
126+
{
127+
// Missing required fields
128+
issuer: "https://auth.example.com",
129+
},
130+
{ status: 200 }
131+
)
132+
);
134133

135134
await expect(
136135
discoverOAuthMetadata("https://auth.example.com")
@@ -321,10 +320,12 @@ describe("OAuth Authorization", () => {
321320
});
322321

323322
it("throws on error response", async () => {
324-
mockFetch.mockResolvedValueOnce({
325-
ok: false,
326-
status: 400,
327-
});
323+
mockFetch.mockResolvedValueOnce(
324+
Response.json(
325+
new ServerError("Token exchange failed").toResponseObject(),
326+
{ status: 400 }
327+
)
328+
);
328329

329330
await expect(
330331
exchangeAuthorization("https://auth.example.com", {
@@ -403,10 +404,12 @@ describe("OAuth Authorization", () => {
403404
});
404405

405406
it("throws on error response", async () => {
406-
mockFetch.mockResolvedValueOnce({
407-
ok: false,
408-
status: 400,
409-
});
407+
mockFetch.mockResolvedValueOnce(
408+
Response.json(
409+
new ServerError("Token refresh failed").toResponseObject(),
410+
{ status: 400 }
411+
)
412+
);
410413

411414
await expect(
412415
refreshAuthorization("https://auth.example.com", {
@@ -491,10 +494,12 @@ describe("OAuth Authorization", () => {
491494
});
492495

493496
it("throws on error response", async () => {
494-
mockFetch.mockResolvedValueOnce({
495-
ok: false,
496-
status: 400,
497-
});
497+
mockFetch.mockResolvedValueOnce(
498+
Response.json(
499+
new ServerError("Dynamic client registration failed").toResponseObject(),
500+
{ status: 400 }
501+
)
502+
);
498503

499504
await expect(
500505
registerClient("https://auth.example.com", {

0 commit comments

Comments
 (0)