| 1 | import fs from "fs/promises"; |
| 2 | import path from "path"; |
| 3 | |
| 4 | import { |
| 5 | cleanupTestContext, |
| 6 | createTestContext, |
| 7 | runCLI, |
| 8 | } from "../test-helpers/cli-helpers.js"; |
| 9 | import { cleanupMocks } from "../test-helpers/mock-helpers.js"; |
| 10 | |
| 11 | describe("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 | accessToken: "test-token", |
| 33 | user: { id: "test-user", email: "test@example.com" }, |
| 34 | }) |
| 35 | ); |
| 36 | |
| 37 | // Run logout |
| 38 | const result = await runCLI(context, { args: ["logout"] }); |
| 39 | |
| 40 | expect(result.exitCode).toBe(0); |
| 41 | expect(result.stdout).toContain("Successfully logged out"); |
| 42 | |
| 43 | // Check auth file is removed |
| 44 | const authExists = await fs |
| 45 | .access(authPath) |
| 46 | .then(() => true) |
| 47 | .catch(() => false); |
| 48 | expect(authExists).toBe(false); |
| 49 | }); |
| 50 | |
| 51 | it("should handle logout when not logged in", async () => { |
| 52 | const result = await runCLI(context, { args: ["logout"] }); |
| 53 | |
| 54 | expect(result.exitCode).toBe(0); |
| 55 | expect(result.stdout).toContain("No active session found"); |
| 56 | }); |
| 57 | }); |
| 58 | }); |