|
1 | 1 | import { describe, test, expect } from "bun:test"; |
2 | | -import { resolve } from "path"; |
| 2 | +import { mkdtempSync, readFileSync, rmSync } from "fs"; |
| 3 | +import { tmpdir } from "os"; |
| 4 | +import { join, resolve } from "path"; |
3 | 5 |
|
4 | 6 | import * as util from "../lib/util"; |
5 | 7 | import * as pkce from "../lib/pkce"; |
@@ -212,6 +214,33 @@ describe("Auth callback server", () => { |
212 | 214 | }); |
213 | 215 |
|
214 | 216 | describe("CLI auth commands", () => { |
| 217 | + test("cli: login --help shows all options", () => { |
| 218 | + const r = runCli(["login", "--help"]); |
| 219 | + expect(r.status).toBe(0); |
| 220 | + expect(r.stdout).toMatch(/--set-key/); |
| 221 | + expect(r.stdout).toMatch(/--debug/); |
| 222 | + }); |
| 223 | + |
| 224 | + test("cli: login --set-key aliases auth login", () => { |
| 225 | + const home = mkdtempSync(join(tmpdir(), "postgresai-login-")); |
| 226 | + |
| 227 | + try { |
| 228 | + const r = runCli(["login", "--set-key", "test-token"], { |
| 229 | + HOME: home, |
| 230 | + XDG_CONFIG_HOME: join(home, ".config"), |
| 231 | + }); |
| 232 | + expect(r.status).toBe(0); |
| 233 | + expect(r.stdout).toMatch(/API key saved/); |
| 234 | + |
| 235 | + const saved = JSON.parse( |
| 236 | + readFileSync(join(home, ".config", "postgresai", "config.json"), "utf8") |
| 237 | + ); |
| 238 | + expect(saved.apiKey).toBe("test-token"); |
| 239 | + } finally { |
| 240 | + rmSync(home, { recursive: true, force: true }); |
| 241 | + } |
| 242 | + }); |
| 243 | + |
215 | 244 | test("cli: auth login --help shows all options", () => { |
216 | 245 | const r = runCli(["auth", "login", "--help"]); |
217 | 246 | expect(r.status).toBe(0); |
|
0 commit comments