add qs joins

This commit is contained in:
Aneurin Barker Snook
2023-10-16 17:21:28 +01:00
parent d51c1846ff
commit d94f155714
4 changed files with 175 additions and 0 deletions
+28
View File
@@ -44,6 +44,19 @@ func TestReadPage(t *testing.T) {
},
},
},
{
Input: "limit=10&page=2&filter=title eq Spaghetti&sort=serves desc&join=author",
Output: &Page{
Pagination: &Pagination{Limit: 10, Offset: 10, Page: 2},
Filters: []Filter{
{Field: "title", Operator: "eq", Value: "Spaghetti"},
},
Sorts: []Sort{
{Field: "serves", Direction: "desc"},
},
Joins: Joins{"author": true},
},
},
}
for n, tc := range testCases {
@@ -103,5 +116,20 @@ func TestReadPage(t *testing.T) {
t.Errorf("Expected %+v for sort %d, got %+v", sort, i, page.Sorts[i])
}
}
// Compare joins (see join_test.go)
if tc.Output.Joins == nil && page.Joins != nil {
t.Error("Expected nil sorts")
}
if len(page.Joins) != len(tc.Output.Joins) {
t.Errorf("Expected %d joins, got %d", len(tc.Output.Joins), len(page.Joins))
}
for name, join := range tc.Output.Joins {
if join != page.Joins[name] {
t.Errorf("Expected %t for join %s, got %t", join, name, page.Joins[name])
}
}
}
}