--- Cursor tests ---
(t *testing.T)
| 821 | // --- Cursor tests --- |
| 822 | |
| 823 | func Test_PaginateWithCursor(t *testing.T) { |
| 824 | t.Parallel() |
| 825 | app := fiber.New() |
| 826 | app.Use(New(Config{ |
| 827 | DefaultSort: "id", |
| 828 | })) |
| 829 | |
| 830 | app.Get("/", func(c fiber.Ctx) error { |
| 831 | pageInfo, ok := FromContext(c) |
| 832 | if !ok { |
| 833 | return fiber.ErrBadRequest |
| 834 | } |
| 835 | return c.JSON(cursorResponse{ |
| 836 | Cursor: pageInfo.Cursor, |
| 837 | Limit: pageInfo.Limit, |
| 838 | Sort: pageInfo.Sort, |
| 839 | }) |
| 840 | }) |
| 841 | |
| 842 | cursorJSON := `{"id":42}` |
| 843 | cursor := base64.RawURLEncoding.EncodeToString([]byte(cursorJSON)) |
| 844 | |
| 845 | resp, err := app.Test(httptest.NewRequest(http.MethodGet, "/?cursor="+cursor+"&limit=20", http.NoBody)) |
| 846 | require.NoError(t, err) |
| 847 | defer resp.Body.Close() //nolint:errcheck // close error not relevant in tests |
| 848 | require.Equal(t, 200, resp.StatusCode) |
| 849 | |
| 850 | var result cursorResponse |
| 851 | require.NoError(t, json.NewDecoder(resp.Body).Decode(&result)) |
| 852 | require.Equal(t, cursor, result.Cursor) |
| 853 | require.Equal(t, 20, result.Limit) |
| 854 | } |
| 855 | |
| 856 | func Test_PaginateCursorPriorityOverPage(t *testing.T) { |
| 857 | t.Parallel() |