import { describe, expect, test } from "bun:test"
import path from "path"
import { Flag } from "@saeeol/core/flag/flag" 
import { Global } from "@saeeol/core/global"
import { InstallationChannel } from "@saeeol/core/installation/version"
import { Database } from "@/storage/db"

describe("Database.Path", () => {
  test("returns database path for the current channel", () => {
    if (Flag.SAEEOL_DB) {
      const expected =
        Flag.SAEEOL_DB === ":memory:" || path.isAbsolute(Flag.SAEEOL_DB)
          ? Flag.SAEEOL_DB
          : path.join(Global.Path.data, Flag.SAEEOL_DB)
      expect(Database.Path).toBe(expected)
      return
    }
    const expected = ["latest", "beta"].includes(InstallationChannel)
      ? path.join(Global.Path.data, "saeeol.db")
      : path.join(Global.Path.data, `saeeol-${InstallationChannel.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`)
    expect(Database.getChannelPath()).toBe(expected)
  })
})
