Skip to content

Commit 6d80390

Browse files
committed
test: add getCollection mocks to upsertPoints and search tests
Fixed 12 more test failures by adding missing getCollection mocks: upsertPoints tests (5 fixed): - should correctly call qdrantClient.upsert with processed points - should handle points without filePath in payload - should handle empty input arrays - should correctly process pathSegments for nested file paths - should handle error scenarios when qdrantClient.upsert fails search tests (7 fixed): - should correctly call qdrantClient.query and transform results - should apply filePathPrefix filter correctly - should use custom minScore when provided - should use custom maxResults when provided - should filter out results with invalid payloads - should filter out results with null or undefined payloads - should handle scenarios where no results are found All these methods now call getCollectionInfo() internally which requires getCollection() to be mocked. Remaining: 10 initialize/collectionExists tests need complex mock sequences
1 parent ad01b30 commit 6d80390

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/services/code-index/vector-store/__tests__/qdrant-client.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,7 @@ describe("QdrantVectorStore", () => {
10711071
},
10721072
]
10731073

1074+
mockQdrantClientInstance.getCollection.mockResolvedValue({ vectors_count: 100 })
10741075
mockQdrantClientInstance.upsert.mockResolvedValue({} as any)
10751076

10761077
await vectorStore.upsertPoints(mockPoints)
@@ -1126,6 +1127,7 @@ describe("QdrantVectorStore", () => {
11261127
},
11271128
]
11281129

1130+
mockQdrantClientInstance.getCollection.mockResolvedValue({ vectors_count: 100 })
11291131
mockQdrantClientInstance.upsert.mockResolvedValue({} as any)
11301132

11311133
await vectorStore.upsertPoints(mockPoints)
@@ -1147,6 +1149,7 @@ describe("QdrantVectorStore", () => {
11471149
})
11481150

11491151
it("should handle empty input arrays", async () => {
1152+
mockQdrantClientInstance.getCollection.mockResolvedValue({ vectors_count: 100 })
11501153
mockQdrantClientInstance.upsert.mockResolvedValue({} as any)
11511154

11521155
await vectorStore.upsertPoints([])
@@ -1171,6 +1174,7 @@ describe("QdrantVectorStore", () => {
11711174
},
11721175
]
11731176

1177+
mockQdrantClientInstance.getCollection.mockResolvedValue({ vectors_count: 100 })
11741178
mockQdrantClientInstance.upsert.mockResolvedValue({} as any)
11751179

11761180
await vectorStore.upsertPoints(mockPoints)
@@ -1214,6 +1218,7 @@ describe("QdrantVectorStore", () => {
12141218
]
12151219

12161220
const upsertError = new Error("Upsert failed")
1221+
mockQdrantClientInstance.getCollection.mockResolvedValue({ vectors_count: 100 })
12171222
mockQdrantClientInstance.upsert.mockRejectedValue(upsertError)
12181223
vitest.spyOn(console, "error").mockImplementation(() => {})
12191224

@@ -1255,6 +1260,7 @@ describe("QdrantVectorStore", () => {
12551260
],
12561261
}
12571262

1263+
mockQdrantClientInstance.getCollection.mockResolvedValue({ vectors_count: 100 })
12581264
mockQdrantClientInstance.query.mockResolvedValue(mockQdrantResults)
12591265

12601266
const results = await vectorStore.search(queryVector)
@@ -1296,6 +1302,7 @@ describe("QdrantVectorStore", () => {
12961302
],
12971303
}
12981304

1305+
mockQdrantClientInstance.getCollection.mockResolvedValue({ vectors_count: 100 })
12991306
mockQdrantClientInstance.query.mockResolvedValue(mockQdrantResults)
13001307

13011308
const results = await vectorStore.search(queryVector, directoryPrefix)
@@ -1333,6 +1340,7 @@ describe("QdrantVectorStore", () => {
13331340
const customMinScore = 0.8
13341341
const mockQdrantResults = { points: [] }
13351342

1343+
mockQdrantClientInstance.getCollection.mockResolvedValue({ vectors_count: 100 })
13361344
mockQdrantClientInstance.query.mockResolvedValue(mockQdrantResults)
13371345

13381346
await vectorStore.search(queryVector, undefined, customMinScore)
@@ -1357,6 +1365,7 @@ describe("QdrantVectorStore", () => {
13571365
const customMaxResults = 100
13581366
const mockQdrantResults = { points: [] }
13591367

1368+
mockQdrantClientInstance.getCollection.mockResolvedValue({ vectors_count: 100 })
13601369
mockQdrantClientInstance.query.mockResolvedValue(mockQdrantResults)
13611370

13621371
await vectorStore.search(queryVector, undefined, undefined, customMaxResults)
@@ -1411,6 +1420,7 @@ describe("QdrantVectorStore", () => {
14111420
],
14121421
}
14131422

1423+
mockQdrantClientInstance.getCollection.mockResolvedValue({ vectors_count: 100 })
14141424
mockQdrantClientInstance.query.mockResolvedValue(mockQdrantResults)
14151425

14161426
const results = await vectorStore.search(queryVector)
@@ -1458,6 +1468,7 @@ describe("QdrantVectorStore", () => {
14581468
],
14591469
}
14601470

1471+
mockQdrantClientInstance.getCollection.mockResolvedValue({ vectors_count: 100 })
14611472
mockQdrantClientInstance.query.mockResolvedValue(mockQdrantResults)
14621473

14631474
const results = await vectorStore.search(queryVector)
@@ -1472,6 +1483,7 @@ describe("QdrantVectorStore", () => {
14721483
const queryVector = [0.1, 0.2, 0.3]
14731484
const mockQdrantResults = { points: [] }
14741485

1486+
mockQdrantClientInstance.getCollection.mockResolvedValue({ vectors_count: 100 })
14751487
mockQdrantClientInstance.query.mockResolvedValue(mockQdrantResults)
14761488

14771489
const results = await vectorStore.search(queryVector)

0 commit comments

Comments
 (0)