Skip to content

Commit eb182d0

Browse files
committed
refactor(tests): Update migrateSettings tests to use ContextProxy
1 parent b4a8a45 commit eb182d0

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/__tests__/migrateSettings.spec.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as fs from "fs/promises"
44
import { fileExistsAtPath } from "../utils/fs"
55
import { GlobalFileNames } from "../shared/globalFileNames"
66
import { migrateSettings } from "../utils/migrateSettings"
7+
import type { ContextProxy } from "../core/config/ContextProxy"
78

89
// Mock dependencies
910
vitest.mock("vscode")
@@ -20,6 +21,7 @@ vitest.mock("../utils/fs")
2021
describe("Settings Migration", () => {
2122
let mockContext: vscode.ExtensionContext
2223
let mockOutputChannel: vscode.OutputChannel
24+
let mockContextProxy: ContextProxy
2325
const mockStoragePath = "/mock/storage"
2426
const mockSettingsDir = path.join(mockStoragePath, "settings")
2527

@@ -48,8 +50,18 @@ describe("Settings Migration", () => {
4850
// Mock extension context
4951
mockContext = {
5052
globalStorageUri: { fsPath: mockStoragePath },
53+
globalState: {
54+
get: vitest.fn().mockReturnValue(undefined),
55+
update: vitest.fn().mockResolvedValue(undefined),
56+
},
5157
} as unknown as vscode.ExtensionContext
5258

59+
// Mock ContextProxy
60+
mockContextProxy = {
61+
getWorkspaceSettings: vitest.fn().mockReturnValue({ taskHistory: [] }),
62+
updateWorkspaceState: vitest.fn().mockResolvedValue(undefined),
63+
} as unknown as ContextProxy
64+
5365
// Set global outputChannel for all tests
5466
;(global as any).outputChannel = mockOutputChannel
5567
})
@@ -69,7 +81,7 @@ describe("Settings Migration", () => {
6981
})
7082

7183
// Run the migration
72-
await migrateSettings(mockContext, mockOutputChannel)
84+
await migrateSettings(mockContext, mockOutputChannel, mockContextProxy)
7385

7486
// Verify expected rename call - cline_custom_modes.json should be renamed to custom_modes.json
7587
expect(mockRename).toHaveBeenCalledWith(legacyClineCustomModesPath, legacyCustomModesJson)
@@ -92,7 +104,7 @@ describe("Settings Migration", () => {
92104
})
93105

94106
// Run the migration
95-
await migrateSettings(mockContext, mockOutputChannel)
107+
await migrateSettings(mockContext, mockOutputChannel, mockContextProxy)
96108

97109
// Verify expected rename call
98110
expect(mockRename).toHaveBeenCalledWith(legacyMcpSettingsPath, newMcpSettingsPath)
@@ -115,7 +127,7 @@ describe("Settings Migration", () => {
115127
return false
116128
})
117129

118-
await migrateSettings(mockContext, mockOutputChannel)
130+
await migrateSettings(mockContext, mockOutputChannel, mockContextProxy)
119131

120132
// Verify rename was not called since destination files exist
121133
expect(mockRename).not.toHaveBeenCalled()
@@ -128,7 +140,7 @@ describe("Settings Migration", () => {
128140
// Mock file existence to throw error
129141
vitest.mocked(fileExistsAtPath).mockRejectedValue(new Error("Test error"))
130142

131-
await migrateSettings(mockContext, mockOutputChannel)
143+
await migrateSettings(mockContext, mockOutputChannel, mockContextProxy)
132144

133145
// Verify error was logged
134146
expect(mockOutputChannel.appendLine).toHaveBeenCalledWith(
@@ -163,7 +175,7 @@ describe("Settings Migration", () => {
163175
return false
164176
})
165177

166-
await migrateSettings(mockContext, mockOutputChannel)
178+
await migrateSettings(mockContext, mockOutputChannel, mockContextProxy)
167179

168180
// Verify file operations
169181
expect(mockWrite).toHaveBeenCalledWith(newCustomModesYaml, expect.any(String), "utf-8")
@@ -201,7 +213,7 @@ describe("Settings Migration", () => {
201213
return false
202214
})
203215

204-
await migrateSettings(mockContext, mockOutputChannel)
216+
await migrateSettings(mockContext, mockOutputChannel, mockContextProxy)
205217

206218
// Verify error was logged
207219
expect(mockOutputChannel.appendLine).toHaveBeenCalledWith(
@@ -239,7 +251,7 @@ describe("Settings Migration", () => {
239251
return false
240252
})
241253

242-
await migrateSettings(mockContext, mockOutputChannel)
254+
await migrateSettings(mockContext, mockOutputChannel, mockContextProxy)
243255

244256
// Verify skip message was logged
245257
expect(mockOutputChannel.appendLine).toHaveBeenCalledWith(

0 commit comments

Comments
 (0)