continue-custom/extensions/cli/src/e2e/auth.test.ts
Nate be45ab63ca Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e'
git-subtree-dir: extensions/cli
git-subtree-mainline: 1674c2aff1
git-subtree-split: e27a5c87d5
2025-08-20 17:19:56 -07:00

58 lines
1.5 KiB
TypeScript

import fs from "fs/promises";
import path from "path";
import {
cleanupTestContext,
createTestContext,
runCLI,
} from "../test-helpers/cli-helpers.js";
import { cleanupMocks } from "../test-helpers/mock-helpers.js";
describe("E2E: Authentication", () => {
let context: any;
beforeEach(async () => {
context = await createTestContext();
});
afterEach(async () => {
cleanupMocks();
await cleanupTestContext(context);
});
describe("logout command", () => {
it("should remove auth credentials", async () => {
const authPath = path.join(context.testDir, ".continue", "auth.json");
// Create auth file
await fs.mkdir(path.dirname(authPath), { recursive: true });
await fs.writeFile(
authPath,
JSON.stringify({
accessToken: "test-token",
user: { id: "test-user", email: "test@example.com" },
})
);
// Run logout
const result = await runCLI(context, { args: ["logout"] });
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain("Successfully logged out");
// Check auth file is removed
const authExists = await fs
.access(authPath)
.then(() => true)
.catch(() => false);
expect(authExists).toBe(false);
});
it("should handle logout when not logged in", async () => {
const result = await runCLI(context, { args: ["logout"] });
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain("No active session found");
});
});
});