mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-07-30 14:17:39 +00:00
feat(handler): implement default sort configuration for models
* Add SetDefaultSort method to configure default sort order * Implement getDefaultSort method to retrieve configured defaults * Update handleRead to apply default sort when none specified * Add tests for default sort functionality
This commit is contained in:
@@ -41,6 +41,36 @@ func TestSetFallbackHandler(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultSort(t *testing.T) {
|
||||
handler := NewHandler(nil, nil)
|
||||
|
||||
// No default configured yet
|
||||
if got := handler.getDefaultSort("public", "users"); got != nil {
|
||||
t.Errorf("Expected no default sort, got %v", got)
|
||||
}
|
||||
|
||||
// Global default
|
||||
global := []common.SortOption{{Column: "created_at", Direction: "desc"}}
|
||||
handler.SetDefaultSort("", "", global...)
|
||||
|
||||
if got := handler.getDefaultSort("public", "users"); !reflect.DeepEqual(got, global) {
|
||||
t.Errorf("Expected global default sort %v, got %v", global, got)
|
||||
}
|
||||
|
||||
// Per-model default overrides the global default
|
||||
perModel := []common.SortOption{{Column: "name", Direction: "asc"}}
|
||||
handler.SetDefaultSort("public", "users", perModel...)
|
||||
|
||||
if got := handler.getDefaultSort("public", "users"); !reflect.DeepEqual(got, perModel) {
|
||||
t.Errorf("Expected per-model default sort %v, got %v", perModel, got)
|
||||
}
|
||||
|
||||
// Other models still fall back to the global default
|
||||
if got := handler.getDefaultSort("public", "orders"); !reflect.DeepEqual(got, global) {
|
||||
t.Errorf("Expected global default sort %v for unrelated model, got %v", global, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDatabase(t *testing.T) {
|
||||
handler := NewHandler(nil, nil)
|
||||
db := handler.GetDatabase()
|
||||
|
||||
Reference in New Issue
Block a user