优化发货接口对接流程
This commit is contained in:
@@ -524,3 +524,83 @@ func TestHandleShipNotifyUpdatesOrderJobAndEnqueuesMerchantCallback(t *testing.T
|
||||
t.Fatalf("expected one ship notify audit, got %d", auditCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleShipNotifyRequiresFinalStatusAndFailureReason(t *testing.T) {
|
||||
db := newServiceTestDB(t)
|
||||
merchantID, product := seedFulfillmentMerchant(t, db, "merchant-source-contract", 1000, 2, 100)
|
||||
svc := NewFulfillmentService(db, nil)
|
||||
created, err := svc.CreateOrder(CreateFulfillmentOrderInput{
|
||||
MerchantID: merchantID,
|
||||
APIClientID: 31,
|
||||
ClientOrderNo: "client-source-contract",
|
||||
SKU: product.SKU,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create order: %v", err)
|
||||
}
|
||||
|
||||
if _, err := svc.HandleShipNotify(ShipNotifyInput{
|
||||
OrderNo: created.Order.OrderNo,
|
||||
ShipStatus: "processing",
|
||||
}); err == nil || !strings.Contains(err.Error(), "success/failed") {
|
||||
t.Fatalf("processing should be rejected, got %v", err)
|
||||
}
|
||||
if _, err := svc.HandleShipNotify(ShipNotifyInput{
|
||||
OrderNo: created.Order.OrderNo,
|
||||
ShipStatus: "failed",
|
||||
}); err == nil || !strings.Contains(err.Error(), "fail_reason") {
|
||||
t.Fatalf("failed without reason should be rejected, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleShipNotifySuccessClearsPreviousResultFailureReason(t *testing.T) {
|
||||
db := newServiceTestDB(t)
|
||||
merchantID, product := seedFulfillmentMerchant(t, db, "merchant-source-clear-reason", 1000, 2, 100)
|
||||
svc := NewFulfillmentService(db, nil)
|
||||
created, err := svc.CreateOrder(CreateFulfillmentOrderInput{
|
||||
MerchantID: merchantID,
|
||||
APIClientID: 31,
|
||||
ClientOrderNo: "client-source-clear-reason",
|
||||
SKU: product.SKU,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create order: %v", err)
|
||||
}
|
||||
|
||||
if _, err := svc.HandleShipNotify(ShipNotifyInput{
|
||||
OrderNo: created.Order.OrderNo,
|
||||
ShipStatus: "failed",
|
||||
FailReason: "渠道服校验失败",
|
||||
}); err != nil {
|
||||
t.Fatalf("mark failed: %v", err)
|
||||
}
|
||||
if _, err := svc.HandleShipNotify(ShipNotifyInput{
|
||||
OrderNo: created.Order.OrderNo,
|
||||
ShipStatus: "success",
|
||||
}); err != nil {
|
||||
t.Fatalf("mark success: %v", err)
|
||||
}
|
||||
|
||||
var order model.FulfillmentOrder
|
||||
if err := db.First(&order, created.Order.ID).Error; err != nil {
|
||||
t.Fatalf("query order: %v", err)
|
||||
}
|
||||
if order.FulfillmentStatus != model.FulfillmentStatusSucceeded || order.FailureReason != "" {
|
||||
t.Fatalf("success should clear order failure reason, got %+v", order)
|
||||
}
|
||||
if strings.Contains(order.ResultData, "fail_reason") {
|
||||
t.Fatalf("success should clear result_data fail_reason, got %s", order.ResultData)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildShipNotifyResultDataSuccessRemovesFailureReason(t *testing.T) {
|
||||
result := buildShipNotifyResultData(`{"ship_status":"failed","fail_reason":"旧失败原因"}`, ShipNotifyInput{
|
||||
ShipStatus: "success",
|
||||
}, nil)
|
||||
if strings.Contains(result, "fail_reason") {
|
||||
t.Fatalf("success result data should remove fail_reason, got %s", result)
|
||||
}
|
||||
if !strings.Contains(result, `"ship_status":"success"`) {
|
||||
t.Fatalf("success result data should keep ship_status, got %s", result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user