Files
cli/tests/client.test.ts
Mauricio Siu c073a037b1 feat: integrate Vitest for testing and update workflows
- Added Vitest as a testing framework in package.json and configured test scripts.
- Created new test files for CLI and client functionalities, ensuring comprehensive coverage.
- Updated GitHub Actions workflows to include testing steps and streamlined release process.
- Removed the deprecated onRelease workflow to consolidate CI/CD processes.
2026-04-15 21:00:48 -06:00

57 lines
1.7 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
describe("readAuthConfig", () => {
const originalEnv = { ...process.env };
beforeEach(() => {
delete process.env.DOKPLOY_URL;
delete process.env.DOKPLOY_API_KEY;
delete process.env.DOKPLOY_AUTH_TOKEN;
});
afterEach(() => {
process.env = { ...originalEnv };
vi.restoreAllMocks();
});
it("should read from DOKPLOY_API_KEY env var", async () => {
process.env.DOKPLOY_URL = "https://test.dokploy.com";
process.env.DOKPLOY_API_KEY = "test-key-123";
const { readAuthConfig } = await import("../src/client.js");
const config = readAuthConfig();
expect(config.url).toBe("https://test.dokploy.com");
expect(config.token).toBe("test-key-123");
});
it("should read from DOKPLOY_AUTH_TOKEN env var as fallback", async () => {
process.env.DOKPLOY_URL = "https://test.dokploy.com";
process.env.DOKPLOY_AUTH_TOKEN = "auth-token-456";
const { readAuthConfig } = await import("../src/client.js");
const config = readAuthConfig();
expect(config.url).toBe("https://test.dokploy.com");
expect(config.token).toBe("auth-token-456");
});
it("should prefer DOKPLOY_API_KEY over DOKPLOY_AUTH_TOKEN", async () => {
process.env.DOKPLOY_URL = "https://test.dokploy.com";
process.env.DOKPLOY_API_KEY = "api-key";
process.env.DOKPLOY_AUTH_TOKEN = "auth-token";
const { readAuthConfig } = await import("../src/client.js");
const config = readAuthConfig();
expect(config.token).toBe("api-key");
});
});
describe("saveAuthConfig", () => {
it("should write config with correct structure", async () => {
const { saveAuthConfig } = await import("../src/client.js");
expect(typeof saveAuthConfig).toBe("function");
});
});