Skip to content

Commit 0913ca5

Browse files
authored
Merge pull request #13 from htnabe/dev
Fix to count items edited
2 parents 2e87465 + 457bb44 commit 0913ca5

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "algolia-uploader",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "command-line util to upload Algolia source",
55
"type": "module",
66
"exports": {

src/utils/Uploader.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,23 @@ export class Uploader {
4141
const sortedNewObjs = normalizeIndexedItemArray(newObjects);
4242
const operations = this.determineOperations(existingObjects, sortedNewObjs);
4343

44-
if (operations.update.length === 0 && operations.add.length === 0) {
44+
if (
45+
operations.update.length === 0 &&
46+
operations.add.length === 0 &&
47+
operations.delete.length === 0
48+
) {
4549
console.log("No updates needed. All objects are up to date.");
4650
return;
4751
}
4852

4953
// Update Operation
5054
if (operations.update.length > 0) {
51-
const res = await this.client.partialUpdateObjects({
55+
const res: BatchResponse[] = await this.client.partialUpdateObjects({
5256
indexName: this.indexName,
5357
objects: operations.update,
5458
createIfNotExists: true,
5559
});
56-
console.log(`Updated ${res.length} objects`);
60+
console.log(`Updated ${res[0].objectIDs.length} objects`);
5761
}
5862

5963
// Add Operation
@@ -62,7 +66,7 @@ export class Uploader {
6266
indexName: this.indexName,
6367
objects: operations.add,
6468
});
65-
console.log(`Added ${res.length} objects`);
69+
console.log(`Added ${res[0].objectIDs.length} objects`);
6670
}
6771

6872
// Delete Operation
@@ -72,7 +76,7 @@ export class Uploader {
7276
indexName: this.indexName,
7377
objectIDs: targetIds,
7478
});
75-
console.log(`Deleted ${res.length} objects`);
79+
console.log(`Deleted ${res[0].objectIDs.length} objects`);
7680
}
7781
}
7882

test/Uploader.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, test, vi, beforeEach } from "vitest";
2-
import { SearchClient, BrowseResponse, BatchResponse } from "algoliasearch";
2+
import { SearchClient, BrowseResponse } from "algoliasearch";
33
import IndexedItem from "src/types/IndexedItem";
44
import { AlgoliaClientProvider } from "src/utils/AlgoliaClientProvider";
55
import { Uploader } from "src/utils/Uploader";
@@ -19,9 +19,15 @@ class MockAlgoliaClient {
1919
},
2020
);
2121

22-
partialUpdateObjects = vi.fn(async () => Promise.resolve({ length: 2 }));
23-
saveObjects = vi.fn(async () => Promise.resolve({ length: 1 }));
24-
deleteObjects = vi.fn(async () => Promise.resolve([{ length: 1 }]));
22+
partialUpdateObjects = vi.fn(async () =>
23+
Promise.resolve([{ objectIDs: ["prod_001"] }]),
24+
);
25+
saveObjects = vi.fn(async () =>
26+
Promise.resolve([{ objectIDs: ["prod_001"] }]),
27+
);
28+
deleteObjects = vi.fn(async () =>
29+
Promise.resolve([{ objectIDs: ["prod_001"] }]),
30+
);
2531
}
2632

2733
describe("Uploader", () => {

0 commit comments

Comments
 (0)