diff --git a/internal/logic/admin/order/updateOrderStatusLogic.go b/internal/logic/admin/order/updateOrderStatusLogic.go index 17df64d..2164652 100644 --- a/internal/logic/admin/order/updateOrderStatusLogic.go +++ b/internal/logic/admin/order/updateOrderStatusLogic.go @@ -31,6 +31,10 @@ func NewUpdateOrderStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) } func (l *UpdateOrderStatusLogic) UpdateOrderStatus(req *types.UpdateOrderStatusRequest) error { + if req.Status == orderStatusRefunded { + return errors.Wrapf(xerr.NewErrCode(xerr.OrderStatusError), "refund status must use refund order endpoint") + } + info, err := l.svcCtx.OrderModel.FindOne(l.ctx, req.Id) if err != nil { l.Errorw("[UpdateOrderStatus] FindOne error", logger.Field("error", err.Error())) diff --git a/internal/logic/admin/order/updateOrderStatusLogic_test.go b/internal/logic/admin/order/updateOrderStatusLogic_test.go new file mode 100644 index 0000000..d867b92 --- /dev/null +++ b/internal/logic/admin/order/updateOrderStatusLogic_test.go @@ -0,0 +1,27 @@ +package order + +import ( + "context" + "testing" + + "github.com/perfect-panel/server/internal/svc" + "github.com/perfect-panel/server/internal/types" + "github.com/perfect-panel/server/pkg/logger" + "github.com/perfect-panel/server/pkg/xerr" +) + +func TestUpdateOrderStatus_RejectsRefundStatus(t *testing.T) { + logic := &UpdateOrderStatusLogic{ + Logger: logger.WithContext(context.Background()), + ctx: context.Background(), + svcCtx: &svc.ServiceContext{}, + } + + err := logic.UpdateOrderStatus(&types.UpdateOrderStatusRequest{ + Id: 1001, + Status: orderStatusRefunded, + }) + if !isErrCode(err, xerr.OrderStatusError) { + t.Fatalf("UpdateOrderStatus error code = %v, want OrderStatusError; raw=%v", errCodeOf(err), err) + } +}