-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix batch fetch util for marketplace-v3 (#5904)
--- title: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" --- CORE-680 ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on fixing the batch fetching utility in the `marketplace-v3` and adding tests to ensure its functionality. ### Detailed summary - Fixed the calculation of the end index in the batch fetching logic in `packages/thirdweb/src/extensions/marketplace/utils.ts`. - Added tests for `getAllInBatches` in `packages/thirdweb/src/extensions/marketplace/getAllInBatches.test.ts` to validate handling of multiple and single batches. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
- Loading branch information
1 parent
0fbce06
commit 5e2eec3
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"thirdweb": patch | ||
--- | ||
|
||
Fix batch fetch util for marketplace-v3 |
54 changes: 54 additions & 0 deletions
54
packages/thirdweb/src/extensions/marketplace/getAllInBatches.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { getAllInBatches } from "./utils.js"; | ||
|
||
describe("getAllInBatches", () => { | ||
it("should handle range with multiple batches", async () => { | ||
const mockFnCalls: { start: bigint; end: bigint }[] = []; | ||
const mockFn = async (start: bigint, end: bigint) => { | ||
mockFnCalls.push({ start, end }); | ||
return { start, end }; | ||
}; | ||
|
||
const options = { | ||
start: 1n, | ||
end: 20n, | ||
maxSize: 5n, | ||
}; | ||
|
||
const result = await getAllInBatches(mockFn, options); | ||
|
||
expect(mockFnCalls.length).toEqual(4); | ||
expect(mockFnCalls[0]).toEqual({ start: 1n, end: 5n }); | ||
expect(mockFnCalls[1]).toEqual({ start: 6n, end: 10n }); | ||
expect(mockFnCalls[2]).toEqual({ start: 11n, end: 15n }); | ||
expect(mockFnCalls[3]).toEqual({ start: 16n, end: 19n }); | ||
|
||
expect(result).toEqual([ | ||
{ start: 1n, end: 5n }, | ||
{ start: 6n, end: 10n }, | ||
{ start: 11n, end: 15n }, | ||
{ start: 16n, end: 19n }, | ||
]); | ||
}); | ||
|
||
it("should handle single batch", async () => { | ||
const mockFnCalls: { start: bigint; end: bigint }[] = []; | ||
const mockFn = async (start: bigint, end: bigint) => { | ||
mockFnCalls.push({ start, end }); | ||
return { start, end }; | ||
}; | ||
|
||
const options = { | ||
start: 1n, | ||
end: 4n, | ||
maxSize: 10n, | ||
}; | ||
|
||
const result = await getAllInBatches(mockFn, options); | ||
|
||
expect(mockFnCalls.length).toEqual(1); | ||
expect(mockFnCalls[0]).toEqual({ start: 1n, end: 3n }); | ||
|
||
expect(result).toEqual([{ start: 1n, end: 3n }]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters