mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
feat(api): allow batch status updates
This commit is contained in:
@@ -200,3 +200,44 @@ func TestBatchModels_Delete(t *testing.T) {
|
||||
t.Fatalf("expected meta removed, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBatchBindings_Status(t *testing.T) {
|
||||
h, db := newTestHandler(t)
|
||||
|
||||
b := &model.Binding{
|
||||
Namespace: "ns",
|
||||
PublicModel: "m1",
|
||||
RouteGroup: "default",
|
||||
SelectorType: "exact",
|
||||
SelectorValue: "m1",
|
||||
Status: "active",
|
||||
}
|
||||
if err := db.Create(b).Error; err != nil {
|
||||
t.Fatalf("create binding: %v", err)
|
||||
}
|
||||
|
||||
r := gin.New()
|
||||
r.POST("/admin/bindings/batch", h.BatchBindings)
|
||||
|
||||
payload := map[string]any{
|
||||
"action": "status",
|
||||
"status": "inactive",
|
||||
"ids": []uint{b.ID},
|
||||
}
|
||||
bb, _ := json.Marshal(payload)
|
||||
req := httptest.NewRequest(http.MethodPost, "/admin/bindings/batch", bytes.NewReader(bb))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
rr := httptest.NewRecorder()
|
||||
r.ServeHTTP(rr, req)
|
||||
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Fatalf("expected 200, got %d body=%s", rr.Code, rr.Body.String())
|
||||
}
|
||||
var updated model.Binding
|
||||
if err := db.First(&updated, b.ID).Error; err != nil {
|
||||
t.Fatalf("reload binding: %v", err)
|
||||
}
|
||||
if updated.Status != "inactive" {
|
||||
t.Fatalf("expected status inactive, got %q", updated.Status)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user