use redis_cloud::account::PaymentMethods;
use redis_cloud::databases::Database;
use redis_cloud::fixed_databases::AccountFixedSubscriptionDatabases;
use redis_cloud::fixed_subscriptions::FixedSubscription;
use redis_cloud::subscriptions::AccountSubscriptions;
use redis_cloud::types::{TaskStateUpdate, TaskStatus};
#[test]
fn fixed_databases_response_deserializes() {
let raw = include_str!("fixtures/cloud/samples/fixed_databases.json");
let resp: AccountFixedSubscriptionDatabases =
serde_json::from_str(raw).expect("fixed databases fixture should deserialize");
let db = resp
.subscription
.and_then(|s| s.databases.into_iter().next())
.expect("fixture should contain a database");
assert_eq!(db.network_monthly_usage_in_byte, Some(1.83615528E+10));
let modules = db.modules.expect("modules should deserialize");
assert_eq!(modules.len(), 2);
assert_eq!(modules[0].parameters, Some(serde_json::json!([])));
assert_eq!(
modules[1].parameters,
Some(serde_json::json!([{ "name": "error_rate", "value": "0.01" }]))
);
assert_eq!(modules[0].id, Some(333333));
assert_eq!(modules[0].capability_name.as_deref(), Some("Time series"));
assert_eq!(modules[0].version.as_deref(), Some("8.2.9"));
let alerts = db.alerts.expect("alerts should deserialize");
assert_eq!(alerts[0].default_value, Some(80));
assert!(db.replica_as_source_endpoints.is_some());
let security = db
.security
.expect("security object should deserialize (see #121)");
assert_eq!(security.source_ips, Some(vec!["0.0.0.0/0".to_string()]));
assert_eq!(security.enable_tls, Some(false));
assert_eq!(security.default_user_enabled, Some(false));
let clustering = db.clustering.expect("clustering object should deserialize");
assert_eq!(clustering.enabled, Some(false));
assert_eq!(clustering.regex_rules.as_ref().map(Vec::len), Some(2));
assert_eq!(clustering.hashing_policy.as_deref(), Some("standard"));
let backup = db.backup.expect("backup object should deserialize");
assert_eq!(backup.remote_backup_enabled, Some(false));
}
#[test]
fn pro_database_response_deserializes() {
let raw = include_str!("fixtures/cloud/samples/pro_database.json");
let db: Database = serde_json::from_str(raw).expect("pro database fixture should deserialize");
assert_eq!(db.database_id, 222333);
assert_eq!(db.support_oss_cluster_api, Some(false));
assert_eq!(db.use_external_endpoint_for_oss_cluster_api, Some(false));
let security = db
.security
.expect("security object should deserialize (see #121)");
assert_eq!(security.source_ips, Some(vec!["0.0.0.0/0".to_string()]));
assert_eq!(security.enable_default_user, Some(true));
assert_eq!(security.enable_tls, Some(false));
let clustering = db.clustering.expect("clustering object should deserialize");
assert_eq!(clustering.number_of_shards, Some(1));
assert_eq!(clustering.regex_rules.as_ref().map(Vec::len), Some(2));
let backup = db.backup.expect("backup object should deserialize");
assert_eq!(backup.enable_remote_backup, Some(false));
assert_eq!(backup.interval.as_deref(), Some("every-12-hours"));
assert_eq!(backup.time_utc.as_deref(), Some("14:00"));
}
#[test]
fn payment_methods_response_deserializes() {
let raw = include_str!("fixtures/cloud/samples/payment_methods.json");
let resp: PaymentMethods =
serde_json::from_str(raw).expect("payment methods fixture should deserialize");
let methods = resp
.payment_methods
.expect("should contain payment methods");
assert_eq!(methods.len(), 1);
assert_eq!(methods[0].credit_card_ends_with.as_deref(), Some("1234"));
}
#[test]
fn cost_report_task_response_deserializes() {
let raw = include_str!("fixtures/cloud/samples/cost_report_task.json");
let task: TaskStateUpdate =
serde_json::from_str(raw).expect("cost-report task fixture should deserialize");
assert!(matches!(task.status, Some(TaskStatus::ProcessingCompleted)));
let report_id = task
.response
.and_then(|r| r.resource)
.and_then(|res| res.get("costReportId").cloned())
.and_then(|v| v.as_str().map(str::to_string))
.expect("response.resource.costReportId should be present");
assert!(report_id.ends_with(".csv"));
}
#[test]
fn fixed_subscription_response_deserializes() {
let raw = include_str!("fixtures/cloud/samples/fixed_subscription.json");
let sub: FixedSubscription =
serde_json::from_str(raw).expect("fixed subscription fixture should deserialize");
assert_eq!(sub.id, Some(111111));
assert_eq!(sub.connections.as_deref(), Some("10000"));
assert_eq!(sub.database_status.as_deref(), Some("active"));
}
#[test]
fn pro_subscriptions_response_deserializes() {
let raw = include_str!("fixtures/cloud/samples/pro_subscriptions.json");
let resp: AccountSubscriptions =
serde_json::from_str(raw).expect("pro subscriptions fixture should deserialize");
let sub = resp
.subscriptions
.and_then(|s| s.into_iter().next())
.expect("fixture should contain a subscription");
let pricing = sub
.subscription_pricing
.expect("subscriptionPricing should deserialize (see #128)");
assert_eq!(pricing.len(), 2);
assert_eq!(pricing[0].r#type.as_deref(), Some("MinimumPrice"));
let cloud = sub
.cloud_details
.and_then(|c| c.into_iter().next())
.expect("cloudDetails should deserialize");
assert!(cloud.resource_tags.is_some());
assert!(cloud.links.is_some());
let net = cloud
.regions
.and_then(|r| r.into_iter().next())
.and_then(|r| r.networking)
.and_then(|n| n.into_iter().next())
.expect("networking should deserialize");
assert_eq!(net.deployment_cidr.as_deref(), Some("192.168.0.0/26"));
assert!(net.security_group_id.is_some());
}