263 lines · 8.3 KB
import { beforeEach, describe, expect, mock, test } from "bun:test";
import type { RepoRow, Viewer } from "~/lib/types";
import type { RequestCredential } from "../token-scope";

class StubEntrypoint {}
mock.module("cloudflare:workers", () => ({
  env: { PUBLIC_URL: "https://forge.example.com" },
  waitUntil: () => undefined,
  WorkflowEntrypoint: StubEntrypoint,
  DurableObject: StubEntrypoint,
  WorkerEntrypoint: StubEntrypoint,
}));

type Collaborator = { repoId: string; userId: string; permission: "read" | "write" | "admin" };
const state: {
  repos: RepoRow[];
  collaborators: Collaborator[];
  tokenRepos: Array<{ tokenId: string; repoId: string }>;
} = {
  repos: [],
  collaborators: [],
  tokenRepos: [],
};

const pull = {
  issue_id: "issue-1",
  repo_id: "base",
  number: 1,
  title: "Feature",
  body: "",
  state: "open",
  author_id: "forker",
  head_repo_id: "fork",
  head_ref: "feature",
  head_sha: "a".repeat(40),
  base_ref: "main",
  base_sha: "b".repeat(40),
  merge_base_sha: null,
  draft: 0,
  mergeable: "unknown",