| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
use crate::common::*; |
| 10 |
use synckit_client::BillingInterval; |
| 11 |
|
| 12 |
const SUBSCRIPTION_PATH: &str = "/api/v1/sync/subscription"; |
| 13 |
const STORAGE_CAP_PATH: &str = "/api/v1/sync/subscription/storage-cap"; |
| 14 |
|
| 15 |
#[tokio::test] |
| 16 |
async fn subscription_status_parses_every_field() { |
| 17 |
let kit = MockKit::start().await; |
| 18 |
kit.get(SUBSCRIPTION_PATH) |
| 19 |
.json(json!({ |
| 20 |
"active": true, |
| 21 |
|
| 22 |
"tier": "annual", |
| 23 |
"status": "active", |
| 24 |
"storage_limit_bytes": 10_737_418_240i64, |
| 25 |
"pending_storage_limit_bytes": serde_json::Value::Null, |
| 26 |
"storage_used_bytes": 4_096i64, |
| 27 |
"current_period_end": "2026-09-01T00:00:00Z", |
| 28 |
})) |
| 29 |
.await; |
| 30 |
|
| 31 |
let status = kit |
| 32 |
.authed() |
| 33 |
.get_subscription_status() |
| 34 |
.await |
| 35 |
.expect("a 200 with a full body parses"); |
| 36 |
|
| 37 |
assert!(status.active); |
| 38 |
assert_eq!(status.interval, Some(BillingInterval::Annual)); |
| 39 |
assert_eq!(status.status.as_deref(), Some("active")); |
| 40 |
assert_eq!(status.storage_limit_bytes, Some(10_737_418_240)); |
| 41 |
assert_eq!(status.pending_storage_limit_bytes, None); |
| 42 |
assert_eq!(status.storage_used_bytes, Some(4_096)); |
| 43 |
assert_eq!( |
| 44 |
status.current_period_end.as_deref(), |
| 45 |
Some("2026-09-01T00:00:00Z") |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
#[tokio::test] |
| 50 |
async fn queue_storage_cap_change_sends_the_cap_and_reads_back_the_pending_one() { |
| 51 |
let kit = MockKit::start().await; |
| 52 |
kit.post(STORAGE_CAP_PATH) |
| 53 |
.json(json!({ |
| 54 |
"active": true, |
| 55 |
"tier": "monthly", |
| 56 |
"status": "active", |
| 57 |
"storage_limit_bytes": 10_737_418_240i64, |
| 58 |
|
| 59 |
|
| 60 |
"pending_storage_limit_bytes": 21_474_836_480i64, |
| 61 |
"storage_used_bytes": 4_096i64, |
| 62 |
"current_period_end": "2026-09-01T00:00:00Z", |
| 63 |
})) |
| 64 |
.await; |
| 65 |
|
| 66 |
let status = kit |
| 67 |
.authed() |
| 68 |
.queue_storage_cap_change(21_474_836_480) |
| 69 |
.await |
| 70 |
.expect("a 200 with a full body parses"); |
| 71 |
|
| 72 |
assert_eq!(status.interval, Some(BillingInterval::Monthly)); |
| 73 |
assert_eq!(status.storage_limit_bytes, Some(10_737_418_240)); |
| 74 |
assert_eq!(status.pending_storage_limit_bytes, Some(21_474_836_480)); |
| 75 |
|
| 76 |
let body = kit.body(STORAGE_CAP_PATH).await; |
| 77 |
assert_eq!(body["cap_bytes"], 21_474_836_480i64); |
| 78 |
} |
| 79 |
|