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 TestInventoryHandler_List(t *testing.T) {
|
||||
// 直接插入库存记录
|
||||
inv := model.Inventory{
|
||||
ShopID: shop.ID,
|
||||
WarehouseID: warehouse.ID,
|
||||
ProductID: product.ID,
|
||||
WarehouseID: &warehouse.ID,
|
||||
ProductID: &product.ID,
|
||||
Quantity: 100,
|
||||
}
|
||||
require.NoError(t, db.Create(&inv).Error)
|
||||
@@ -49,8 +49,8 @@ func TestInventoryHandler_List_FilterByWarehouse(t *testing.T) {
|
||||
r := setupProtectedRouter(db)
|
||||
|
||||
// 两个仓库各有一个库存
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: warehouse1.ID, ProductID: product1.ID, Quantity: 10})
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: warehouse2.ID, ProductID: product2.ID, Quantity: 20})
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: &warehouse1.ID, ProductID: &product1.ID, Quantity: 10})
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: &warehouse2.ID, ProductID: &product2.ID, Quantity: 20})
|
||||
|
||||
// 按仓库过滤
|
||||
w := makeRequest(r, "GET", fmt.Sprintf("/api/v1/inventory?warehouse_id=%d", warehouse1.ID), token, nil)
|
||||
@@ -69,8 +69,8 @@ func TestInventoryHandler_List_InStockOnly(t *testing.T) {
|
||||
token := getAuthToken(user.ID, shop.ID, "admin")
|
||||
r := setupProtectedRouter(db)
|
||||
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: warehouse.ID, ProductID: product1.ID, Quantity: 10})
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: warehouse.ID, ProductID: product2.ID, Quantity: 0})
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: &warehouse.ID, ProductID: &product1.ID, Quantity: 10})
|
||||
db.Create(&model.Inventory{ShopID: shop.ID, WarehouseID: &warehouse.ID, ProductID: &product2.ID, Quantity: 0})
|
||||
|
||||
// 只显示有库存的
|
||||
w := makeRequest(r, "GET", "/api/v1/inventory?in_stock=1", token, nil)
|
||||
@@ -121,8 +121,8 @@ func TestInventoryHandler_CreateCheck(t *testing.T) {
|
||||
// 先创建库存
|
||||
db.Create(&model.Inventory{
|
||||
ShopID: shop.ID,
|
||||
WarehouseID: warehouse.ID,
|
||||
ProductID: product.ID,
|
||||
WarehouseID: &warehouse.ID,
|
||||
ProductID: &product.ID,
|
||||
Quantity: 50,
|
||||
})
|
||||
|
||||
@@ -206,7 +206,7 @@ func TestInventoryHandler_List_HotelIsolation(t *testing.T) {
|
||||
r := setupProtectedRouter(db)
|
||||
|
||||
// 酒店 A 有库存
|
||||
db.Create(&model.Inventory{ShopID: shopA.ID, WarehouseID: warehouseA.ID, ProductID: productA.ID, Quantity: 100})
|
||||
db.Create(&model.Inventory{ShopID: shopA.ID, WarehouseID: &warehouseA.ID, ProductID: &productA.ID, Quantity: 100})
|
||||
|
||||
// 酒店 A 能看到自己的库存
|
||||
w := makeRequest(r, "GET", "/api/v1/inventory", tokenA, nil)
|
||||
|
||||
Reference in New Issue
Block a user