From b47f7b4f4614978a3085277043dcf9f716e5cfec Mon Sep 17 00:00:00 2001 From: huang Date: Mon, 2 Feb 2026 12:16:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=9B=86=E6=88=90=E6=B5=8B=E8=AF=95=E4=BB=A5=E9=80=82=E9=85=8D?= =?UTF-8?q?=20series=5Fid=20=E5=AD=97=E6=AE=B5=E9=87=8D=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将所有测试用例的 series_allocation_id 改为 series_id - 更新测试逻辑,直接使用 series.ID 而非 allocation.ID - 修复禁用系列测试,直接禁用 PackageSeries 而非 ShopSeriesAllocation - 所有集成测试通过验证 --- tests/integration/device_test.go | 54 +++++++++++++++--------------- tests/integration/iot_card_test.go | 54 +++++++++++++++--------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/tests/integration/device_test.go b/tests/integration/device_test.go index b12eee5..4805001 100644 --- a/tests/integration/device_test.go +++ b/tests/integration/device_test.go @@ -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) diff --git a/tests/integration/iot_card_test.go b/tests/integration/iot_card_test.go index 4c78e7f..2e8fe2f 100644 --- a/tests/integration/iot_card_test.go +++ b/tests/integration/iot_card_test.go @@ -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)