Files
Mazyar 843e1508df
continuous-integration/drone/push Build is passing
Enhance tender search functionality with pagination and filtering improvements
- Updated the tender search handler to include a new `include_total` query parameter, allowing clients to request total count and pagination metadata for search results.
- Refactored the `tenderSearchListProjection` to exclude heavy fields from the list response, optimizing data retrieval.
- Modified the `buildSearchFilter` method to utilize the `processing_metadata.documents_scraped` flag for filtering, improving search accuracy.
- Added unit tests for the new pagination features and search filter logic, ensuring robust validation of the search functionality.

This update significantly enhances the tender search experience by providing more flexible pagination options and improving the efficiency of data handling.
2026-07-10 16:23:46 +03:30

63 lines
1.6 KiB
Go

package response
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo/v4"
)
func TestNewPaginationDefaults(t *testing.T) {
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/?limit=10&offset=0&sort_by=created_at&sort_order=desc", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
p, err := NewPagination(c)
if err != nil {
t.Fatalf("NewPagination: %v", err)
}
if p.Limit != 10 || p.Offset != 0 || p.Cursor != "" || p.IncludeTotal {
t.Fatalf("unexpected pagination: %+v", p)
}
}
func TestNewPaginationIncludeTotal(t *testing.T) {
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/?include_total=true", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
p, err := NewPagination(c)
if err != nil {
t.Fatalf("NewPagination: %v", err)
}
if !p.IncludeTotal {
t.Fatal("expected include_total=true")
}
}
func TestNewPaginationCursorConflict(t *testing.T) {
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/?limit=10&offset=5&cursor=abc", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
_, err := NewPagination(c)
if !IsPaginationError(err) {
t.Fatalf("expected pagination conflict, got %v", err)
}
}
func TestListMetaOmitsNextCursorOnLastPage(t *testing.T) {
p := &Pagination{Limit: 10, Offset: 0}
meta := p.ListMeta(15, "should-not-appear", false, 0)
if meta.HasMore || meta.NextCursor != "" {
t.Fatalf("expected no next cursor on last page: %+v", meta)
}
if meta.Page != 1 || meta.Pages != 2 || meta.Total != 15 {
t.Fatalf("unexpected page meta: %+v", meta)
}
}