-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathauth-commands.test.ts
More file actions
76 lines (60 loc) · 2.91 KB
/
Copy pathauth-commands.test.ts
File metadata and controls
76 lines (60 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
vi.mock("@/lib/storage/index.js", () => ({
loadToken: vi.fn(),
loadCredentials: vi.fn(),
getCredentialsPath: vi.fn(() => "/tmp/roo/cli-credentials.json"),
hasToken: vi.fn(),
clearToken: vi.fn(),
}))
vi.mock("@/lib/auth/index.js", () => ({
isTokenExpired: vi.fn(),
isTokenValid: vi.fn(),
getTokenExpirationDate: vi.fn(),
}))
import { status } from "../status.js"
import { logout } from "../logout.js"
import { loadToken, loadCredentials, getCredentialsPath, hasToken, clearToken } from "@/lib/storage/index.js"
import { isTokenExpired, isTokenValid, getTokenExpirationDate } from "@/lib/auth/index.js"
describe("auth commands", () => {
beforeEach(() => {
vi.clearAllMocks()
})
it("reports missing Roo auth tokens as normal for standard CLI usage", async () => {
vi.mocked(loadToken).mockResolvedValue(null)
const consoleLog = vi.spyOn(console, "log").mockImplementation(() => {})
const result = await status()
expect(result).toEqual({ authenticated: false })
expect(consoleLog.mock.calls.flat().join("\n")).toContain("Normal CLI usage does not require login.")
expect(consoleLog.mock.calls.flat().join("\n")).toContain("Roo Code Router has been removed")
})
it("reports optional Roo auth token details when available", async () => {
const token = "header.payload.signature"
const expiresAt = new Date("2026-05-01T00:00:00.000Z")
vi.mocked(loadToken).mockResolvedValue(token)
vi.mocked(loadCredentials).mockResolvedValue({ token, createdAt: "2026-04-01T00:00:00.000Z" })
vi.mocked(isTokenValid).mockReturnValue(true)
vi.mocked(isTokenExpired).mockReturnValue(false)
vi.mocked(getTokenExpirationDate).mockReturnValue(expiresAt)
vi.mocked(getCredentialsPath).mockReturnValue("/tmp/roo/cli-credentials.json")
const consoleLog = vi.spyOn(console, "log").mockImplementation(() => {})
const result = await status({ verbose: true })
expect(result.authenticated).toBe(true)
expect(consoleLog.mock.calls.flat().join("\n")).toContain("Legacy Roo auth token still stored")
expect(consoleLog.mock.calls.flat().join("\n")).toContain("/tmp/roo/cli-credentials.json")
})
it("removes stored Roo auth tokens", async () => {
vi.mocked(hasToken).mockResolvedValue(true)
const consoleLog = vi.spyOn(console, "log").mockImplementation(() => {})
const result = await logout()
expect(result).toEqual({ success: true, wasLoggedIn: true })
expect(clearToken).toHaveBeenCalledTimes(1)
expect(consoleLog.mock.calls.flat().join("\n")).toContain("Removed stored legacy Roo auth token")
})
it("treats missing Roo auth tokens as already logged out", async () => {
vi.mocked(hasToken).mockResolvedValue(false)
const consoleLog = vi.spyOn(console, "log").mockImplementation(() => {})
const result = await logout()
expect(result).toEqual({ success: true, wasLoggedIn: false })
expect(clearToken).not.toHaveBeenCalled()
expect(consoleLog.mock.calls.flat().join("\n")).toContain("No legacy Roo auth token stored.")
})
})