@smbcloud / smbcloud-ascapi Mirror · read-only / commits / d0fcb53
Fork 0

Read-only mirror of github.com/smbcloudXYZ/smbcloud-ascapi.

Mirrored from https://github.com/smbcloudXYZ/smbcloud-ascapi.git

Synced Nov 25, 09:15 UTC

Let a multi-option product's price be updated

products update had no way to say which purchase option a price change re-prices, so a product with several options could never be price-updated: pick_purchase_option errored and told the user to pass --purchase-option, a flag the command did not have. Add that flag and thread it through ProductChanges. Also fix two guards the review caught in the same path: with zero listings and no --language the error wrongly claimed 'several listings', and the update path dropped the regions version with .ok() instead of surfacing the error the create path already raises. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-Authored-By: siGit Code v1.7.6 <noreply@sigit.si>

Seto Elkahfi committed Nov 8, 2026 at 19:44 UTC d0fcb53cec4ed054b91d51f5e21816db07125b1a
3 files changed +62 -3
crates/cli/src/main.rs
+6
@@ -716,6 +716,10 @@ enum PlayProductsCommand {
716 price: Option<String>,
717 #[arg(long, default_value = "USD")]
718 currency: String,
719 + /// Which purchase option a price change re-prices; optional when the
720 + /// product has one option.
721 + #[arg(long)]
722 + purchase_option: Option<String>,
723 },
724 /// Make a product buyable again. Without `--purchase-option`, uses the
725 /// product's only option.
@@ -1596,6 +1600,7 @@ async fn run_play(
1600 language,
1601 price,
1602 currency,
1603 + purchase_option,
1604 } => {
1605 let price = price
1606 .map(|p| PlayMoney::parse(&currency, &p))
@@ -1606,6 +1611,7 @@ async fn run_play(
1611 description,
1612 language,
1613 price,
1614 + purchase_option,
1615 };
1616 let result =
1617 play::update_product(&client, &package, &product_id, &changes, dry_run)
crates/frontend/src/play.rs
+4 -1
@@ -986,7 +986,10 @@ pub async fn update_product(
986 stored: None,
987 });
988 }
989 - let version = converted.as_ref().and_then(|c| regions_version(c).ok());
989 + let version = match converted.as_ref() {
990 + Some(c) => Some(regions_version(c).map_err(err)?),
991 + None => None,
992 + };
993 client
994 .update_product(package, product_id, &body, &mask, version.as_deref())
995 .await
crates/play/src/product.rs
+52 -2
@@ -227,6 +227,9 @@ pub struct ProductChanges {
227 /// Which listing to change; optional when the product has one listing.
228 pub language: Option<String>,
229 pub price: Option<Money>,
230 + /// Which purchase option a price change re-prices; optional when the
231 + /// product has one option.
232 + pub purchase_option: Option<String>,
233 }
234
235 impl ProductChanges {
@@ -310,7 +313,9 @@ pub fn update_body(
313 .to_string(),
314 _ => {
315 return Err(Error::Invalid(
313 - "the product has several listings; pass --language".to_string(),
316 + "pass --language to name the listing to change (a new one also needs \
317 + --title and --description)"
318 + .to_string(),
319 ))
320 }
321 };
@@ -351,7 +356,7 @@ pub fn update_body(
356 .and_then(Value::as_object)
357 .filter(|m| !m.is_empty())
358 .ok_or_else(|| Error::Invalid("Play returned no regional prices".to_string()))?;
354 - let target = pick_purchase_option(product, None)?;
359 + let target = pick_purchase_option(product, changes.purchase_option.as_deref())?;
360 let mut all: Vec<Value> = options(product).to_vec();
361 for option in all.iter_mut() {
362 if option.get("purchaseOptionId").and_then(Value::as_str) != Some(target.as_str()) {
@@ -689,6 +694,51 @@ mod tests {
694 assert_eq!(existing_price(&stored_product()).unwrap().currency, "GBP");
695 }
696
697 + #[test]
698 + fn a_price_update_names_the_option_when_the_product_has_several() {
699 + let converted = json!({
700 + "regionVersion": { "version": "2022/02" },
701 + "convertedRegionPrices": {
702 + "GB": { "price": { "currencyCode": "GBP", "units": "5", "nanos": 0 } }
703 + }
704 + });
705 + let mut product = stored_product();
706 + product["purchaseOptions"]
707 + .as_array_mut()
708 + .unwrap()
709 + .push(json!({
710 + "purchaseOptionId": "rent", "state": "ACTIVE",
711 + "regionalPricingAndAvailabilityConfigs": [
712 + { "regionCode": "GB", "availability": "AVAILABLE",
713 + "price": { "currencyCode": "GBP", "units": "2", "nanos": 0 } }
714 + ]
715 + }));
716 + let changes = ProductChanges {
717 + price: Some(Money::parse("USD", "5").unwrap()),
718 + ..Default::default()
719 + };
720 + assert!(update_body(&product, &changes, Some(&converted))
721 + .unwrap_err()
722 + .to_string()
723 + .contains("--purchase-option"));
724 + let changes = ProductChanges {
725 + price: Some(Money::parse("USD", "5").unwrap()),
726 + purchase_option: Some("rent".into()),
727 + ..Default::default()
728 + };
729 + let body = update_body(&product, &changes, Some(&converted)).unwrap();
730 + let repriced = body["purchaseOptions"]
731 + .as_array()
732 + .unwrap()
733 + .iter()
734 + .find(|o| o["purchaseOptionId"] == "rent")
735 + .unwrap();
736 + assert_eq!(
737 + repriced["regionalPricingAndAvailabilityConfigs"][0]["price"]["units"],
738 + "5"
739 + );
740 + }
741 +
742 #[test]
743 fn read_back_differences_are_caught() {
744 let changes = ProductChanges {