修复: 更新集成测试以适配 series_id 字段重命名
- 将所有测试用例的 series_allocation_id 改为 series_id - 更新测试逻辑,直接使用 series.ID 而非 allocation.ID - 修复禁用系列测试,直接禁用 PackageSeries 而非 ShopSeriesAllocation - 所有集成测试通过验证
This commit is contained in:
@@ -257,7 +257,7 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
agentAccount := env.CreateTestAccount(fmt.Sprintf("agent_dev_%d", time.Now().UnixNano()), "password123", constants.UserTypeAgent, &shop.ID, nil)
|
agentAccount := env.CreateTestAccount(fmt.Sprintf("agent_dev_%d", time.Now().UnixNano()), "password123", constants.UserTypeAgent, &shop.ID, nil)
|
||||||
|
|
||||||
series := createTestPackageSeries(t, env, "测试系列")
|
series := createTestPackageSeries(t, env, "测试系列")
|
||||||
allocation := createTestAllocation(t, env, shop.ID, series.ID, 0)
|
createTestAllocation(t, env, shop.ID, series.ID, 0)
|
||||||
|
|
||||||
devices := []*model.Device{
|
devices := []*model.Device{
|
||||||
{DeviceNo: fmt.Sprintf("DEV_%d_001", time.Now().UnixNano()), DeviceName: "测试设备1", DeviceType: "router", MaxSimSlots: 4, Status: constants.DeviceStatusInStock, ShopID: &shop.ID},
|
{DeviceNo: fmt.Sprintf("DEV_%d_001", time.Now().UnixNano()), DeviceName: "测试设备1", DeviceType: "router", MaxSimSlots: 4, Status: constants.DeviceStatusInStock, ShopID: &shop.ID},
|
||||||
@@ -271,7 +271,7 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
t.Run("批量设置设备系列绑定-成功", func(t *testing.T) {
|
t.Run("批量设置设备系列绑定-成功", func(t *testing.T) {
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"device_ids": []uint{devices[0].ID, devices[1].ID},
|
"device_ids": []uint{devices[0].ID, devices[1].ID},
|
||||||
"series_allocation_id": allocation.ID,
|
"series_id": series.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -297,14 +297,14 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
var updatedDevice model.Device
|
var updatedDevice model.Device
|
||||||
err = env.RawDB().Where("id = ?", devices[0].ID).First(&updatedDevice).Error
|
err = env.RawDB().Where("id = ?", devices[0].ID).First(&updatedDevice).Error
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, updatedDevice.SeriesAllocationID)
|
assert.NotNil(t, updatedDevice.SeriesID)
|
||||||
assert.Equal(t, allocation.ID, *updatedDevice.SeriesAllocationID)
|
assert.Equal(t, series.ID, *updatedDevice.SeriesID)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("清除设备系列绑定-series_allocation_id=0", func(t *testing.T) {
|
t.Run("清除设备系列绑定-series_id=0", func(t *testing.T) {
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"device_ids": []uint{devices[0].ID},
|
"device_ids": []uint{devices[0].ID},
|
||||||
"series_allocation_id": 0,
|
"series_id": 0,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -322,13 +322,13 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
var updatedDevice model.Device
|
var updatedDevice model.Device
|
||||||
err = env.RawDB().Where("id = ?", devices[0].ID).First(&updatedDevice).Error
|
err = env.RawDB().Where("id = ?", devices[0].ID).First(&updatedDevice).Error
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Nil(t, updatedDevice.SeriesAllocationID, "系列分配应被清除")
|
assert.Nil(t, updatedDevice.SeriesID, "系列分配应被清除")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("批量设置-部分设备不存在", func(t *testing.T) {
|
t.Run("批量设置-部分设备不存在", func(t *testing.T) {
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"device_ids": []uint{devices[2].ID, 999999},
|
"device_ids": []uint{devices[2].ID, 999999},
|
||||||
"series_allocation_id": allocation.ID,
|
"series_id": series.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -360,7 +360,7 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
t.Run("设置不存在的系列分配-应失败", func(t *testing.T) {
|
t.Run("设置不存在的系列分配-应失败", func(t *testing.T) {
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"device_ids": []uint{devices[2].ID},
|
"device_ids": []uint{devices[2].ID},
|
||||||
"series_allocation_id": 999999,
|
"series_id": 999999,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -374,14 +374,14 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
assert.NotEqual(t, 0, result.Code, "不存在的系列分配应返回错误")
|
assert.NotEqual(t, 0, result.Code, "不存在的系列分配应返回错误")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("设置禁用的系列分配-应失败", func(t *testing.T) {
|
t.Run("设置禁用的系列-应失败", func(t *testing.T) {
|
||||||
disabledSeries := createTestPackageSeries(t, env, "禁用系列")
|
disabledSeries := createTestPackageSeries(t, env, "禁用系列")
|
||||||
disabledAllocation := createTestAllocation(t, env, shop.ID, disabledSeries.ID, 0)
|
env.TX.Model(&model.PackageSeries{}).Where("id = ?", disabledSeries.ID).Update("status", constants.StatusDisabled)
|
||||||
env.TX.Model(&model.ShopSeriesAllocation{}).Where("id = ?", disabledAllocation.ID).Update("status", constants.StatusDisabled)
|
env.TX.Model(&model.ShopSeriesAllocation{}).Where("id = ?", disabledSeries.ID).Update("status", constants.StatusDisabled)
|
||||||
|
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"device_ids": []uint{devices[2].ID},
|
"device_ids": []uint{devices[2].ID},
|
||||||
"series_allocation_id": disabledAllocation.ID,
|
"series_id": disabledSeries.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -409,7 +409,7 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
|
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"device_ids": []uint{otherDevice.ID},
|
"device_ids": []uint{otherDevice.ID},
|
||||||
"series_allocation_id": allocation.ID,
|
"series_id": series.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -438,11 +438,11 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
}
|
}
|
||||||
require.NoError(t, env.TX.Create(anotherDevice).Error)
|
require.NoError(t, env.TX.Create(anotherDevice).Error)
|
||||||
|
|
||||||
anotherAllocation := createTestAllocation(t, env, anotherShop.ID, series.ID, 0)
|
createTestAllocation(t, env, anotherShop.ID, series.ID, 0)
|
||||||
|
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"device_ids": []uint{anotherDevice.ID},
|
"device_ids": []uint{anotherDevice.ID},
|
||||||
"series_allocation_id": anotherAllocation.ID,
|
"series_id": series.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -464,7 +464,7 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
t.Run("未认证请求应返回错误", func(t *testing.T) {
|
t.Run("未认证请求应返回错误", func(t *testing.T) {
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"device_ids": []uint{devices[0].ID},
|
"device_ids": []uint{devices[0].ID},
|
||||||
"series_allocation_id": allocation.ID,
|
"series_id": series.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -481,7 +481,7 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
t.Run("空设备ID列表-返回成功但无操作", func(t *testing.T) {
|
t.Run("空设备ID列表-返回成功但无操作", func(t *testing.T) {
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"device_ids": []uint{},
|
"device_ids": []uint{},
|
||||||
"series_allocation_id": allocation.ID,
|
"series_id": series.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
|
|||||||
@@ -552,7 +552,7 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
|
|
||||||
// 创建套餐系列和分配
|
// 创建套餐系列和分配
|
||||||
series := createTestPackageSeries(t, env, "测试系列")
|
series := createTestPackageSeries(t, env, "测试系列")
|
||||||
allocation := createTestAllocation(t, env, shop.ID, series.ID, 0)
|
createTestAllocation(t, env, shop.ID, series.ID, 0)
|
||||||
|
|
||||||
// 创建测试卡(归属于该店铺)
|
// 创建测试卡(归属于该店铺)
|
||||||
timestamp := time.Now().Unix() % 1000000
|
timestamp := time.Now().Unix() % 1000000
|
||||||
@@ -568,7 +568,7 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
t.Run("批量设置卡系列绑定-成功", func(t *testing.T) {
|
t.Run("批量设置卡系列绑定-成功", func(t *testing.T) {
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"iccids": []string{cards[0].ICCID, cards[1].ICCID},
|
"iccids": []string{cards[0].ICCID, cards[1].ICCID},
|
||||||
"series_allocation_id": allocation.ID,
|
"series_id": series.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -592,14 +592,14 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
var updatedCard model.IotCard
|
var updatedCard model.IotCard
|
||||||
err = env.RawDB().Where("iccid = ?", cards[0].ICCID).First(&updatedCard).Error
|
err = env.RawDB().Where("iccid = ?", cards[0].ICCID).First(&updatedCard).Error
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, updatedCard.SeriesAllocationID)
|
assert.NotNil(t, updatedCard.SeriesID)
|
||||||
assert.Equal(t, allocation.ID, *updatedCard.SeriesAllocationID)
|
assert.Equal(t, series.ID, *updatedCard.SeriesID)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("清除卡系列绑定-series_allocation_id=0", func(t *testing.T) {
|
t.Run("清除卡系列绑定-series_id=0", func(t *testing.T) {
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"iccids": []string{cards[0].ICCID},
|
"iccids": []string{cards[0].ICCID},
|
||||||
"series_allocation_id": 0,
|
"series_id": 0,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -618,13 +618,13 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
var updatedCard model.IotCard
|
var updatedCard model.IotCard
|
||||||
err = env.RawDB().Where("iccid = ?", cards[0].ICCID).First(&updatedCard).Error
|
err = env.RawDB().Where("iccid = ?", cards[0].ICCID).First(&updatedCard).Error
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Nil(t, updatedCard.SeriesAllocationID, "系列分配应被清除")
|
assert.Nil(t, updatedCard.SeriesID, "系列分配应被清除")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("批量设置-部分卡不存在", func(t *testing.T) {
|
t.Run("批量设置-部分卡不存在", func(t *testing.T) {
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"iccids": []string{cards[2].ICCID, "NONEXISTENT_ICCID_999"},
|
"iccids": []string{cards[2].ICCID, "NONEXISTENT_ICCID_999"},
|
||||||
"series_allocation_id": allocation.ID,
|
"series_id": series.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -654,7 +654,7 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
t.Run("设置不存在的系列分配-应失败", func(t *testing.T) {
|
t.Run("设置不存在的系列分配-应失败", func(t *testing.T) {
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"iccids": []string{cards[2].ICCID},
|
"iccids": []string{cards[2].ICCID},
|
||||||
"series_allocation_id": 999999,
|
"series_id": 999999,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -668,15 +668,15 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
assert.NotEqual(t, 0, result.Code, "不存在的系列分配应返回错误")
|
assert.NotEqual(t, 0, result.Code, "不存在的系列分配应返回错误")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("设置禁用的系列分配-应失败", func(t *testing.T) {
|
t.Run("设置禁用的系列-应失败", func(t *testing.T) {
|
||||||
// 创建一个禁用的分配
|
// 创建一个禁用的分配
|
||||||
disabledSeries := createTestPackageSeries(t, env, "禁用系列")
|
disabledSeries := createTestPackageSeries(t, env, "禁用系列")
|
||||||
disabledAllocation := createTestAllocation(t, env, shop.ID, disabledSeries.ID, 0)
|
env.TX.Model(&model.PackageSeries{}).Where("id = ?", disabledSeries.ID).Update("status", constants.StatusDisabled)
|
||||||
env.TX.Model(&model.ShopSeriesAllocation{}).Where("id = ?", disabledAllocation.ID).Update("status", constants.StatusDisabled)
|
env.TX.Model(&model.ShopSeriesAllocation{}).Where("id = ?", disabledSeries.ID).Update("status", constants.StatusDisabled)
|
||||||
|
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"iccids": []string{cards[2].ICCID},
|
"iccids": []string{cards[2].ICCID},
|
||||||
"series_allocation_id": disabledAllocation.ID,
|
"series_id": disabledSeries.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -704,7 +704,7 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
|
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"iccids": []string{otherCard.ICCID},
|
"iccids": []string{otherCard.ICCID},
|
||||||
"series_allocation_id": allocation.ID,
|
"series_id": series.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -735,11 +735,11 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
require.NoError(t, env.TX.Create(anotherCard).Error)
|
require.NoError(t, env.TX.Create(anotherCard).Error)
|
||||||
|
|
||||||
// 为这个店铺创建系列分配
|
// 为这个店铺创建系列分配
|
||||||
anotherAllocation := createTestAllocation(t, env, anotherShop.ID, series.ID, 0)
|
createTestAllocation(t, env, anotherShop.ID, series.ID, 0)
|
||||||
|
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"iccids": []string{anotherCard.ICCID},
|
"iccids": []string{anotherCard.ICCID},
|
||||||
"series_allocation_id": anotherAllocation.ID,
|
"series_id": series.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -762,7 +762,7 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
t.Run("未认证请求应返回错误", func(t *testing.T) {
|
t.Run("未认证请求应返回错误", func(t *testing.T) {
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"iccids": []string{cards[0].ICCID},
|
"iccids": []string{cards[0].ICCID},
|
||||||
"series_allocation_id": allocation.ID,
|
"series_id": series.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
@@ -779,7 +779,7 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
|
|||||||
t.Run("空ICCID列表-返回成功但无操作", func(t *testing.T) {
|
t.Run("空ICCID列表-返回成功但无操作", func(t *testing.T) {
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"iccids": []string{},
|
"iccids": []string{},
|
||||||
"series_allocation_id": allocation.ID,
|
"series_id": series.ID,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user