We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stakwork Run
package utils import ( "net/http" "net/url" "testing" "github.com/stretchr/testify/assert" ) func TestGetPaginationParams(t *testing.T) { tests := []struct { name string query string expectedOffset int expectedLimit int expectedSortBy string expectedDir string expectedSearch string }{ { name: "Standard Input with All Parameters Present", query: "page=2&limit=10&sortBy=created&direction=asc&search=test", expectedOffset: 10, expectedLimit: 10, expectedSortBy: "created", expectedDir: "asc", expectedSearch: "test", }, { name: "Standard Input with Default Parameters", query: "page=1&limit=5", expectedOffset: 0, expectedLimit: 5, expectedSortBy: "created", expectedDir: "desc", expectedSearch: "", }, { name: "Minimum Values for Page and Limit", query: "page=1&limit=1", expectedOffset: 0, expectedLimit: 1, expectedSortBy: "created", expectedDir: "desc", expectedSearch: "", }, { name: "Zero Values for Page and Limit", query: "page=0&limit=0", expectedOffset: 0, expectedLimit: 1, expectedSortBy: "created", expectedDir: "desc", expectedSearch: "", }, { name: "Negative Values for Page and Limit", query: "page=-1&limit=-10", expectedOffset: 0, expectedLimit: 1, expectedSortBy: "created", expectedDir: "desc", expectedSearch: "", }, { name: "Non-Integer Values for Page and Limit", query: "page=abc&limit=xyz", expectedOffset: 0, expectedLimit: 1, expectedSortBy: "created", expectedDir: "desc", expectedSearch: "", }, { name: "Null Request", query: "", expectedOffset: 0, expectedLimit: 1, expectedSortBy: "created", expectedDir: "desc", expectedSearch: "", }, { name: "Large Values for Page and Limit", query: "page=10000&limit=1000", expectedOffset: 9999000, expectedLimit: 1000, expectedSortBy: "created", expectedDir: "desc", expectedSearch: "", }, { name: "Empty Query Parameters", query: "", expectedOffset: 0, expectedLimit: 1, expectedSortBy: "created", expectedDir: "desc", expectedSearch: "", }, { name: "Only Search Parameter Present", query: "search=example", expectedOffset: 0, expectedLimit: 1, expectedSortBy: "created", expectedDir: "desc", expectedSearch: "example", }, { name: "Invalid Direction Value", query: "direction=upwards", expectedOffset: 0, expectedLimit: 1, expectedSortBy: "created", expectedDir: "desc", expectedSearch: "", }, { name: "Invalid SortBy Value", query: "sortBy=unknown", expectedOffset: 0, expectedLimit: 1, expectedSortBy: "created", expectedDir: "desc", expectedSearch: "", }, { name: "Mixed Valid and Invalid Parameters", query: "page=3&limit=abc&sortBy=unknown&direction=upwards", expectedOffset: 20, expectedLimit: 1, expectedSortBy: "created", expectedDir: "desc", expectedSearch: "", }, { name: "Whitespace in Parameters", query: "page= 2 &limit= 10&sortBy= created &direction= asc ", expectedOffset: 10, expectedLimit: 10, expectedSortBy: "created", expectedDir: "asc", expectedSearch: "", }, { name: "Case Sensitivity in Parameters", query: "sortBy=CREATED&direction=ASC", expectedOffset: 0, expectedLimit: 1, expectedSortBy: "created", expectedDir: "asc", expectedSearch: "", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { req := &http.Request{ URL: &url.URL{ RawQuery: tt.query, }, } offset, limit, sortBy, direction, search := GetPaginationParams(req) assert.Equal(t, tt.expectedOffset, offset) assert.Equal(t, tt.expectedLimit, limit) assert.Equal(t, tt.expectedSortBy, sortBy) assert.Equal(t, tt.expectedDir, direction) assert.Equal(t, tt.expectedSearch, search) }) } }
The text was updated successfully, but these errors were encountered:
elraphty
Successfully merging a pull request may close this issue.
Unit Test Coverage for " GetPaginationParams"
Stakwork Run
Unit Test Code
The text was updated successfully, but these errors were encountered: