From 075da3063d4f12e4a489675612c13e4b4c99c93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Wed, 23 Oct 2024 09:57:52 +0000 Subject: [PATCH] fix test (#2) Co-authored-by: daniel.w Reviewed-on: https://code.30cm.net/digimon/app-cloudep-order-server/pulls/2 --- internal/logic/orderservice/decimal_tools.go | 13 +++---------- internal/logic/orderservice/get_order_logic.go | 6 ++++-- internal/logic/orderservice/get_order_logic_test.go | 3 ++- internal/logic/orderservice/list_order_logic.go | 1 + .../logic/orderservice/modify_order_status_logic.go | 3 ++- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/internal/logic/orderservice/decimal_tools.go b/internal/logic/orderservice/decimal_tools.go index 80bb3a6..8992d8c 100644 --- a/internal/logic/orderservice/decimal_tools.go +++ b/internal/logic/orderservice/decimal_tools.go @@ -14,6 +14,7 @@ func decimalPtrFromString(val string) *decimal.Decimal { dec, err := decimal.NewFromString(val) if err != nil { logx.Errorf("Failed to convert string to decimal: %v", err) + return nil } @@ -28,6 +29,7 @@ func convertDecimalPtrToDecimal128(d *decimal.Decimal) *primitive.Decimal128 { result, err := primitive.ParseDecimal128(d.String()) if err != nil { logx.Errorf("Failed to convert decimal to Decimal128: %v", err) + return nil } @@ -39,6 +41,7 @@ func convertDecimalToDecimal128(d decimal.Decimal) primitive.Decimal128 { result, err := primitive.ParseDecimal128(d.String()) if err != nil { logx.Errorf("Failed to convert decimal to Decimal128: %v", err) + return primitive.NewDecimal128(0, 0) } @@ -72,16 +75,6 @@ func optionalInt64(i *int64) *int64 { return nil } -func optionalDecimalToString(d *decimal.Decimal) *string { - if d != nil { - s := d.String() - - return &s - } - - return nil -} - func nilString(s *string) *string { if s == nil { return nil diff --git a/internal/logic/orderservice/get_order_logic.go b/internal/logic/orderservice/get_order_logic.go index 1d3030c..12803bb 100644 --- a/internal/logic/orderservice/get_order_logic.go +++ b/internal/logic/orderservice/get_order_logic.go @@ -4,9 +4,10 @@ import ( "app-cloudep-order-server/gen_result/pb/order" "app-cloudep-order-server/internal/domain" "app-cloudep-order-server/internal/svc" - ers "code.30cm.net/digimon/library-go/errs" "context" "errors" + + ers "code.30cm.net/digimon/library-go/errs" "github.com/zeromicro/go-zero/core/stores/mon" "github.com/zeromicro/go-zero/core/logx" @@ -43,9 +44,10 @@ func (l *GetOrderLogic) GetOrder(in *order.GetOrderReq) (*order.GetOrderResp, er o, err := l.svcCtx.OrderModel.FindOneBusinessID(l.ctx, in.GetBusinessId()) if err != nil { - if errors.As(err, &mon.ErrNotFound) { + if errors.Is(mon.ErrNotFound, err) { return nil, domain.NotFoundError(domain.DataNotFoundErrorCode, "failed to get this order id:", in.GetBusinessId()) } + return nil, err } diff --git a/internal/logic/orderservice/get_order_logic_test.go b/internal/logic/orderservice/get_order_logic_test.go index ddc83fa..ca37e15 100644 --- a/internal/logic/orderservice/get_order_logic_test.go +++ b/internal/logic/orderservice/get_order_logic_test.go @@ -8,9 +8,10 @@ import ( "app-cloudep-order-server/internal/svc" "context" "errors" - "go.mongodb.org/mongo-driver/bson/primitive" "testing" + "go.mongodb.org/mongo-driver/bson/primitive" + "github.com/stretchr/testify/assert" "go.uber.org/mock/gomock" ) diff --git a/internal/logic/orderservice/list_order_logic.go b/internal/logic/orderservice/list_order_logic.go index c020dc7..e3cd514 100644 --- a/internal/logic/orderservice/list_order_logic.go +++ b/internal/logic/orderservice/list_order_logic.go @@ -6,6 +6,7 @@ import ( "context" "app-cloudep-order-server/internal/svc" + ers "code.30cm.net/digimon/library-go/errs" "github.com/zeromicro/go-zero/core/logx" diff --git a/internal/logic/orderservice/modify_order_status_logic.go b/internal/logic/orderservice/modify_order_status_logic.go index 5254a21..9167370 100644 --- a/internal/logic/orderservice/modify_order_status_logic.go +++ b/internal/logic/orderservice/modify_order_status_logic.go @@ -4,9 +4,10 @@ import ( "app-cloudep-order-server/gen_result/pb/order" "app-cloudep-order-server/internal/domain" model "app-cloudep-order-server/internal/model/mongo" - ers "code.30cm.net/digimon/library-go/errs" "context" + ers "code.30cm.net/digimon/library-go/errs" + "app-cloudep-order-server/internal/svc" "github.com/zeromicro/go-zero/core/logx"