From 324e872849bca4e4be40d83d96d9afdba8eef6f6 Mon Sep 17 00:00:00 2001 From: dswbx Date: Tue, 22 Jul 2025 20:58:03 +0200 Subject: [PATCH] add custom auth strategy test --- app/__test__/auth/strategies/custom.test.ts | 54 +++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 app/__test__/auth/strategies/custom.test.ts diff --git a/app/__test__/auth/strategies/custom.test.ts b/app/__test__/auth/strategies/custom.test.ts new file mode 100644 index 00000000..e5f7f702 --- /dev/null +++ b/app/__test__/auth/strategies/custom.test.ts @@ -0,0 +1,54 @@ +import { AuthStrategy, registries } from "bknd"; +import { describe, it, expect } from "bun:test"; +import { createApp } from "core/test/utils"; +import { s } from "bknd/utils"; +import { Hono } from "hono"; + +const customStrategySchema = s.object({ + name: s.string(), +}); +type CustomStrategyOptions = s.Static; + +class CustomStrategy extends AuthStrategy { + constructor(config: Partial = {}) { + super(config as any, "custom", "custom", "form"); + } + getSchema() { + return customStrategySchema; + } + + getController() { + return new Hono() + .post("/login", async (c) => { + return c.json({ + message: "Hello, world!", + }); + }) + .post("/register", async (c) => { + return c.json({ + message: "Hello, world!", + }); + }); + } +} + +describe("custom auth strategy", () => { + it("should be registered", async () => { + registries.auth.register("custom", CustomStrategy); + + const app = createApp({ + initialConfig: { + auth: { + enabled: true, + }, + }, + }); + await app.build(); + + const strategies = app + .getSchema() + .auth.properties.strategies.additionalProperties.anyOf.map((s) => s.properties.type.const); + + expect(strategies).toContain("custom"); + }); +});