Skip to main content

faker_rust/default/
subscription.rs

1//! Subscription generator
2
3use crate::base::sample;
4use crate::locale::fetch_locale;
5
6/// Generate a random subscription plan
7pub fn plan() -> String {
8    fetch_locale("subscription.plans", "en")
9        .map(|v| sample(&v))
10        .unwrap_or_else(|| sample(FALLBACK_PLANS).to_string())
11}
12
13/// Generate a random subscription status
14pub fn status() -> String {
15    fetch_locale("subscription.statuses", "en")
16        .map(|v| sample(&v))
17        .unwrap_or_else(|| sample(FALLBACK_STATUSES).to_string())
18}
19
20/// Generate a random payment method
21pub fn payment_method() -> String {
22    fetch_locale("subscription.payment_methods", "en")
23        .map(|v| sample(&v))
24        .unwrap_or_else(|| sample(FALLBACK_PAYMENT_METHODS).to_string())
25}
26
27// Fallback data
28const FALLBACK_PLANS: &[&str] = &[
29    "Free", "Basic", "Standard", "Premium", "Pro", "Enterprise", "Starter",
30    "Gold", "Silver", "Bronze", "Platinum", "Ultimate",
31];
32
33const FALLBACK_STATUSES: &[&str] = &[
34    "active", "inactive", "pending", "canceled", "expired", "suspended",
35    "trial", "past_due",
36];
37
38const FALLBACK_PAYMENT_METHODS: &[&str] = &[
39    "Credit Card", "Debit Card", "PayPal", "Bank Transfer", "Apple Pay",
40    "Google Pay", "Cryptocurrency", "Direct Debit", "Check",
41];
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_plan() {
49        assert!(!plan().is_empty());
50    }
51
52    #[test]
53    fn test_status() {
54        assert!(!status().is_empty());
55    }
56
57    #[test]
58    fn test_payment_method() {
59        assert!(!payment_method().is_empty());
60    }
61}