Skip to content

Commit 0b3a4dd

Browse files
committed
Added test case for updateDocumentsInBatch
1 parent b73df30 commit 0b3a4dd

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/lib/indexes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class Index<T = Record<string, any>> {
330330
const resultArray = []
331331
let batchDocuments = [];
332332
for(let i = 0, n = documents.length; i < n; ++i) {
333-
if(batchDocuments.length == batchSize) {
333+
if(batchDocuments.length === batchSize) {
334334
resultArray.push(await this.addDocuments(batchDocuments, options));
335335
batchDocuments = []
336336
}
@@ -368,7 +368,7 @@ class Index<T = Record<string, any>> {
368368
const resultArray = []
369369
let batchDocuments = [];
370370
for(let i = 0, n = documents.length; i < n; ++i) {
371-
if(batchDocuments.length == batchSize) {
371+
if(batchDocuments.length === batchSize) {
372372
resultArray.push(await this.updateDocuments(batchDocuments, options));
373373
batchDocuments = []
374374
}

tests/documents_tests.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,33 @@ describe.each([
226226
})
227227
})
228228

229+
test(`${permission} key: Update document from index that has a primary key in batch`, async () => {
230+
const id = 456
231+
const title = 'The Little Prince'
232+
const comment = 'Updated comment'
233+
234+
const updateIds = await client
235+
.index(indexPk.uid)
236+
.updateDocumentsInBatch([{ id, title }, {id, comment}], 1)
237+
.then((response: EnqueuedUpdate[]) => {
238+
expect(response).toHaveLength(2)
239+
expect(response[0]).toHaveProperty('updateId', expect.any(Number))
240+
const tempIds:number[] = [];
241+
response.forEach((entry) => tempIds.push(entry.updateId))
242+
return tempIds
243+
})
244+
await client.index(indexPk.uid).waitForPendingUpdate(updateIds[0])
245+
await client.index(indexPk.uid).waitForPendingUpdate(updateIds[1])
246+
await client
247+
.index(indexPk.uid)
248+
.getDocument(id)
249+
.then((response) => {
250+
expect(response).toHaveProperty('id', id)
251+
expect(response).toHaveProperty('title', title)
252+
expect(response).toHaveProperty('comment', comment)
253+
})
254+
})
255+
229256
test(`${permission} key: Add document with update documents function from index that has NO primary key`, async () => {
230257
const { updateId: addDocUpdate } = await client
231258
.index(indexNoPk.uid)

0 commit comments

Comments
 (0)