diff --git a/bun.lockb b/bun.lockb index 4f81503..3f8c38c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 6296001..5307482 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "@total-typescript/tsconfig": "^1.0.4", "@types/bun": "^1.1.13", "@types/debug": "^4.1.12", + "msw": "^2.6.6", "remix-auth": "^4.0.0", "typedoc": "^0.26.11", "typedoc-plugin-mdn-links": "^4.0.1", diff --git a/src/index.test.ts b/src/index.test.ts index 424a3f4..559f6e5 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,8 +1,30 @@ -import { describe, expect, mock, test } from "bun:test"; +import { + afterAll, + afterEach, + beforeAll, + describe, + expect, + mock, + test, +} from "bun:test"; import { Cookie, SetCookie } from "@mjackson/headers"; +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/native"; import { OAuth2Strategy } from "."; import { catchResponse } from "./test/helpers"; +const server = setupServer( + http.post("https://example.app/token", async () => { + return HttpResponse.json({ + access_token: "mocked", + expires_in: 3600, + refresh_token: "mocked", + scope: ["user:email", "user:profile"].join(" "), + token_type: "Bearer", + }); + }), +); + describe(OAuth2Strategy.name, () => { let verify = mock(); @@ -19,6 +41,18 @@ describe(OAuth2Strategy.name, () => { id: string; } + beforeAll(() => { + server.listen(); + }); + + afterEach(() => { + server.resetHandlers(); + }); + + afterAll(() => { + server.close(); + }); + test("should have the name `oauth2`", () => { let strategy = new OAuth2Strategy(options, verify); expect(strategy.name).toBe("oauth2"); @@ -101,7 +135,7 @@ describe(OAuth2Strategy.name, () => { { headers: { cookie: cookie.toString() } }, ); - await strategy.authenticate(request).catch((error) => error); + await strategy.authenticate(request); expect(verify).toHaveBeenCalled(); });