feat: add extensive test suite

This commit is contained in:
2026-08-30 11:33:53 +07:00 Unverified
parent 061cce00dc
commit 8359c7272e
131 changed files with 8717 additions and 2200 deletions
+23
View File
@@ -0,0 +1,23 @@
import { describe, expect, mock, test } from "bun:test";
import { createAuthHandlers } from "./handler";
describe("auth route factory", () => {
test("creates both handlers from the provided auth instance", async () => {
const auth = { name: "auth" };
const get = mock(async (_request: Request) => new Response("GET"));
const post = mock(async (_request: Request) => new Response("POST"));
const adapter = mock((_auth: typeof auth) => ({ GET: get, POST: post }));
const handlers = createAuthHandlers(adapter, auth);
expect(adapter).toHaveBeenCalledWith(auth);
expect(
await (await handlers.GET(new Request("https://buzz.test"))).text(),
).toBe("GET");
expect(
await (
await handlers.POST(
new Request("https://buzz.test", { method: "POST" }),
)
).text(),
).toBe("POST");
});
});
+8
View File
@@ -0,0 +1,8 @@
type AuthHandler = (request: Request) => Response | Promise<Response>;
export function createAuthHandlers<TAuth>(
toHandler: (auth: TAuth) => { GET: AuthHandler; POST: AuthHandler },
auth: TAuth,
) {
return toHandler(auth);
}
+2 -1
View File
@@ -1,4 +1,5 @@
import { toNextJsHandler } from "better-auth/next-js";
import { auth } from "@/lib/auth"; // path to your auth file
import { createAuthHandlers } from "./handler";
export const { POST, GET } = toNextJsHandler(auth);
export const { POST, GET } = createAuthHandlers(toNextJsHandler, auth);