release: WRNexusJS 0.4.0
This commit is contained in:
@@ -3,11 +3,13 @@ import { turnstileProvider } from "../src/providers/turnstile.ts";
|
||||
import { recaptchaProvider } from "../src/providers/recaptcha.ts";
|
||||
import { hcaptchaProvider } from "../src/providers/hcaptcha.ts";
|
||||
|
||||
const okFetch = (payload: Record<string, unknown>) => async (_url: string | URL | Request, init?: RequestInit) => {
|
||||
expect(init?.method).toBe("POST");
|
||||
expect(init?.headers).toMatchObject({ "content-type": "application/x-www-form-urlencoded" });
|
||||
return Response.json(payload);
|
||||
};
|
||||
const okFetch =
|
||||
(payload: Record<string, unknown>) =>
|
||||
async (_url: string | URL | Request, init?: RequestInit) => {
|
||||
expect(init?.method).toBe("POST");
|
||||
expect(init?.headers).toMatchObject({ "content-type": "application/x-www-form-urlencoded" });
|
||||
return Response.json(payload);
|
||||
};
|
||||
|
||||
describe("hosted providers", () => {
|
||||
test("verifies Turnstile hostname and action", async () => {
|
||||
@@ -17,7 +19,10 @@ describe("hosted providers", () => {
|
||||
expectedAction: "signup",
|
||||
fetch: okFetch({ success: true, hostname: "example.test", action: "signup" }) as typeof fetch,
|
||||
});
|
||||
expect(await provider.verify({ action: "signup", providerToken: "token" })).toMatchObject({ success: true, provider: "turnstile" });
|
||||
expect(await provider.verify({ action: "signup", providerToken: "token" })).toMatchObject({
|
||||
success: true,
|
||||
provider: "turnstile",
|
||||
});
|
||||
});
|
||||
|
||||
test("maps provider duplicate failures", async () => {
|
||||
@@ -25,7 +30,10 @@ describe("hosted providers", () => {
|
||||
secretKey: "secret",
|
||||
fetch: okFetch({ success: false, "error-codes": ["timeout-or-duplicate"] }) as typeof fetch,
|
||||
});
|
||||
expect(await provider.verify({ action: "login", providerToken: "token" })).toMatchObject({ success: false, code: "already-used" });
|
||||
expect(await provider.verify({ action: "login", providerToken: "token" })).toMatchObject({
|
||||
success: false,
|
||||
code: "already-used",
|
||||
});
|
||||
});
|
||||
|
||||
test("sends hCaptcha site key when configured", async () => {
|
||||
@@ -38,7 +46,9 @@ describe("hosted providers", () => {
|
||||
return Response.json({ success: true, hostname: "example.test" });
|
||||
}) as typeof fetch,
|
||||
});
|
||||
expect((await provider.verify({ action: "contact", providerToken: "token" })).success).toBe(true);
|
||||
expect((await provider.verify({ action: "contact", providerToken: "token" })).success).toBe(
|
||||
true,
|
||||
);
|
||||
expect(submitted).toContain("sitekey=site-key");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user