Skip to content

Commit

Permalink
test: query divider function
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinWoetzel committed Mar 28, 2024
1 parent c4d8927 commit be3892d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/contracts/services/batchQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
batchQuery$,
batchQuery,
batchQuerySingleBatch$,
divideSingleBatchIntoArrayOfMultipleBatches,
} from './batchQuery';

const sendSecretClientContractQuery$ = vi.hoisted(() => vi.fn());
Expand Down Expand Up @@ -157,3 +158,44 @@ test('it can call the multi-batch query service for multiple batches', async ()
expect(msgBatchQuery).toHaveBeenNthCalledWith(4, [input.queries[1]]);
expect(response).toStrictEqual(combinedOutput);
});

test('it can divide a batch of queries into an array of multiple batches', () => {
const input1 = [
1 as unknown as BatchQueryParams,
2 as unknown as BatchQueryParams,
3 as unknown as BatchQueryParams,
4 as unknown as BatchQueryParams,
5 as unknown as BatchQueryParams,
6 as unknown as BatchQueryParams,
7 as unknown as BatchQueryParams,
8 as unknown as BatchQueryParams,
];

expect(divideSingleBatchIntoArrayOfMultipleBatches(input1, 2)).toStrictEqual([
[1, 2],
[3, 4],
[5, 6],
[7, 8],
]);

expect(divideSingleBatchIntoArrayOfMultipleBatches(input1, 3)).toStrictEqual([
[1, 2, 3],
[4, 5, 6],
[7, 8],
]);

expect(divideSingleBatchIntoArrayOfMultipleBatches(input1, 1)).toStrictEqual([
[1],
[2],
[3],
[4],
[5],
[6],
[7],
[8],
]);

expect(divideSingleBatchIntoArrayOfMultipleBatches(input1, 10)).toStrictEqual([
[1, 2, 3, 4, 5, 6, 7, 8],
]);
});
1 change: 1 addition & 0 deletions src/contracts/services/batchQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,5 @@ export {
batchQuery$,
batchQuery,
batchQuerySingleBatch$,
divideSingleBatchIntoArrayOfMultipleBatches,
};

0 comments on commit be3892d

Please sign in to comment.