CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | /**
* Invite token helpers + /invites/:token smoke.
*
* We exercise the pure-crypto helpers exhaustively (cheap, deterministic)
* and hit the route with a bogus token to prove the not-found branch works
* without needing a DB seeded invite. A DB-seeded happy-path test would
* require fixture plumbing that the existing collaborators.test.ts also
* avoids, so we stay consistent.
*/
import { describe, it, expect } from "bun:test";
import {
generateInviteToken,
hashInviteToken,
} from "../lib/invite-tokens";
import app from "../app";
describe("invite-tokens lib", () => {
it("generateInviteToken emits 32 hex chars and is unique across calls", () => {
const seen = new Set<string>();
for (let i = 0; i < 100; i++) {
const t = generateInviteToken();
expect(t).toMatch(/^[0-9a-f]{32}$/);
expect(seen.has(t)).toBe(false);
seen.add(t);
}
});
it("hashInviteToken is deterministic and differs per input", () => {
const a = generateInviteToken();
const b = generateInviteToken();
expect(hashInviteToken(a)).toBe(hashInviteToken(a));
expect(hashInviteToken(a)).not.toBe(hashInviteToken(b));
// sha256 hex is 64 chars.
expect(hashInviteToken(a)).toMatch(/^[0-9a-f]{64}$/);
});
});
describe("GET /invites/:token", () => {
it("returns 404 for a bogus token", async () => {
const res = await app.request("/invites/not-a-real-token-xxxxxxxxxxxxxxxx");
// 404 is the expected path. If the DB is unreachable in the test env the
// route's try/catch still maps that to not-found, so 404 is the single
// acceptable status.
expect(res.status).toBe(404);
});
});
|