Skip to content

Commit 7ed0214

Browse files
mixelburgStrift
authored andcommitted
fix(types): make batchStrategy optional for pre-v1.15 server compat
Co-authored feedback from CodeRabbit review: batchStrategy should be optional since pre-v1.15 Meilisearch servers do not return this field.
1 parent 06368df commit 7ed0214

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/types/task-and-batch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export type Batch = {
249249
startedAt: string;
250250
finishedAt: string | null;
251251
/** Explains why the batch was finalized and stopped accepting more tasks. */
252-
batchStrategy: string;
252+
batchStrategy?: string;
253253
};
254254

255255
/**

tests/batch.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
4545
expect(batch.startedAt).toBeDefined();
4646
expect(batch.finishedAt).toBeDefined();
4747
expect(batch.progress).toBeDefined();
48-
expect(typeof batch.batchStrategy).toBe("string");
48+
expect(["string", "undefined"]).toContain(typeof batch.batchStrategy);
4949
});
5050
},
5151
);

tests/utils/assertions/tasks-and-batches.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ export const tasksAndBatchesAssertions = {
5353
},
5454

5555
isBatch(batch: Batch) {
56-
assert.lengthOf(Object.keys(batch), 8);
56+
const keyCount = Object.keys(batch).length;
57+
assert(
58+
keyCount === 7 || keyCount === 8,
59+
`expected batch to have 7 or 8 keys, got ${keyCount}`,
60+
);
5761

5862
const {
5963
uid,
@@ -154,7 +158,10 @@ export const tasksAndBatchesAssertions = {
154158
"expected finishedAt to be null or string",
155159
);
156160

157-
assert.typeOf(batchStrategy, "string");
161+
assert(
162+
batchStrategy === undefined || typeof batchStrategy === "string",
163+
"expected batchStrategy to be undefined or string",
164+
);
158165
},
159166

160167
isTasksOrBatchesResults(value: TasksResults | BatchesResults) {

0 commit comments

Comments
 (0)