@smbcloud / smbcloud-ascapi Mirror · read-only / commits / bc212ae
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

Add Apple subscriptions, subscription images and review items

asc in-app-purchases only covers one-time products, so there was no way to list an app's auto-renewable subscriptions or give them the 1024x1024 image the App Store shows. asc subscriptions list walks the app's subscription groups; subscriptions promotional-image uploads to subscriptionImages with the same reserve, PUT, commit flow as the IAP image, and reads it back. review-submissions items shows what a submission holds. It now asks for the related version, events and product page versions, so an item says what it points at instead of only carrying links. This commit also carries the CLI wiring for the Play and Microsoft Store commands in the next two commits, since it all lives in main.rs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si> Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>

Seto Elkahfi committed Nov 19, 2026 at 23:08 UTC bc212aefe16e3ff72d9e9d7a914a05dfb10ba666
4 files changed +551 -2
crates/aso/src/review_submission.rs
+10 -2
@@ -179,8 +179,16 @@ impl ReviewSubmissionsApi for Client {
179 submission_id: &str,
180 ) -> Result<Vec<ReviewSubmissionItem>> {
181 let path = format!("/v1/reviewSubmissions/{submission_id}/items");
182 - self.list_all::<ReviewSubmissionItemAttributes>(&path, &[])
183 - .await
182 + // Without `include` Apple returns only relationship links, so the
183 + // caller could not tell which version or event an item points at.
184 + self.list_all::<ReviewSubmissionItemAttributes>(
185 + &path,
186 + &[(
187 + "include",
188 + "appStoreVersion,appCustomProductPageVersion,appStoreVersionExperiment,appEvent",
189 + )],
190 + )
191 + .await
192 }
193
194 async fn add_app_store_version_to_review_submission(
crates/cli/src/main.rs
+249
@@ -206,6 +206,57 @@ enum PlayCommand {
206 #[command(subcommand)]
207 command: PlayProductsCommand,
208 },
209 + /// Auto-renewing subscriptions: list, read, create. The subscription's
210 + /// icon has no API; upload it in Play Console.
211 + Subscriptions {
212 + #[command(subcommand)]
213 + command: PlaySubscriptionsCommand,
214 + },
215 +}
216 +
217 +// Create carries many flags; boxing a clap subcommand field is not possible.
218 +#[allow(clippy::large_enum_variant)]
219 +#[derive(Subcommand)]
220 +enum PlaySubscriptionsCommand {
221 + /// Every subscription of the app, with its base plans and their state.
222 + List { package: String },
223 + /// One subscription by id, in full.
224 + Get { package: String, product_id: String },
225 + /// Create a subscription with one auto-renewing base plan, price it in
226 + /// every region from one price, and activate the base plan. Refuses an id
227 + /// that exists. With `--dry-run` it prints the body and sends nothing.
228 + Create {
229 + package: String,
230 + #[arg(long)]
231 + id: String,
232 + /// Shown on Play (at most 55 characters).
233 + #[arg(long)]
234 + title: String,
235 + /// At most 200 characters; Play does not show it to buyers.
236 + #[arg(long)]
237 + description: Option<String>,
238 + /// One benefit (at most 40 characters); repeat for up to four.
239 + #[arg(long)]
240 + benefit: Vec<String>,
241 + /// Price in `--currency` per billing period, for example 14.99.
242 + #[arg(long)]
243 + price: String,
244 + #[arg(long, default_value = "USD")]
245 + currency: String,
246 + /// Language of the listing; the app's default language.
247 + #[arg(long)]
248 + language: String,
249 + /// Base plan id (lowercase letters, digits and -).
250 + #[arg(long, default_value = "monthly")]
251 + base_plan_id: String,
252 + /// ISO 8601 billing period: P1W, P1M, P3M, P6M, P1Y.
253 + #[arg(long, default_value = "P1M")]
254 + billing_period: String,
255 + /// ISO 8601 grace period after a failed renewal, e.g. P3D. Leave it
256 + /// off for Play's default.
257 + #[arg(long)]
258 + grace_period: Option<String>,
259 + },
260 }
261
262 // The update commands carry many flags; boxing a clap subcommand field is not
@@ -972,6 +1023,39 @@ enum MsStoreCommand {
1023 #[command(subcommand)]
1024 command: MsStoreListingsCommand,
1025 },
1026 + /// Add-ons (in-app products and subscriptions): list them and set their
1027 + /// 300x300 store logo. Writes go into the add-on's pending submission and
1028 + /// never commit it.
1029 + Addons {
1030 + #[command(subcommand)]
1031 + command: MsStoreAddonsCommand,
1032 + },
1033 +}
1034 +
1035 +#[derive(Subcommand)]
1036 +enum MsStoreAddonsCommand {
1037 + /// Every add-on of the app: Store id, product id, type, pending draft.
1038 + List {
1039 + /// Store product id of the app; defaults to MSSTORE_PRODUCT_ID.
1040 + #[arg(long)]
1041 + product_id: Option<String>,
1042 + },
1043 + /// Put a 300x300 PNG on an add-on's listing(s) as its logo, in the
1044 + /// pending add-on submission (created from the last published one when
1045 + /// there is none). Submit it in Partner Center afterwards.
1046 + SetIcon {
1047 + /// The add-on, by Store id or by the product id the app buys with
1048 + /// (e.g. personal_pro_monthly).
1049 + addon: String,
1050 + #[arg(long)]
1051 + file: PathBuf,
1052 + /// Only this listing locale (e.g. en-us); every listing by default.
1053 + #[arg(long)]
1054 + locale: Option<String>,
1055 + /// Store product id of the app; defaults to MSSTORE_PRODUCT_ID.
1056 + #[arg(long)]
1057 + product_id: Option<String>,
1058 + },
1059 }
1060
1061 #[derive(Subcommand)]
@@ -1197,6 +1281,12 @@ enum Command {
1281 #[command(subcommand)]
1282 command: InAppPurchasesCommand,
1283 },
1284 + /// Auto-renewable subscriptions: list them through their groups and
1285 + /// upload each one's promotional image.
1286 + Subscriptions {
1287 + #[command(subcommand)]
1288 + command: SubscriptionsCommand,
1289 + },
1290 /// Signing certificates: list what the team holds, issue a new one, or
1291 /// revoke an old one.
1292 Certificates {
@@ -1602,6 +1692,34 @@ async fn run_msstore(
1692 .await
1693 .map_err(fail)?,
1694 ),
1695 + MsStoreCommand::Addons { command } => match command {
1696 + MsStoreAddonsCommand::List { product_id } => print_json(
1697 + &msstore::read_addons(&client, product_id.as_deref())
1698 + .await
1699 + .map_err(fail)?,
1700 + ),
1701 + MsStoreAddonsCommand::SetIcon {
1702 + addon,
1703 + file,
1704 + locale,
1705 + product_id,
1706 + } => {
1707 + let result = msstore::set_addon_icon(
1708 + &client,
1709 + product_id.as_deref(),
1710 + &addon,
1711 + &file,
1712 + locale.as_deref(),
1713 + dry_run,
1714 + )
1715 + .await
1716 + .map_err(fail)?;
1717 + if result.dry_run {
1718 + println!("# dry run: nothing was changed:");
1719 + }
1720 + print_json(&result)
1721 + }
1722 + },
1723 MsStoreCommand::Submissions { command } => match command {
1724 MsStoreSubmissionsCommand::Status { product_id } => print_json(
1725 &msstore::submission_status(&client, product_id.as_deref())
@@ -2036,6 +2154,54 @@ async fn run_play(
2154 .map_err(fail)?,
2155 ),
2156 },
2157 + PlayCommand::Subscriptions { command } => match command {
2158 + PlaySubscriptionsCommand::List { package } => print_json(
2159 + &play::read_subscriptions(&client, &package)
2160 + .await
2161 + .map_err(fail)?,
2162 + ),
2163 + PlaySubscriptionsCommand::Get {
2164 + package,
2165 + product_id,
2166 + } => print_json(
2167 + &play::read_subscription(&client, &package, &product_id)
2168 + .await
2169 + .map_err(fail)?,
2170 + ),
2171 + PlaySubscriptionsCommand::Create {
2172 + package,
2173 + id,
2174 + title,
2175 + description,
2176 + benefit,
2177 + price,
2178 + currency,
2179 + language,
2180 + base_plan_id,
2181 + billing_period,
2182 + grace_period,
2183 + } => {
2184 + let price = PlayMoney::parse(&currency, &price).map_err(|e| fail(e.to_string()))?;
2185 + let subscription = smbcloud_ascapi_play::NewSubscription {
2186 + grace_period,
2187 + package,
2188 + product_id: id,
2189 + language,
2190 + title,
2191 + description,
2192 + benefits: benefit,
2193 + base_plan_id,
2194 + billing_period,
2195 + };
2196 + let result = play::create_subscription(&client, &subscription, &price, dry_run)
2197 + .await
2198 + .map_err(fail)?;
2199 + if result.dry_run {
2200 + println!("# dry run: nothing was created; body that would be sent:");
2201 + }
2202 + print_json(&result)
2203 + }
2204 + },
2205 PlayCommand::Products { command } => match command {
2206 PlayProductsCommand::List { package } => {
2207 print_json(&play::read_products(&client, &package).await.map_err(fail)?)
@@ -2945,6 +3111,29 @@ enum ReviewSubmissionsCommand {
3111 /// `PATCH /v1/reviewSubmissions/{id}` with `canceled: true` — withdraw
3112 /// a submission before App Review picks it up.
3113 Cancel { id: String },
3114 + /// `GET /v1/reviewSubmissions/{id}/items`: what a submission holds (the
3115 + /// version, events, product page versions) and each item's state. Use
3116 + /// it on a submission stuck in UNRESOLVED_ISSUES. The reviewer's message
3117 + /// itself is not in the API; read it in App Store Connect.
3118 + Items { id: String },
3119 +}
3120 +
3121 +#[derive(Subcommand)]
3122 +enum SubscriptionsCommand {
3123 + /// Every auto-renewable subscription of an app, across its subscription
3124 + /// groups, ordered by group level (1 = highest level of service).
3125 + List { app_id: String },
3126 + /// The promotional images a subscription holds.
3127 + Images { id: String },
3128 + /// Upload the 1024x1024 image the App Store shows for the subscription.
3129 + /// A subscription can hold several; --replace deletes the existing ones
3130 + /// first.
3131 + PromotionalImage {
3132 + id: String,
3133 + path: PathBuf,
3134 + #[arg(long)]
3135 + replace: bool,
3136 + },
3137 }
3138
3139 #[derive(Subcommand)]
@@ -3578,6 +3767,9 @@ async fn main() -> Result<()> {
3767 Command::InAppPurchases { command } => {
3768 run_in_app_purchases(&client, command, cli.dry_run).await
3769 }
3770 + Command::Subscriptions { command } => {
3771 + run_subscriptions(&client, command, cli.dry_run).await
3772 + }
3773 Command::Certificates { command } => run_certificates(&client, command, cli.dry_run).await,
3774 Command::Profiles { command } => run_profiles(&client, command, cli.dry_run).await,
3775 Command::ReviewSubmissions { command } => {
@@ -4196,6 +4388,63 @@ async fn run_review_submissions(
4388 }
4389 print_json(&client.cancel_review_submission(&id).await?)
4390 }
4391 + ReviewSubmissionsCommand::Items { id } => {
4392 + print_json(&client.list_review_submission_items(&id).await?)
4393 + }
4394 + }
4395 +}
4396 +
4397 +async fn run_subscriptions(
4398 + client: &Client,
4399 + command: SubscriptionsCommand,
4400 + dry_run: bool,
4401 +) -> Result<()> {
4402 + match command {
4403 + SubscriptionsCommand::List { app_id } => {
4404 + print_json(&client.list_app_subscriptions(&app_id).await?)
4405 + }
4406 + SubscriptionsCommand::Images { id } => {
4407 + print_json(&client.list_subscription_images(&id).await?)
4408 + }
4409 + SubscriptionsCommand::PromotionalImage { id, path, replace } => {
4410 + let bytes =
4411 + std::fs::read(&path).with_context(|| format!("cannot read {}", path.display()))?;
4412 + let file_name = path
4413 + .file_name()
4414 + .and_then(|n| n.to_str())
4415 + .context("the image path has no file name")?
4416 + .to_string();
4417 + let existing = client.list_subscription_images(&id).await?;
4418 + if !existing.is_empty() && !replace {
4419 + anyhow::bail!(
4420 + "{id} already has {} promotional image(s); pass --replace",
4421 + existing.len()
4422 + );
4423 + }
4424 + if dry_run {
4425 + println!(
4426 + "# dry run: would {}upload {file_name} ({} bytes) as the image of subscription {id}",
4427 + if existing.is_empty() { "" } else { "delete the current images and " },
4428 + bytes.len()
4429 + );
4430 + return Ok(());
4431 + }
4432 + for old in &existing {
4433 + client.delete_subscription_image(&old.id).await?;
4434 + }
4435 + let uploaded = client
4436 + .upload_subscription_image(&id, file_name, bytes)
4437 + .await?;
4438 + let back = client.list_subscription_images(&id).await?;
4439 + if !back.iter().any(|i| i.id == uploaded.id) {
4440 + anyhow::bail!(
4441 + "the image was committed but {} does not list it ({})",
4442 + id,
4443 + uploaded.id
4444 + );
4445 + }
4446 + print_json(&back)
4447 + }
4448 }
4449 }
4450
crates/iap/src/lib.rs
+5
@@ -17,6 +17,9 @@
17 //! A promotional image ([`promotional_image`]) is optional: it only feeds
18 //! the App Store product page.
19 //!
20 +//! Auto-renewable subscriptions live in [`subscription`]: listed through
21 +//! their subscription groups, with their own promotional image resource.
22 +//!
23 //! With those in place the product reaches `READY_TO_SUBMIT`. An app's
24 //! first in-app purchase is reviewed together with an app version, which is
25 //! done on the version page, so this crate has no submit call.
@@ -30,6 +33,7 @@ pub mod localization;
33 pub mod price;
34 pub mod promotional_image;
35 pub mod review_screenshot;
36 +pub mod subscription;
37
38 /// Every extension trait in this crate, for one glob import.
39 pub mod prelude {
@@ -39,4 +43,5 @@ pub mod prelude {
43 pub use crate::price::InAppPurchasePricesApi;
44 pub use crate::promotional_image::InAppPurchasePromotionalImageApi;
45 pub use crate::review_screenshot::InAppPurchaseReviewScreenshotApi;
46 + pub use crate::subscription::SubscriptionsApi;
47 }
crates/iap/src/subscription.rs new
+287
@@ -0,0 +1,287 @@
1 +//! Auto-renewable subscriptions: the `subscriptionGroups` an app holds, the
2 +//! `subscriptions` in each group, and each subscription's 1024x1024
3 +//! promotional image (`subscriptionImages`).
4 +//!
5 +//! Subscriptions are a different resource from the one-time products in
6 +//! [`crate::in_app_purchase`], and are listed through their group rather
7 +//! than the app. The image upload is the same reserve, PUT, commit sequence
8 +//! as [`crate::promotional_image`], with a `subscription` relationship.
9 +
10 +use async_trait::async_trait;
11 +use reqwest::Method;
12 +use serde::{Deserialize, Serialize};
13 +use smbcloud_ascapi_core::jsonapi::{
14 + CreateBody, CreateData, Document, Resource, ResourceId, ToOne, UpdateBody, UpdateData,
15 +};
16 +use smbcloud_ascapi_core::{Client, Result};
17 +
18 +use crate::review_screenshot::{null_as_default, upload_operations, UploadOperation};
19 +
20 +pub const GROUP_RESOURCE_TYPE: &str = "subscriptionGroups";
21 +pub const RESOURCE_TYPE: &str = "subscriptions";
22 +pub const IMAGE_RESOURCE_TYPE: &str = "subscriptionImages";
23 +
24 +#[derive(Debug, Clone, Default, Serialize, Deserialize)]
25 +#[serde(rename_all = "camelCase")]
26 +pub struct SubscriptionGroupAttributes {
27 + #[serde(default)]
28 + pub reference_name: Option<String>,
29 +}
30 +
31 +pub type SubscriptionGroup = Resource<SubscriptionGroupAttributes>;
32 +
33 +#[derive(Debug, Clone, Default, Serialize, Deserialize)]
34 +#[serde(rename_all = "camelCase")]
35 +pub struct SubscriptionAttributes {
36 + #[serde(default)]
37 + pub name: Option<String>,
38 + #[serde(default)]
39 + pub product_id: Option<String>,
40 + /// e.g. `MISSING_METADATA`, `READY_TO_SUBMIT`, `WAITING_FOR_REVIEW`,
41 + /// `APPROVED`, `REJECTED`, `DEVELOPER_ACTION_NEEDED`.
42 + #[serde(default)]
43 + pub state: Option<String>,
44 + #[serde(default)]
45 + pub subscription_period: Option<String>,
46 + /// 1 is the highest level of service in the group.
47 + #[serde(default)]
48 + pub group_level: Option<u32>,
49 + #[serde(default)]
50 + pub family_sharable: Option<bool>,
51 + #[serde(default)]
52 + pub review_note: Option<String>,
53 +}
54 +
55 +pub type Subscription = Resource<SubscriptionAttributes>;
56 +
57 +#[derive(Debug, Clone, Default, Serialize, Deserialize)]
58 +#[serde(rename_all = "camelCase")]
59 +pub struct SubscriptionImageAttributes {
60 + #[serde(default)]
61 + pub file_name: Option<String>,
62 + #[serde(default)]
63 + pub file_size: Option<u64>,
64 + #[serde(default)]
65 + pub source_file_checksum: Option<String>,
66 + #[serde(default)]
67 + pub state: Option<String>,
68 + #[serde(default, deserialize_with = "null_as_default")]
69 + pub upload_operations: Vec<UploadOperation>,
70 +}
71 +
72 +pub type SubscriptionImage = Resource<SubscriptionImageAttributes>;
73 +
74 +/// One subscription together with the group it belongs to, which is what
75 +/// `subscriptions list` prints.
76 +#[derive(Debug, Clone, Serialize)]
77 +#[serde(rename_all = "camelCase")]
78 +pub struct GroupedSubscription {
79 + pub group_id: String,
80 + pub group_name: Option<String>,
81 + #[serde(flatten)]
82 + pub subscription: Subscription,
83 +}
84 +
85 +#[derive(Debug, Clone, Serialize)]
86 +#[serde(rename_all = "camelCase")]
87 +struct CreateImageAttributes {
88 + file_name: String,
89 + file_size: u64,
90 +}
91 +
92 +#[derive(Debug, Clone, Serialize)]
93 +#[serde(rename_all = "camelCase")]
94 +struct CreateImageRelationships {
95 + subscription: ToOne,
96 +}
97 +
98 +#[derive(Debug, Clone, Serialize)]
99 +#[serde(rename_all = "camelCase")]
100 +struct CommitAttributes {
101 + uploaded: bool,
102 + source_file_checksum: String,
103 +}
104 +
105 +/// The image reserve (`POST /v1/subscriptionImages`) body.
106 +pub fn create_image_body(
107 + subscription_id: &str,
108 + file_name: &str,
109 + file_size: u64,
110 +) -> impl Serialize + Send + Sync {
111 + CreateBody {
112 + data: CreateData {
113 + resource_type: IMAGE_RESOURCE_TYPE,
114 + attributes: CreateImageAttributes {
115 + file_name: file_name.to_string(),
116 + file_size,
117 + },
118 + relationships: Some(CreateImageRelationships {
119 + subscription: ToOne {
120 + data: ResourceId {
121 + resource_type: RESOURCE_TYPE,
122 + id: subscription_id.to_string(),
123 + },
124 + },
125 + }),
126 + },
127 + }
128 +}
129 +
130 +#[async_trait]
131 +pub trait SubscriptionsApi {
132 + /// `GET /v1/apps/{id}/subscriptionGroups`.
133 + async fn list_subscription_groups(&self, app_id: &str) -> Result<Vec<SubscriptionGroup>>;
134 +
135 + /// `GET /v1/subscriptionGroups/{id}/subscriptions`.
136 + async fn list_group_subscriptions(&self, group_id: &str) -> Result<Vec<Subscription>>;
137 +
138 + /// Every subscription of an app, across all its groups.
139 + async fn list_app_subscriptions(&self, app_id: &str) -> Result<Vec<GroupedSubscription>>;
140 +
141 + /// `GET /v1/subscriptions/{id}/images`.
142 + async fn list_subscription_images(
143 + &self,
144 + subscription_id: &str,
145 + ) -> Result<Vec<SubscriptionImage>>;
146 +
147 + /// `DELETE /v1/subscriptionImages/{id}`.
148 + async fn delete_subscription_image(&self, id: &str) -> Result<()>;
149 +
150 + /// Reserve, upload and commit `bytes` as a subscription's image.
151 + async fn upload_subscription_image(
152 + &self,
153 + subscription_id: &str,
154 + file_name: String,
155 + bytes: Vec<u8>,
156 + ) -> Result<SubscriptionImage>;
157 +}
158 +
159 +#[async_trait]
160 +impl SubscriptionsApi for Client {
161 + async fn list_subscription_groups(&self, app_id: &str) -> Result<Vec<SubscriptionGroup>> {
162 + let path = format!("/v1/apps/{app_id}/subscriptionGroups");
163 + self.list_all::<SubscriptionGroupAttributes>(&path, &[("limit", "200")])
164 + .await
165 + }
166 +
167 + async fn list_group_subscriptions(&self, group_id: &str) -> Result<Vec<Subscription>> {
168 + let path = format!("/v1/subscriptionGroups/{group_id}/subscriptions");
169 + self.list_all::<SubscriptionAttributes>(&path, &[("limit", "200")])
170 + .await
171 + }
172 +
173 + async fn list_app_subscriptions(&self, app_id: &str) -> Result<Vec<GroupedSubscription>> {
174 + let mut rows = Vec::new();
175 + for group in self.list_subscription_groups(app_id).await? {
176 + for subscription in self.list_group_subscriptions(&group.id).await? {
177 + rows.push(GroupedSubscription {
178 + group_id: group.id.clone(),
179 + group_name: group.attributes.reference_name.clone(),
180 + subscription,
181 + });
182 + }
183 + }
184 + rows.sort_by_key(|row| row.subscription.attributes.group_level.unwrap_or(u32::MAX));
185 + Ok(rows)
186 + }
187 +
188 + async fn list_subscription_images(
189 + &self,
190 + subscription_id: &str,
191 + ) -> Result<Vec<SubscriptionImage>> {
192 + let path = format!("/v1/subscriptions/{subscription_id}/images");
193 + self.list_all::<SubscriptionImageAttributes>(&path, &[("limit", "200")])
194 + .await
195 + }
196 +
197 + async fn delete_subscription_image(&self, id: &str) -> Result<()> {
198 + let path = format!("/v1/subscriptionImages/{id}");
199 + self.request_no_content::<()>(Method::DELETE, &path, &[], None)
200 + .await
201 + }
202 +
203 + async fn upload_subscription_image(
204 + &self,
205 + subscription_id: &str,
206 + file_name: String,
207 + bytes: Vec<u8>,
208 + ) -> Result<SubscriptionImage> {
209 + let checksum = format!("{:x}", md5::compute(&bytes));
210 + let body = create_image_body(subscription_id, &file_name, bytes.len() as u64);
211 + let reserved: Document<SubscriptionImageAttributes> = self
212 + .request(Method::POST, "/v1/subscriptionImages", &[], Some(&body))
213 + .await?;
214 + let reserved = reserved.data;
215 +
216 + upload_operations(self, &reserved.attributes.upload_operations, &bytes).await?;
217 +
218 + let path = format!("/v1/subscriptionImages/{}", reserved.id);
219 + let commit = UpdateBody {
220 + data: UpdateData {
221 + resource_type: IMAGE_RESOURCE_TYPE,
222 + id: reserved.id.clone(),
223 + attributes: CommitAttributes {
224 + uploaded: true,
225 + source_file_checksum: checksum,
226 + },
227 + },
228 + };
229 + let doc: Document<SubscriptionImageAttributes> = self
230 + .request(Method::PATCH, &path, &[], Some(&commit))
231 + .await?;
232 + Ok(doc.data)
233 + }
234 +}
235 +
236 +#[cfg(test)]
237 +mod tests {
238 + use super::*;
239 +
240 + #[test]
241 + fn the_image_reserve_body_names_the_subscription_relationship() {
242 + let v = serde_json::to_value(create_image_body("SUB1", "pro.png", 42)).unwrap();
243 + assert_eq!(v["data"]["type"], "subscriptionImages");
244 + assert_eq!(v["data"]["attributes"]["fileName"], "pro.png");
245 + assert_eq!(v["data"]["attributes"]["fileSize"], 42);
246 + assert_eq!(
247 + v["data"]["relationships"]["subscription"]["data"]["type"],
248 + "subscriptions"
249 + );
250 + assert_eq!(
251 + v["data"]["relationships"]["subscription"]["data"]["id"],
252 + "SUB1"
253 + );
254 + }
255 +
256 + #[test]
257 + fn a_subscription_row_deserializes_and_flattens_with_its_group() {
258 + let sub: Subscription = serde_json::from_value(serde_json::json!({
259 + "id": "S1", "type": "subscriptions",
260 + "attributes": { "name": "Business Monthly", "productId": "business_business_monthly",
261 + "state": "APPROVED", "subscriptionPeriod": "ONE_MONTH", "groupLevel": 2 }
262 + }))
263 + .unwrap();
264 + let row = GroupedSubscription {
265 + group_id: "G1".into(),
266 + group_name: Some("smbCloud Mail Pro".into()),
267 + subscription: sub,
268 + };
269 + let v = serde_json::to_value(&row).unwrap();
270 + assert_eq!(v["groupName"], "smbCloud Mail Pro");
271 + assert_eq!(v["id"], "S1");
272 + assert_eq!(v["attributes"]["productId"], "business_business_monthly");
273 + assert_eq!(v["attributes"]["groupLevel"], 2);
274 + }
275 +
276 + #[test]
277 + fn a_committed_subscription_image_with_null_operations_deserializes() {
278 + let doc: Document<SubscriptionImageAttributes> =
279 + serde_json::from_value(serde_json::json!({
280 + "data": { "id": "I1", "type": IMAGE_RESOURCE_TYPE,
281 + "attributes": { "fileName": "pro.png", "fileSize": 10,
282 + "uploadOperations": null, "state": "UPLOAD_COMPLETE" } }
283 + }))
284 + .unwrap();
285 + assert!(doc.data.attributes.upload_operations.is_empty());
286 + }
287 +}