fix(#56): add go-admin success envelope
This commit is contained in:
@@ -101,3 +101,20 @@ func TestAdminQueryHandlersRequireOperatorRole(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminSuccessEnvelopeIsCompatibleWithGoAdminUI(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
recorder := httptest.NewRecorder()
|
||||
context, _ := gin.CreateTestContext(recorder)
|
||||
writeAdminReplay(context, gin.H{"id": 42}, true)
|
||||
if recorder.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d", recorder.Code)
|
||||
}
|
||||
var response map[string]any
|
||||
if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if response["code"] != float64(http.StatusOK) || response["replayed"] != true || response["data"] == nil {
|
||||
t.Fatalf("unexpected admin envelope: %v", response)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (h Handler) AdminList(c *gin.Context) {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": response})
|
||||
writeAdminData(c, response)
|
||||
}
|
||||
|
||||
func (h Handler) AdminDetail(c *gin.Context) {
|
||||
@@ -77,7 +77,7 @@ func (h Handler) AdminDetail(c *gin.Context) {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": response})
|
||||
writeAdminData(c, response)
|
||||
}
|
||||
|
||||
func (h Handler) AdminCreate(c *gin.Context) {
|
||||
@@ -97,7 +97,7 @@ func (h Handler) AdminCreate(c *gin.Context) {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": record, "replayed": replayed})
|
||||
writeAdminReplay(c, record, replayed)
|
||||
}
|
||||
func (h Handler) Next(c *gin.Context) {
|
||||
service, ok := h.service(c)
|
||||
@@ -160,7 +160,7 @@ func (h Handler) SpecDecision(c *gin.Context) {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": p, "replayed": replayed})
|
||||
writeAdminReplay(c, p, replayed)
|
||||
}
|
||||
func (h Handler) AuthorizeRePurchase(c *gin.Context) { h.manual(c, (*Service).AuthorizeRePurchase) }
|
||||
func (h Handler) ReviewPayment(c *gin.Context) { h.manual(c, (*Service).ReviewPayment) }
|
||||
@@ -215,7 +215,15 @@ func (h Handler) manual(c *gin.Context, fn func(*Service, context.Context, uint6
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": p, "replayed": replayed})
|
||||
writeAdminReplay(c, p, replayed)
|
||||
}
|
||||
|
||||
func writeAdminData(c *gin.Context, data any) {
|
||||
c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "data": data})
|
||||
}
|
||||
|
||||
func writeAdminReplay(c *gin.Context, data any, replayed bool) {
|
||||
c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "data": data, "replayed": replayed})
|
||||
}
|
||||
|
||||
func allowedOperator(c *gin.Context) bool {
|
||||
|
||||
Reference in New Issue
Block a user