Elffuss BraidHub

kikocis/continue public

main · 1.9 KiBRawPermalink
1import fs from "fs/promises";
2import path from "path";
3
4import {
5 cleanupTestContext,
6 createTestContext,
7 runCLI,
8} from "../test-helpers/cli-helpers.js";
9import { cleanupMocks } from "../test-helpers/mock-helpers.js";
10
11describe("E2E: Authentication", () => {
12 let context: any;
13
14 beforeEach(async () => {
15 context = await createTestContext();
16 });
17
18 afterEach(async () => {
19 cleanupMocks();
20 await cleanupTestContext(context);
21 });
22
23 describe("logout command", () => {
24 it("should remove auth credentials", async () => {
25 const authPath = path.join(context.testDir, ".continue", "auth.json");
26
27 // Create auth file
28 await fs.mkdir(path.dirname(authPath), { recursive: true });
29 await fs.writeFile(
30 authPath,
31 JSON.stringify({
32 userId: "test-user",
33 userEmail: "test@example.com",
34 accessToken: "test-token",
35 refreshToken: "test-refresh-token",
36 expiresAt: Date.now() + 3600000,
37 organizationId: null,
38 }),
39 );
40
41 // Run logout
42 const result = await runCLI(context, {
43 args: ["logout"],
44 env: {
45 HOME: context.testDir,
46 CONTINUE_GLOBAL_DIR: path.join(context.testDir, ".continue"),
47 },
48 });
49
50 expect(result.exitCode).toBe(0);
51 expect(result.stdout).toContain("Successfully logged out");
52
53 // Check auth file is removed
54 const authExists = await fs
55 .access(authPath)
56 .then(() => true)
57 .catch(() => false);
58 expect(authExists).toBe(false);
59 });
60
61 it("should handle logout when not logged in", async () => {
62 const result = await runCLI(context, {
63 args: ["logout"],
64 env: {
65 HOME: context.testDir,
66 CONTINUE_GLOBAL_DIR: path.join(context.testDir, ".continue"),
67 },
68 });
69
70 expect(result.exitCode).toBe(0);
71 expect(result.stdout).toContain("No active session found");
72 });
73 });
74});