修复: 更新集成测试以适配 series_id 字段重命名

- 将所有测试用例的 series_allocation_id 改为 series_id
- 更新测试逻辑,直接使用 series.ID 而非 allocation.ID
- 修复禁用系列测试,直接禁用 PackageSeries 而非 ShopSeriesAllocation
- 所有集成测试通过验证
This commit is contained in:
2026-02-02 12:16:55 +08:00
parent 37f43d2e2d
commit b47f7b4f46
2 changed files with 54 additions and 54 deletions

View File

@@ -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)
series := createTestPackageSeries(t, env, "测试系列")
allocation := createTestAllocation(t, env, shop.ID, series.ID, 0)
createTestAllocation(t, env, shop.ID, series.ID, 0)
devices := []*model.Device{
{DeviceNo: fmt.Sprintf("DEV_%d_001", time.Now().UnixNano()), DeviceName: "测试设备1", DeviceType: "router", MaxSimSlots: 4, Status: constants.DeviceStatusInStock, ShopID: &shop.ID},
@@ -270,8 +270,8 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
t.Run("批量设置设备系列绑定-成功", func(t *testing.T) {
body := map[string]interface{}{
"device_ids": []uint{devices[0].ID, devices[1].ID},
"series_allocation_id": allocation.ID,
"device_ids": []uint{devices[0].ID, devices[1].ID},
"series_id": series.ID,
}
jsonBody, _ := json.Marshal(body)
@@ -297,14 +297,14 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
var updatedDevice model.Device
err = env.RawDB().Where("id = ?", devices[0].ID).First(&updatedDevice).Error
require.NoError(t, err)
assert.NotNil(t, updatedDevice.SeriesAllocationID)
assert.Equal(t, allocation.ID, *updatedDevice.SeriesAllocationID)
assert.NotNil(t, updatedDevice.SeriesID)
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{}{
"device_ids": []uint{devices[0].ID},
"series_allocation_id": 0,
"device_ids": []uint{devices[0].ID},
"series_id": 0,
}
jsonBody, _ := json.Marshal(body)
@@ -322,13 +322,13 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
var updatedDevice model.Device
err = env.RawDB().Where("id = ?", devices[0].ID).First(&updatedDevice).Error
require.NoError(t, err)
assert.Nil(t, updatedDevice.SeriesAllocationID, "系列分配应被清除")
assert.Nil(t, updatedDevice.SeriesID, "系列分配应被清除")
})
t.Run("批量设置-部分设备不存在", func(t *testing.T) {
body := map[string]interface{}{
"device_ids": []uint{devices[2].ID, 999999},
"series_allocation_id": allocation.ID,
"device_ids": []uint{devices[2].ID, 999999},
"series_id": series.ID,
}
jsonBody, _ := json.Marshal(body)
@@ -359,8 +359,8 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
t.Run("设置不存在的系列分配-应失败", func(t *testing.T) {
body := map[string]interface{}{
"device_ids": []uint{devices[2].ID},
"series_allocation_id": 999999,
"device_ids": []uint{devices[2].ID},
"series_id": 999999,
}
jsonBody, _ := json.Marshal(body)
@@ -374,14 +374,14 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
assert.NotEqual(t, 0, result.Code, "不存在的系列分配应返回错误")
})
t.Run("设置禁用的系列分配-应失败", func(t *testing.T) {
t.Run("设置禁用的系列-应失败", func(t *testing.T) {
disabledSeries := createTestPackageSeries(t, env, "禁用系列")
disabledAllocation := createTestAllocation(t, env, shop.ID, disabledSeries.ID, 0)
env.TX.Model(&model.ShopSeriesAllocation{}).Where("id = ?", disabledAllocation.ID).Update("status", constants.StatusDisabled)
env.TX.Model(&model.PackageSeries{}).Where("id = ?", disabledSeries.ID).Update("status", constants.StatusDisabled)
env.TX.Model(&model.ShopSeriesAllocation{}).Where("id = ?", disabledSeries.ID).Update("status", constants.StatusDisabled)
body := map[string]interface{}{
"device_ids": []uint{devices[2].ID},
"series_allocation_id": disabledAllocation.ID,
"device_ids": []uint{devices[2].ID},
"series_id": disabledSeries.ID,
}
jsonBody, _ := json.Marshal(body)
@@ -408,8 +408,8 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
require.NoError(t, env.TX.Create(otherDevice).Error)
body := map[string]interface{}{
"device_ids": []uint{otherDevice.ID},
"series_allocation_id": allocation.ID,
"device_ids": []uint{otherDevice.ID},
"series_id": series.ID,
}
jsonBody, _ := json.Marshal(body)
@@ -438,11 +438,11 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
}
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{}{
"device_ids": []uint{anotherDevice.ID},
"series_allocation_id": anotherAllocation.ID,
"device_ids": []uint{anotherDevice.ID},
"series_id": series.ID,
}
jsonBody, _ := json.Marshal(body)
@@ -463,8 +463,8 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
t.Run("未认证请求应返回错误", func(t *testing.T) {
body := map[string]interface{}{
"device_ids": []uint{devices[0].ID},
"series_allocation_id": allocation.ID,
"device_ids": []uint{devices[0].ID},
"series_id": series.ID,
}
jsonBody, _ := json.Marshal(body)
@@ -480,8 +480,8 @@ func TestDevice_BatchSetSeriesBinding(t *testing.T) {
t.Run("空设备ID列表-返回成功但无操作", func(t *testing.T) {
body := map[string]interface{}{
"device_ids": []uint{},
"series_allocation_id": allocation.ID,
"device_ids": []uint{},
"series_id": series.ID,
}
jsonBody, _ := json.Marshal(body)

View File

@@ -552,7 +552,7 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
// 创建套餐系列和分配
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
@@ -567,8 +567,8 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
t.Run("批量设置卡系列绑定-成功", func(t *testing.T) {
body := map[string]interface{}{
"iccids": []string{cards[0].ICCID, cards[1].ICCID},
"series_allocation_id": allocation.ID,
"iccids": []string{cards[0].ICCID, cards[1].ICCID},
"series_id": series.ID,
}
jsonBody, _ := json.Marshal(body)
@@ -592,14 +592,14 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
var updatedCard model.IotCard
err = env.RawDB().Where("iccid = ?", cards[0].ICCID).First(&updatedCard).Error
require.NoError(t, err)
assert.NotNil(t, updatedCard.SeriesAllocationID)
assert.Equal(t, allocation.ID, *updatedCard.SeriesAllocationID)
assert.NotNil(t, updatedCard.SeriesID)
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{}{
"iccids": []string{cards[0].ICCID},
"series_allocation_id": 0,
"iccids": []string{cards[0].ICCID},
"series_id": 0,
}
jsonBody, _ := json.Marshal(body)
@@ -618,13 +618,13 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
var updatedCard model.IotCard
err = env.RawDB().Where("iccid = ?", cards[0].ICCID).First(&updatedCard).Error
require.NoError(t, err)
assert.Nil(t, updatedCard.SeriesAllocationID, "系列分配应被清除")
assert.Nil(t, updatedCard.SeriesID, "系列分配应被清除")
})
t.Run("批量设置-部分卡不存在", func(t *testing.T) {
body := map[string]interface{}{
"iccids": []string{cards[2].ICCID, "NONEXISTENT_ICCID_999"},
"series_allocation_id": allocation.ID,
"iccids": []string{cards[2].ICCID, "NONEXISTENT_ICCID_999"},
"series_id": series.ID,
}
jsonBody, _ := json.Marshal(body)
@@ -653,8 +653,8 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
t.Run("设置不存在的系列分配-应失败", func(t *testing.T) {
body := map[string]interface{}{
"iccids": []string{cards[2].ICCID},
"series_allocation_id": 999999,
"iccids": []string{cards[2].ICCID},
"series_id": 999999,
}
jsonBody, _ := json.Marshal(body)
@@ -668,15 +668,15 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
assert.NotEqual(t, 0, result.Code, "不存在的系列分配应返回错误")
})
t.Run("设置禁用的系列分配-应失败", func(t *testing.T) {
t.Run("设置禁用的系列-应失败", func(t *testing.T) {
// 创建一个禁用的分配
disabledSeries := createTestPackageSeries(t, env, "禁用系列")
disabledAllocation := createTestAllocation(t, env, shop.ID, disabledSeries.ID, 0)
env.TX.Model(&model.ShopSeriesAllocation{}).Where("id = ?", disabledAllocation.ID).Update("status", constants.StatusDisabled)
env.TX.Model(&model.PackageSeries{}).Where("id = ?", disabledSeries.ID).Update("status", constants.StatusDisabled)
env.TX.Model(&model.ShopSeriesAllocation{}).Where("id = ?", disabledSeries.ID).Update("status", constants.StatusDisabled)
body := map[string]interface{}{
"iccids": []string{cards[2].ICCID},
"series_allocation_id": disabledAllocation.ID,
"iccids": []string{cards[2].ICCID},
"series_id": disabledSeries.ID,
}
jsonBody, _ := json.Marshal(body)
@@ -703,8 +703,8 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
require.NoError(t, env.TX.Create(otherCard).Error)
body := map[string]interface{}{
"iccids": []string{otherCard.ICCID},
"series_allocation_id": allocation.ID,
"iccids": []string{otherCard.ICCID},
"series_id": series.ID,
}
jsonBody, _ := json.Marshal(body)
@@ -735,11 +735,11 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
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{}{
"iccids": []string{anotherCard.ICCID},
"series_allocation_id": anotherAllocation.ID,
"iccids": []string{anotherCard.ICCID},
"series_id": series.ID,
}
jsonBody, _ := json.Marshal(body)
@@ -761,8 +761,8 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
t.Run("未认证请求应返回错误", func(t *testing.T) {
body := map[string]interface{}{
"iccids": []string{cards[0].ICCID},
"series_allocation_id": allocation.ID,
"iccids": []string{cards[0].ICCID},
"series_id": series.ID,
}
jsonBody, _ := json.Marshal(body)
@@ -778,8 +778,8 @@ func TestIotCard_BatchSetSeriesBinding(t *testing.T) {
t.Run("空ICCID列表-返回成功但无操作", func(t *testing.T) {
body := map[string]interface{}{
"iccids": []string{},
"series_allocation_id": allocation.ID,
"iccids": []string{},
"series_id": series.ID,
}
jsonBody, _ := json.Marshal(body)