All checks were successful
Deploy production / deploy (push) Successful in 10m51s
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { fetchRegistrationAvailability } from "./registration-availability.ts";
|
|
|
|
for (const allowed of [true, false]) {
|
|
test(`registration availability: ${allowed}`, async (t) => {
|
|
const signal = new AbortController().signal;
|
|
t.mock.method(globalThis, "fetch", async (url, options) => {
|
|
assert.equal(url, "/api/auth/registration-availability/");
|
|
assert.equal(options.cache, "no-store");
|
|
assert.equal(options.credentials, "same-origin");
|
|
assert.equal(options.redirect, "error");
|
|
assert.equal(options.signal, signal);
|
|
return Response.json({ registration_allowed: allowed });
|
|
});
|
|
assert.equal(
|
|
await fetchRegistrationAvailability(signal),
|
|
allowed ? "allowed" : "denied",
|
|
);
|
|
});
|
|
}
|
|
|
|
for (const payload of [
|
|
null,
|
|
{},
|
|
{ registration_allowed: "true" },
|
|
{ registration_allowed: 1 },
|
|
]) {
|
|
test(`invalid response fails closed: ${JSON.stringify(payload)}`, async (t) => {
|
|
t.mock.method(globalThis, "fetch", async () => Response.json(payload));
|
|
await assert.rejects(
|
|
fetchRegistrationAvailability(new AbortController().signal),
|
|
);
|
|
});
|
|
}
|
|
|
|
test("server failure does not expose registration", async (t) => {
|
|
t.mock.method(globalThis, "fetch", async () =>
|
|
Response.json({ registration_allowed: true }, { status: 503 }),
|
|
);
|
|
await assert.rejects(
|
|
fetchRegistrationAvailability(new AbortController().signal),
|
|
);
|
|
});
|
|
|
|
test("network failure does not expose registration", async (t) => {
|
|
t.mock.method(globalThis, "fetch", async () => {
|
|
throw new TypeError("offline");
|
|
});
|
|
await assert.rejects(
|
|
fetchRegistrationAvailability(new AbortController().signal),
|
|
);
|
|
});
|