fix(pagination): handle out-of-bounds slicing in pagination
Ensure the pagination function correctly handles out-of-bounds indices when slicing items. Update the slice logic to prevent slice bounds errors and add a test case for better coverage of edge cases.
This commit is contained in:
@@ -39,6 +39,16 @@ func TestGetPage(t *testing.T) {
|
||||
EndCursor: ptr("Mg=="),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "first 10",
|
||||
args: args[string]{items: []string{"1", "2", "3"}, first: ptr(10), max: 10, fn: func(s string) string { return s }},
|
||||
wantItems: []string{"1", "2", "3"},
|
||||
wantPageInfo: PageInfo{
|
||||
StartCursor: ptr("MQ=="),
|
||||
HasNextPage: false,
|
||||
EndCursor: ptr("Mw=="),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "after 2",
|
||||
args: args[string]{items: []string{"1", "2", "3", "4"}, first: ptr(2), after: ptr("Mg=="), max: 10, fn: func(s string) string { return s }},
|
||||
|
||||
Reference in New Issue
Block a user