feat(ECR-009): Ops-D order filters, plan display prices, refund status
LOOP-RUN-002 sample: admin order multi-filter, membership display price catalog, read-only refund_status. No real payment or RBAC. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOpsCommercePhaseD(t *testing.T) {
|
||||
r, _ := setupAPI(t)
|
||||
|
||||
loginEnv, code := doAdminJSON(t, r, http.MethodPost, "/api/v1/admin/auth/login", map[string]string{
|
||||
"username": "admin", "password": "change-me",
|
||||
}, "")
|
||||
if code != http.StatusOK {
|
||||
t.Fatalf("login http=%d", code)
|
||||
}
|
||||
var login struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
_ = json.Unmarshal(loginEnv.Data, &login)
|
||||
|
||||
pricesEnv, code := doAdminJSON(t, r, http.MethodGet, "/api/v1/admin/membership/plan-prices", nil, login.Token)
|
||||
if code != http.StatusOK || pricesEnv.Code != 0 {
|
||||
t.Fatalf("list prices http=%d code=%d msg=%s", code, pricesEnv.Code, pricesEnv.Message)
|
||||
}
|
||||
var prices struct {
|
||||
Items []struct {
|
||||
Plan string `json:"plan"`
|
||||
DisplayCents int `json:"display_cents"`
|
||||
} `json:"items"`
|
||||
}
|
||||
_ = json.Unmarshal(pricesEnv.Data, &prices)
|
||||
if len(prices.Items) == 0 {
|
||||
t.Fatal("expected seeded plan prices")
|
||||
}
|
||||
|
||||
putEnv, code := doAdminJSON(t, r, http.MethodPut, "/api/v1/admin/membership/plan-prices", map[string]any{
|
||||
"items": []map[string]any{
|
||||
{"plan": "monthly", "display_cents": 2900},
|
||||
{"plan": "yearly", "display_cents": 19900},
|
||||
},
|
||||
}, login.Token)
|
||||
if code != http.StatusOK || putEnv.Code != 0 {
|
||||
t.Fatalf("put prices http=%d code=%d msg=%s", code, putEnv.Code, putEnv.Message)
|
||||
}
|
||||
|
||||
ordersEnv, code := doAdminJSON(t, r, http.MethodGet, "/api/v1/admin/orders?status=paid&limit=5", nil, login.Token)
|
||||
if code != http.StatusOK || ordersEnv.Code != 0 {
|
||||
t.Fatalf("orders filter http=%d code=%d msg=%s", code, ordersEnv.Code, ordersEnv.Message)
|
||||
}
|
||||
var orders struct {
|
||||
Items []struct {
|
||||
Status string `json:"status"`
|
||||
RefundStatus string `json:"refund_status"`
|
||||
} `json:"items"`
|
||||
}
|
||||
_ = json.Unmarshal(ordersEnv.Data, &orders)
|
||||
for _, o := range orders.Items {
|
||||
if o.Status != "paid" {
|
||||
t.Fatalf("filter status=paid returned %q", o.Status)
|
||||
}
|
||||
if o.RefundStatus == "" {
|
||||
t.Fatal("expected refund_status field")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user