Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions crates/aso/src/beta_app_review_submission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
use async_trait::async_trait;
use reqwest::Method;
use serde::{Deserialize, Serialize};
use smbcloud_ascapi_core::jsonapi::{
CreateBody, CreateData, Document, ListDocument, Resource, ResourceId, ToOne,
};
use smbcloud_ascapi_core::jsonapi::{Document, ListDocument, Resource, ResourceId, ToOne};
use smbcloud_ascapi_core::Client;
use smbcloud_ascapi_core::Result;

Expand Down Expand Up @@ -51,6 +49,23 @@ pub type BetaAppReviewSubmission = Resource<BetaAppReviewSubmissionAttributes>;

// ── internal create helper ────────────────────────────────────────────────────

/// A beta app review submission carries only a `build` relationship. Apple's
/// endpoint rejects a request whose `data.attributes` is present but null
/// (422 `ENTITY_UNPROCESSABLE`), so this body omits the field entirely rather
/// than reusing [`smbcloud_ascapi_core::jsonapi::CreateBody`] with `()`
/// attributes.
#[derive(Debug, Clone, Serialize)]
struct CreateBody {
Comment thread
setoelkahfi marked this conversation as resolved.
data: CreateData,
}

#[derive(Debug, Clone, Serialize)]
struct CreateData {
#[serde(rename = "type")]
resource_type: &'static str,
relationships: CreateRelationships,
}

#[derive(Debug, Clone, Serialize)]
struct CreateRelationships {
build: ToOne,
Expand Down Expand Up @@ -99,15 +114,14 @@ impl BetaAppReviewSubmissionsApi for Client {
let body = CreateBody {
data: CreateData {
resource_type: RESOURCE_TYPE,
attributes: (),
relationships: Some(CreateRelationships {
relationships: CreateRelationships {
build: ToOne {
data: ResourceId {
resource_type: crate::build::RESOURCE_TYPE,
id: build_id.to_string(),
},
},
}),
},
},
};
let doc: Document<BetaAppReviewSubmissionAttributes> = self
Expand Down Expand Up @@ -196,17 +210,31 @@ mod tests {
}

#[test]
fn create_body_attributes_unit_serializes() {
// The create body has no attributes — verify `()` round-trips cleanly.
fn create_body_omits_attributes() {
Comment thread
setoelkahfi marked this conversation as resolved.
// Apple's endpoint 422s on a null `data.attributes`; the body must omit
// the field entirely and carry only the `build` relationship.
let body = CreateBody {
data: CreateData {
resource_type: RESOURCE_TYPE,
attributes: (),
relationships: None::<()>,
relationships: CreateRelationships {
build: ToOne {
data: ResourceId {
resource_type: crate::build::RESOURCE_TYPE,
id: "BUILD_ID".to_string(),
},
},
},
},
};
let v = serde_json::to_value(&body).unwrap();
// `()` serialises as `null`; the key is present in the object.
assert!(v["data"]["attributes"].is_null());
assert!(
v["data"].get("attributes").is_none(),
"attributes must be omitted, not null: {v}"
);
assert_eq!(v["data"]["type"], RESOURCE_TYPE);
assert_eq!(
v["data"]["relationships"]["build"]["data"]["id"],
"BUILD_ID"
);
}
}
Loading