import { beforeEach, describe, expect, mock, test } from "bun:test";
const env = {
EMAIL_REPLY_DOMAIN: "gitfor.dev",
SECRETS_KEY: "k".repeat(32),
PUBLIC_URL: "https://gitfor.dev",
};
mock.module("cloudflare:workers", () => ({ env, waitUntil: () => undefined }));
type Issue = {
id: string;
repo_id: string;
is_pull: number;
locked: number;
number: number;
title: string;
};
const users = new Map([["u1aaaaaaaaaaaaaaaaaa", { account_id: "u1aaaaaaaaaaaaaaaaaa", name: "alice" }]]);
const emails = new Map([["u1aaaaaaaaaaaaaaaaaa", [{ email: "Alice@Example.com", verified: true, primary: true }]]]);
let issues = new Map<string, Issue>();
let access: "read" | "none" = "read";
let comments: Array<{ issueId: string; userId: string; body: string }> = [];
mock.module("./auth", () => ({
loadActiveUserById: async (id: string) => users.get(id) ?? null,
toViewer: (user: { account_id: string; name: string }) => ({
id: user.account_id,
name: user.name,
displayName: null,
email: "",
isAdmin: false,
}),
}));
mock.module("./scoped-db", () => ({
repoDb: () => ({
first: async (_sql: string, id: string) => issues.get(id) ?? null,
}),
}));
mock.module("./issue-scope", () => ({
issueRepoId: async (id: string) => issues.get(id)?.repo_id ?? null,