Skip to content

Commit f0d621c

Browse files
committed
fix: update cloud package tests to use named imports for proper mocking
- Changed from namespace imports to named imports in WebAuthService.spec.ts - Updated CloudSettingsService.test.ts mock to use correct module path - Fixed mock URL to match new production URL from config.ts - This resolves the TypeError: vi.mocked(...).mockReturnValue is not a function
1 parent 737e782 commit f0d621c

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

packages/cloud/src/__tests__/CloudSettingsService.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type { OrganizationSettings } from "@roo-code/types"
66

77
// Mock dependencies
88
vi.mock("../RefreshTimer")
9-
vi.mock("../Config", () => ({
10-
getRooCodeApiUrl: vi.fn().mockReturnValue("https://api.example.com"),
9+
vi.mock("../config", () => ({
10+
getRooCodeApiUrl: vi.fn().mockReturnValue("https://app.roocode.com"),
1111
}))
1212

1313
// Mock fetch globally
@@ -338,7 +338,7 @@ describe("CloudSettingsService", () => {
338338
const result = await timerCallback()
339339

340340
expect(result).toBe(true)
341-
expect(fetch).toHaveBeenCalledWith("https://api.example.com/api/organization-settings", {
341+
expect(fetch).toHaveBeenCalledWith("https://app.roocode.com/api/organization-settings", {
342342
headers: {
343343
Authorization: "Bearer valid-token",
344344
},

packages/cloud/src/__tests__/auth/WebAuthService.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import * as vscode from "vscode"
66

77
import { WebAuthService } from "../../auth/WebAuthService"
88
import { RefreshTimer } from "../../RefreshTimer"
9-
import * as Config from "../../config"
10-
import * as utils from "../../utils"
9+
import { getClerkBaseUrl, getRooCodeApiUrl } from "../../config"
10+
import { getUserAgent } from "../../utils"
1111

1212
// Mock external dependencies
1313
vi.mock("../../RefreshTimer")
14-
vi.mock("../../Config")
14+
vi.mock("../../config")
1515
vi.mock("../../utils")
1616
vi.mock("crypto")
1717

@@ -101,11 +101,11 @@ describe("WebAuthService", () => {
101101
MockedRefreshTimer.mockImplementation(() => mockTimer as unknown as RefreshTimer)
102102

103103
// Setup config mocks - use production URL by default to maintain existing test behavior
104-
vi.mocked(Config.getClerkBaseUrl).mockReturnValue("https://clerk.roocode.com")
105-
vi.mocked(Config.getRooCodeApiUrl).mockReturnValue("https://api.test.com")
104+
vi.mocked(getClerkBaseUrl).mockReturnValue("https://clerk.roocode.com")
105+
vi.mocked(getRooCodeApiUrl).mockReturnValue("https://api.test.com")
106106

107107
// Setup utils mock
108-
vi.mocked(utils.getUserAgent).mockReturnValue("Roo-Code 1.0.0")
108+
vi.mocked(getUserAgent).mockReturnValue("Roo-Code 1.0.0")
109109

110110
// Setup crypto mock
111111
vi.mocked(crypto.randomBytes).mockReturnValue(Buffer.from("test-random-bytes") as never)
@@ -977,7 +977,7 @@ describe("WebAuthService", () => {
977977
describe("auth credentials key scoping", () => {
978978
it("should use default key when getClerkBaseUrl returns production URL", async () => {
979979
// Mock getClerkBaseUrl to return production URL
980-
vi.mocked(Config.getClerkBaseUrl).mockReturnValue("https://clerk.roocode.com")
980+
vi.mocked(getClerkBaseUrl).mockReturnValue("https://clerk.roocode.com")
981981

982982
const service = new WebAuthService(mockContext as unknown as vscode.ExtensionContext, mockLog)
983983
const credentials = { clientToken: "test-token", sessionId: "test-session" }
@@ -994,7 +994,7 @@ describe("WebAuthService", () => {
994994
it("should use scoped key when getClerkBaseUrl returns custom URL", async () => {
995995
const customUrl = "https://custom.clerk.com"
996996
// Mock getClerkBaseUrl to return custom URL
997-
vi.mocked(Config.getClerkBaseUrl).mockReturnValue(customUrl)
997+
vi.mocked(getClerkBaseUrl).mockReturnValue(customUrl)
998998

999999
const service = new WebAuthService(mockContext as unknown as vscode.ExtensionContext, mockLog)
10001000
const credentials = { clientToken: "test-token", sessionId: "test-session" }
@@ -1010,7 +1010,7 @@ describe("WebAuthService", () => {
10101010

10111011
it("should load credentials using scoped key", async () => {
10121012
const customUrl = "https://custom.clerk.com"
1013-
vi.mocked(Config.getClerkBaseUrl).mockReturnValue(customUrl)
1013+
vi.mocked(getClerkBaseUrl).mockReturnValue(customUrl)
10141014

10151015
const service = new WebAuthService(mockContext as unknown as vscode.ExtensionContext, mockLog)
10161016
const credentials = { clientToken: "test-token", sessionId: "test-session" }
@@ -1025,7 +1025,7 @@ describe("WebAuthService", () => {
10251025

10261026
it("should clear credentials using scoped key", async () => {
10271027
const customUrl = "https://custom.clerk.com"
1028-
vi.mocked(Config.getClerkBaseUrl).mockReturnValue(customUrl)
1028+
vi.mocked(getClerkBaseUrl).mockReturnValue(customUrl)
10291029

10301030
const service = new WebAuthService(mockContext as unknown as vscode.ExtensionContext, mockLog)
10311031

@@ -1037,7 +1037,7 @@ describe("WebAuthService", () => {
10371037

10381038
it("should listen for changes on scoped key", async () => {
10391039
const customUrl = "https://custom.clerk.com"
1040-
vi.mocked(Config.getClerkBaseUrl).mockReturnValue(customUrl)
1040+
vi.mocked(getClerkBaseUrl).mockReturnValue(customUrl)
10411041

10421042
let onDidChangeCallback: (e: { key: string }) => void
10431043

@@ -1064,7 +1064,7 @@ describe("WebAuthService", () => {
10641064

10651065
it("should not respond to changes on different scoped keys", async () => {
10661066
const customUrl = "https://custom.clerk.com"
1067-
vi.mocked(Config.getClerkBaseUrl).mockReturnValue(customUrl)
1067+
vi.mocked(getClerkBaseUrl).mockReturnValue(customUrl)
10681068

10691069
let onDidChangeCallback: (e: { key: string }) => void
10701070

@@ -1088,7 +1088,7 @@ describe("WebAuthService", () => {
10881088

10891089
it("should not respond to changes on default key when using scoped key", async () => {
10901090
const customUrl = "https://custom.clerk.com"
1091-
vi.mocked(Config.getClerkBaseUrl).mockReturnValue(customUrl)
1091+
vi.mocked(getClerkBaseUrl).mockReturnValue(customUrl)
10921092

10931093
let onDidChangeCallback: (e: { key: string }) => void
10941094

0 commit comments

Comments
 (0)