//! Subscription status and the queued storage-cap change. //! //! Both calls return the same `SubscriptionStatus` shape, and both are only //! useful if the fields survive the round trip: `active` gates whether an app //! syncs at all, and `pending_storage_limit_bytes` is the whole answer to //! "did the cap change take". Asserting `Ok` alone would pass on a default //! `SubscriptionStatus`. use crate::common::*; use synckit_client::BillingInterval; const SUBSCRIPTION_PATH: &str = "/api/v1/sync/subscription"; const STORAGE_CAP_PATH: &str = "/api/v1/sync/subscription/storage-cap"; #[tokio::test] async fn subscription_status_parses_every_field() { let kit = MockKit::start().await; kit.get(SUBSCRIPTION_PATH) .json(json!({ "active": true, // The interval travels under the legacy `tier` field name. "tier": "annual", "status": "active", "storage_limit_bytes": 10_737_418_240i64, "pending_storage_limit_bytes": serde_json::Value::Null, "storage_used_bytes": 4_096i64, "current_period_end": "2026-09-01T00:00:00Z", })) .await; let status = kit .authed() .get_subscription_status() .await .expect("a 200 with a full body parses"); assert!(status.active); assert_eq!(status.interval, Some(BillingInterval::Annual)); assert_eq!(status.status.as_deref(), Some("active")); assert_eq!(status.storage_limit_bytes, Some(10_737_418_240)); assert_eq!(status.pending_storage_limit_bytes, None); assert_eq!(status.storage_used_bytes, Some(4_096)); assert_eq!( status.current_period_end.as_deref(), Some("2026-09-01T00:00:00Z") ); } #[tokio::test] async fn queue_storage_cap_change_sends_the_cap_and_reads_back_the_pending_one() { let kit = MockKit::start().await; kit.post(STORAGE_CAP_PATH) .json(json!({ "active": true, "tier": "monthly", "status": "active", "storage_limit_bytes": 10_737_418_240i64, // The queued cap applies at the next cycle, so the current limit is // unchanged and this is the only field carrying the new number. "pending_storage_limit_bytes": 21_474_836_480i64, "storage_used_bytes": 4_096i64, "current_period_end": "2026-09-01T00:00:00Z", })) .await; let status = kit .authed() .queue_storage_cap_change(21_474_836_480) .await .expect("a 200 with a full body parses"); assert_eq!(status.interval, Some(BillingInterval::Monthly)); assert_eq!(status.storage_limit_bytes, Some(10_737_418_240)); assert_eq!(status.pending_storage_limit_bytes, Some(21_474_836_480)); let body = kit.body(STORAGE_CAP_PATH).await; assert_eq!(body["cap_bytes"], 21_474_836_480i64); }