fix(test): 修复测试文件类型错误和测试数据库 schema 过期问题
- 修正 stock_in/out 测试中 WarehouseID/ProductID 指针误用(StockOrder 用 uint64,Inventory 用 *uint64) - 更新 testutil/setup.go:inventories 表加入所有批次字段,stock_in_items 加 production_date,新增 finance_records 表 - 修正 inventory handler 中 DATE_FORMAT(MySQL 专属)→ DATE()(跨 DB 兼容) - 更新断言:order_no 前缀改为 RK,库存总量用 SUM 替代 First - 库存 List 新增 in_stock=1 过滤器 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -25,8 +25,8 @@ func TestStockOutHandler_FullFlow(t *testing.T) {
|
||||
// 先建立库存
|
||||
db.Create(&model.Inventory{
|
||||
ShopID: shop.ID,
|
||||
WarehouseID: warehouse.ID,
|
||||
ProductID: product.ID,
|
||||
WarehouseID: &warehouse.ID,
|
||||
ProductID: &product.ID,
|
||||
Quantity: 100,
|
||||
})
|
||||
|
||||
@@ -83,8 +83,8 @@ func TestStockOutHandler_InsufficientStock(t *testing.T) {
|
||||
// 库存只有 5
|
||||
db.Create(&model.Inventory{
|
||||
ShopID: shop.ID,
|
||||
WarehouseID: warehouse.ID,
|
||||
ProductID: product.ID,
|
||||
WarehouseID: &warehouse.ID,
|
||||
ProductID: &product.ID,
|
||||
Quantity: 5,
|
||||
})
|
||||
|
||||
@@ -114,7 +114,7 @@ func TestStockOutHandler_List(t *testing.T) {
|
||||
r := setupProtectedRouter(db)
|
||||
|
||||
// 先建立库存
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: warehouse.ID, ProductID: product.ID, Quantity: 100})
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: &warehouse.ID, ProductID: &product.ID, Quantity: 100})
|
||||
|
||||
// 创建 2 个出库单
|
||||
for i := 0; i < 2; i++ {
|
||||
@@ -142,7 +142,7 @@ func TestStockOutHandler_Reject(t *testing.T) {
|
||||
token := getAuthToken(user.ID, shop.ID, "admin")
|
||||
r := setupProtectedRouter(db)
|
||||
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: warehouse.ID, ProductID: product.ID, Quantity: 100})
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: &warehouse.ID, ProductID: &product.ID, Quantity: 100})
|
||||
|
||||
w := makeRequest(r, "POST", "/api/v1/stock-out/orders", token, map[string]interface{}{
|
||||
"warehouse_id": warehouse.ID,
|
||||
@@ -206,8 +206,8 @@ func TestStockOutHandler_TenantIsolation(t *testing.T) {
|
||||
// 建立门店 A 的库存
|
||||
db.Create(&model.Inventory{
|
||||
ShopID: shopA.ID,
|
||||
WarehouseID: warehouseA.ID,
|
||||
ProductID: productA.ID,
|
||||
WarehouseID: &warehouseA.ID,
|
||||
ProductID: &productA.ID,
|
||||
Quantity: 50,
|
||||
})
|
||||
|
||||
@@ -259,7 +259,7 @@ func TestStockOutHandler_Approve_NotPending(t *testing.T) {
|
||||
token := getAuthToken(user.ID, shop.ID, "admin")
|
||||
r := setupProtectedRouter(db)
|
||||
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: warehouse.ID, ProductID: product.ID, Quantity: 50})
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: &warehouse.ID, ProductID: &product.ID, Quantity: 50})
|
||||
|
||||
// 创建但不提交
|
||||
w := makeRequest(r, "POST", "/api/v1/stock-out/orders", token, map[string]interface{}{
|
||||
@@ -285,7 +285,7 @@ func TestStockOutHandler_InventoryLog_OnApprove(t *testing.T) {
|
||||
token := getAuthToken(user.ID, shop.ID, "admin")
|
||||
r := setupProtectedRouter(db)
|
||||
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: warehouse.ID, ProductID: product.ID, Quantity: 100})
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: &warehouse.ID, ProductID: &product.ID, Quantity: 100})
|
||||
|
||||
// 创建、提交、审核
|
||||
w := makeRequest(r, "POST", "/api/v1/stock-out/orders", token, map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user