后台定价用例改键前先断言目标键存在

- server-rs/crates/api-server/src/app.rs:改默认定价 fixture 时先用 pointer_mut 断言目标键存在再赋值,不再依赖 Value::index_mut 的隐式 panic,键名或版本号漂移时报错能指出是哪一层对不上
This commit is contained in:
2026-09-24 17:51:08 +08:00
parent f2d3e2218d
commit a8dc0d8870
+10 -2
View File
@@ -6235,8 +6235,16 @@ mod tests {
.expect("后台定价必须返回版本");
let mut model3d = before["model3d"].clone();
assert!(!model3d.is_null(), "默认定价必须带 3D 两段");
model3d["textToModelPricing"]["addOnPrices"]["quadMesh"] = Value::Number(9.into());
model3d["imageToModelPricing"]["versionPrices"]["P2-20260801"]["texture"] =
// 先按路径读到目标键再改:`Value::index_mut` 在键缺失时直接 panic,默认定价
// 一旦换版本号或重命名键,只会看到一个没有上下文的 panic。先断言存在,
// fixture 漂移时就能看清是哪一层对不上。
*model3d
.pointer_mut("/textToModelPricing/addOnPrices/quadMesh")
.expect("默认定价必须带 textToModelPricing.addOnPrices.quadMesh") =
Value::Number(9.into());
*model3d
.pointer_mut("/imageToModelPricing/versionPrices/P2-20260801/texture")
.expect("默认定价必须带 imageToModelPricing.versionPrices.P2-20260801.texture") =
Value::Number(99.into());
let response = save_admin_editor_generation_pricing(