payment-history: /payments/{id}/gateway takes an order ID and lists its payments
The frontend calls /payments/{id}/gateway with an order ID, so that URL
now returns every payment of the order (newest first, each with its
HALKBANK JSON) instead of one payment by payment ID. /{id}/gateway stays
as an alias of the same handler.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,21 +12,11 @@ import (
|
||||
"online-back/pkg/logging"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v4"
|
||||
)
|
||||
|
||||
type fakeRepository struct {
|
||||
Repository
|
||||
orders map[int64][]PaymentHistoryDetailDTO
|
||||
payments map[int64]PaymentHistoryDetailDTO
|
||||
}
|
||||
|
||||
func (f fakeRepository) Get(_ context.Context, paymentID int64) (PaymentHistoryDetailDTO, error) {
|
||||
p, ok := f.payments[paymentID]
|
||||
if !ok {
|
||||
return PaymentHistoryDetailDTO{}, pgx.ErrNoRows
|
||||
}
|
||||
return p, nil
|
||||
orders map[int64][]PaymentHistoryDetailDTO
|
||||
}
|
||||
|
||||
func (f fakeRepository) OrderPaymentDetails(_ context.Context, orderID int64) ([]PaymentHistoryDetailDTO, error) {
|
||||
@@ -45,11 +35,10 @@ func gatewayRequest(t *testing.T, repo Repository, path string) *httptest.Respon
|
||||
router.Use(func(c *gin.Context) {
|
||||
c.Set("rbacPrincipal", &rbac.Principal{UserID: 1, Scope: rbac.ScopeAll})
|
||||
})
|
||||
router.GET("/payment-history/payments/:id/gateway", h.paymentGateway)
|
||||
router.GET("/payment-history/:id/gateway", h.gateway)
|
||||
router.GET("/payment-history/payments/:id/gateway", h.gateway)
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
router.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/payment-history/"+path, nil))
|
||||
router.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/payment-history/payments/"+path, nil))
|
||||
return rec
|
||||
}
|
||||
|
||||
@@ -142,34 +131,3 @@ func TestGatewayEmptyOrderAndBadID(t *testing.T) {
|
||||
t.Errorf("abc/gateway: got %d, want %d", rec.Code, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPaymentGatewayReturnsOnePayment(t *testing.T) {
|
||||
repo := fakeRepository{payments: map[int64]PaymentHistoryDetailDTO{
|
||||
2922: {
|
||||
PaymentHistoryItemDTO: PaymentHistoryItemDTO{Id: 2922, OrderId: 9437, Paid: true, GatewayStatus: "success"},
|
||||
GatewayResponse: json.RawMessage(`{"orderStatus":2}`),
|
||||
},
|
||||
}}
|
||||
|
||||
rec := gatewayRequest(t, repo, "payments/2922/gateway")
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("got %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var body struct {
|
||||
Data map[string]json.RawMessage `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for key, value := range map[string]string{"id": `2922`, "orderId": `9437`, "gatewayResponse": `{"orderStatus":2}`} {
|
||||
if got := string(body.Data[key]); got != value {
|
||||
t.Errorf("%s: got %s, want %s", key, got, value)
|
||||
}
|
||||
}
|
||||
|
||||
for path, want := range map[string]int{"payments/abc/gateway": http.StatusBadRequest, "payments/999/gateway": http.StatusNotFound} {
|
||||
if rec := gatewayRequest(t, repo, path); rec.Code != want {
|
||||
t.Errorf("%s: got %d, want %d", path, rec.Code, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user