import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";

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

import { createSqliteRepository } from "../sqlite-repository";

describe("createSqliteRepository", () => {
  let tempDir: string;
  let dbPath: string;

  beforeEach(() => {
    tempDir = mkdtempSync(join(tmpdir(), "geo-repository-"));
    dbPath = join(tempDir, "app.db");
  });

  afterEach(() => {
    rmSync(tempDir, { recursive: true, force: true });
  });

  test("creates and reads an article job through the async repository interface", async () => {
    const repository = createSqliteRepository(dbPath);

    const job = await repository.createArticleJob({
      source_title: "Title",
      source_body: "Body",
      image_inputs: [],
      publish_platform: "official_site",
      user_instructions: "",
    });

    await expect(repository.getArticleJob(job.id)).resolves.toMatchObject({
      id: job.id,
      source_title: "Title",
      export_paths: {},
    });
  });
});
