// @ts-ignore
import { detectProjectMetadata } from "./projectMetadata.js";
import * as fs from "fs";
import * as path from "path";
import * as os from "os";
function makeTempDir() {
    return fs.mkdtempSync(path.join(os.tmpdir(), "pm-test-"));
}
describe("detectProjectMetadata", () => {
    it("detects Node.js + Express project", () => {
        const dir = makeTempDir();
        fs.writeFileSync(path.join(dir, "package.json"), JSON.stringify({ dependencies: { express: "^4.18.0" } }));
        const meta = detectProjectMetadata(dir);
        expect(meta.primaryLanguage).toBe("JavaScript");
        expect(meta.frameworks).toContain("Express");
        expect(meta.projectType).toBe("rest-api");
    });
    it("detects Node.js + Next.js as fullstack", () => {
        const dir = makeTempDir();
        fs.writeFileSync(path.join(dir, "package.json"), JSON.stringify({ dependencies: { next: "^14.0.0", react: "^18.0.0" } }));
        const meta = detectProjectMetadata(dir);
        expect(meta.frameworks).toContain("Next.js");
        expect(meta.frameworks).toContain("React");
        expect(["frontend", "full-stack"]).toContain(meta.projectType);
    });
    it("detects Python + FastAPI project", () => {
        const dir = makeTempDir();
        fs.writeFileSync(path.join(dir, "requirements.txt"), "fastapi==0.100.0\nuvicorn\n");
        const meta = detectProjectMetadata(dir);
        expect(meta.primaryLanguage).toBe("Python");
        expect(meta.frameworks).toContain("FastAPI");
    });
    it("detects Python + Django project", () => {
        const dir = makeTempDir();
        fs.writeFileSync(path.join(dir, "requirements.txt"), "django==4.2\n");
        const meta = detectProjectMetadata(dir);
        expect(meta.primaryLanguage).toBe("Python");
        expect(meta.frameworks).toContain("Django");
    });
    it("detects Java + Spring project", () => {
        const dir = makeTempDir();
        fs.writeFileSync(path.join(dir, "pom.xml"), "<project></project>");
        const meta = detectProjectMetadata(dir);
        expect(meta.primaryLanguage).toBe("Java");
        expect(meta.frameworks).toContain("Spring");
    });
    it("detects Go + Gin project", () => {
        const dir = makeTempDir();
        fs.writeFileSync(path.join(dir, "go.mod"), "module example.com/app\nrequire github.com/gin-gonic/gin v1.9.0\n");
        const meta = detectProjectMetadata(dir);
        expect(meta.primaryLanguage).toBe("Go");
        expect(meta.frameworks).toContain("Gin");
    });
    it("detects Ruby + Rails project", () => {
        const dir = makeTempDir();
        fs.writeFileSync(path.join(dir, "Gemfile"), 'source "https://rubygems.org"\ngem "rails", "~> 7.0"\n');
        const meta = detectProjectMetadata(dir);
        expect(meta.primaryLanguage).toBe("Ruby");
        expect(meta.frameworks).toContain("Rails");
    });
    it("detects PHP + Laravel project", () => {
        const dir = makeTempDir();
        fs.writeFileSync(path.join(dir, "composer.json"), JSON.stringify({ require: { "laravel/framework": "^10.0" } }));
        const meta = detectProjectMetadata(dir);
        expect(meta.primaryLanguage).toBe("PHP");
        expect(meta.frameworks).toContain("Laravel");
    });
    it("detects Rust + Actix project", () => {
        const dir = makeTempDir();
        fs.writeFileSync(path.join(dir, "Cargo.toml"), '[dependencies]\nactix-web = "4"\n');
        const meta = detectProjectMetadata(dir);
        expect(meta.primaryLanguage).toBe("Rust");
        expect(meta.frameworks).toContain("Actix");
    });
    it("returns unknown for empty directory", () => {
        const dir = makeTempDir();
        const meta = detectProjectMetadata(dir);
        expect(meta.primaryLanguage).toBe("unknown");
        expect(meta.primaryFramework).toBe("unknown");
    });
});
