Skip to content

Commit f3b3058

Browse files
authored
Merge pull request #1397 from RooVetGit/fix_context_proxy_tests
fix test
2 parents e1fb929 + e0c267d commit f3b3058

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/core/webview/__tests__/ClineProvider.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ jest.mock("../../contextProxy", () => {
3737
saveChanges: jest.fn().mockResolvedValue(undefined),
3838
dispose: jest.fn().mockResolvedValue(undefined),
3939
hasPendingChanges: jest.fn().mockReturnValue(false),
40+
setValue: jest.fn().mockImplementation((key, value) => {
41+
if (key.startsWith("apiKey") || key.startsWith("openAiApiKey")) {
42+
return context.secrets.store(key, value)
43+
}
44+
return context.globalState.update(key, value)
45+
}),
46+
setValues: jest.fn().mockImplementation((values) => {
47+
const promises = Object.entries(values).map(([key, value]) => context.globalState.update(key, value))
48+
return Promise.all(promises)
49+
}),
4050
})),
4151
}
4252
})
@@ -267,6 +277,8 @@ describe("ClineProvider", () => {
267277
let mockContextProxy: {
268278
updateGlobalState: jest.Mock
269279
getGlobalState: jest.Mock
280+
setValue: jest.Mock
281+
setValues: jest.Mock
270282
storeSecret: jest.Mock
271283
dispose: jest.Mock
272284
}
@@ -1536,14 +1548,19 @@ describe("ContextProxy integration", () => {
15361548
let mockContext: vscode.ExtensionContext
15371549
let mockOutputChannel: vscode.OutputChannel
15381550
let mockContextProxy: any
1551+
let mockGlobalStateUpdate: jest.Mock
15391552

15401553
beforeEach(() => {
15411554
// Reset mocks
15421555
jest.clearAllMocks()
15431556

15441557
// Setup basic mocks
15451558
mockContext = {
1546-
globalState: { get: jest.fn(), update: jest.fn(), keys: jest.fn().mockReturnValue([]) },
1559+
globalState: {
1560+
get: jest.fn(),
1561+
update: jest.fn(),
1562+
keys: jest.fn().mockReturnValue([]),
1563+
},
15471564
secrets: { get: jest.fn(), store: jest.fn(), delete: jest.fn() },
15481565
extensionUri: {} as vscode.Uri,
15491566
globalStorageUri: { fsPath: "/test/path" },
@@ -1555,6 +1572,8 @@ describe("ContextProxy integration", () => {
15551572

15561573
// @ts-ignore - accessing private property for testing
15571574
mockContextProxy = provider.contextProxy
1575+
1576+
mockGlobalStateUpdate = mockContext.globalState.update as jest.Mock
15581577
})
15591578

15601579
test("updateGlobalState uses contextProxy", async () => {
@@ -1579,5 +1598,7 @@ describe("ContextProxy integration", () => {
15791598
expect(mockContextProxy.getGlobalState).toBeDefined()
15801599
expect(mockContextProxy.updateGlobalState).toBeDefined()
15811600
expect(mockContextProxy.storeSecret).toBeDefined()
1601+
expect(mockContextProxy.setValue).toBeDefined()
1602+
expect(mockContextProxy.setValues).toBeDefined()
15821603
})
15831604
})

0 commit comments

Comments
 (0)