import { describe, expect, test } from "bun:test";
import { mkdtempSync, readFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { DEPLOY_TARGETS, generateDeployment } from "../src/deploy.ts";

describe("deployment presets", () => {
  for (const target of DEPLOY_TARGETS) {
    test(`generates ${target}`, () => {
      const root = mkdtempSync(join(tmpdir(), `wrnexus-${target}-`));
      const files = generateDeployment(root, target);
      expect(files).toContain(".env.production.example");
      expect(readFileSync(join(root, "deploy/README.md"), "utf8")).toContain("/readyz");
      expect(generateDeployment(root, target)).toEqual([]);
    });
  }

  test("Kubernetes includes probes, limits and release migration", () => {
    const root = mkdtempSync(join(tmpdir(), "wrnexus-k8s-"));
    generateDeployment(root, "kubernetes");
    const manifest = readFileSync(join(root, "deploy/kubernetes.yaml"), "utf8");
    expect(manifest).toContain("readinessProbe");
    expect(manifest).toContain("kind: Job");
    expect(manifest).toContain("resources:");
  });

  test("rejects unknown targets", () => {
    expect(() => generateDeployment(".", "unknown")).toThrow("WRN-DEPLOY-TARGET");
  });
});
