243 lines · 12.2 KB
import { beforeEach, describe, expect, mock, test } from "bun:test";
import { Database } from "bun:sqlite";
import { applyCombinedSchema } from "./test-schema.test-helper";

const dropped: string[] = [];
const sent: { to: string; text?: string; html?: string }[] = [];

class StubEntrypoint {}
mock.module("cloudflare:workers", () => ({
  env: {
    PUBLIC_URL: "http://localhost:8787",
    SECRETS_KEY: "test-key",
    RATE_LIMITS_DISABLED: "true",
    EMAIL_FROM: "gitfor <noreply@gitfor.dev>",
    EVENTS: {
      send: async (message: { to: string; text?: string; html?: string }) => {
        sent.push(message);
      },
    },
    MCP_HUB: {
      idFromName: (name: string) => name,
      get: () => ({
        invalidateSubscribers: async (repoId: string) => {
          dropped.push(repoId);
        },
      }),
    },
  },
  waitUntil: () => undefined,
  WorkflowEntrypoint: StubEntrypoint,
  DurableObject: StubEntrypoint,
  WorkerEntrypoint: StubEntrypoint,
}));
mock.module("@tanstack/react-start/server", () => ({
  getRequestHeader: () => undefined,
  getCookie: () => undefined,
  setCookie: () => undefined,
  deleteCookie: () => undefined,
}));