import { describe, expect, test } from "vitest";

import { getRepositoryFromRuntime } from "../repository";

describe("getRepositoryFromRuntime", () => {
  test("returns local repository when APP_RUNTIME is not cloudflare", () => {
    const repository = getRepositoryFromRuntime({
      appRuntime: "local",
      dbPath: ":memory:",
    });

    expect(repository).toBeDefined();
  });

  test("throws clearly for cloudflare runtime without D1 binding", () => {
    expect(() =>
      getRepositoryFromRuntime({
        appRuntime: "cloudflare",
        cloudflareEnv: {},
      }),
    ).toThrow("Cloudflare D1 binding DB is required");
  });
});
