| 1 |
use super::*; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#[test] |
| 6 |
fn label_basic() { |
| 7 |
assert_eq!(CreatorTier::Basic.label(), "Basic"); |
| 8 |
} |
| 9 |
|
| 10 |
#[test] |
| 11 |
fn label_small_files() { |
| 12 |
assert_eq!(CreatorTier::SmallFiles.label(), "Small Files"); |
| 13 |
} |
| 14 |
|
| 15 |
#[test] |
| 16 |
fn label_big_files() { |
| 17 |
assert_eq!(CreatorTier::BigFiles.label(), "Big Files"); |
| 18 |
} |
| 19 |
|
| 20 |
#[test] |
| 21 |
fn label_everything() { |
| 22 |
assert_eq!(CreatorTier::Everything.label(), "Everything"); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
fn all_tiers() -> [CreatorTier; 4] { |
| 35 |
[ |
| 36 |
CreatorTier::Basic, |
| 37 |
CreatorTier::SmallFiles, |
| 38 |
CreatorTier::BigFiles, |
| 39 |
CreatorTier::Everything, |
| 40 |
] |
| 41 |
} |
| 42 |
|
| 43 |
#[test] |
| 44 |
fn prices_positive_and_strictly_increasing() { |
| 45 |
crate::tier_prices::TierPrices::install_test_default(); |
| 46 |
let tiers = all_tiers(); |
| 47 |
assert!(tiers[0].price_cents() > 0); |
| 48 |
for pair in tiers.windows(2) { |
| 49 |
assert!( |
| 50 |
pair[0].price_cents() < pair[1].price_cents(), |
| 51 |
"{:?} should cost less than {:?}", |
| 52 |
pair[0], |
| 53 |
pair[1], |
| 54 |
); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
#[test] |
| 59 |
fn max_file_bytes_non_decreasing() { |
| 60 |
crate::tier_prices::TierPrices::install_test_default(); |
| 61 |
let tiers = all_tiers(); |
| 62 |
assert!(tiers[0].max_file_bytes() > 0); |
| 63 |
for pair in tiers.windows(2) { |
| 64 |
assert!( |
| 65 |
pair[0].max_file_bytes() <= pair[1].max_file_bytes(), |
| 66 |
"{:?} file limit should not exceed {:?}", |
| 67 |
pair[0], |
| 68 |
pair[1], |
| 69 |
); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
#[test] |
| 74 |
fn max_storage_bytes_non_decreasing() { |
| 75 |
crate::tier_prices::TierPrices::install_test_default(); |
| 76 |
let tiers = all_tiers(); |
| 77 |
assert!(tiers[0].max_storage_bytes() > 0); |
| 78 |
for pair in tiers.windows(2) { |
| 79 |
assert!( |
| 80 |
pair[0].max_storage_bytes() <= pair[1].max_storage_bytes(), |
| 81 |
"{:?} storage limit should not exceed {:?}", |
| 82 |
pair[0], |
| 83 |
pair[1], |
| 84 |
); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
#[test] |
| 89 |
fn top_tier_matches_big_files_envelope() { |
| 90 |
|
| 91 |
|
| 92 |
crate::tier_prices::TierPrices::install_test_default(); |
| 93 |
assert_eq!( |
| 94 |
CreatorTier::Everything.max_file_bytes(), |
| 95 |
CreatorTier::BigFiles.max_file_bytes(), |
| 96 |
); |
| 97 |
assert_eq!( |
| 98 |
CreatorTier::Everything.max_storage_bytes(), |
| 99 |
CreatorTier::BigFiles.max_storage_bytes(), |
| 100 |
); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
#[test] |
| 106 |
fn basic_tier_disallows_file_uploads() { |
| 107 |
assert!(!CreatorTier::Basic.allows_file_uploads()); |
| 108 |
} |
| 109 |
|
| 110 |
#[test] |
| 111 |
fn small_files_allows_file_uploads() { |
| 112 |
assert!(CreatorTier::SmallFiles.allows_file_uploads()); |
| 113 |
} |
| 114 |
|
| 115 |
#[test] |
| 116 |
fn big_files_allows_file_uploads() { |
| 117 |
assert!(CreatorTier::BigFiles.allows_file_uploads()); |
| 118 |
} |
| 119 |
|
| 120 |
#[test] |
| 121 |
fn everything_allows_file_uploads() { |
| 122 |
assert!(CreatorTier::Everything.allows_file_uploads()); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
#[test] |
| 128 |
fn format_bytes_zero() { |
| 129 |
assert_eq!(format_bytes(0), "0 B"); |
| 130 |
} |
| 131 |
|
| 132 |
#[test] |
| 133 |
fn format_bytes_one_byte() { |
| 134 |
assert_eq!(format_bytes(1), "1 B"); |
| 135 |
} |
| 136 |
|
| 137 |
#[test] |
| 138 |
fn format_bytes_below_kb() { |
| 139 |
assert_eq!(format_bytes(1023), "1023 B"); |
| 140 |
} |
| 141 |
|
| 142 |
#[test] |
| 143 |
fn format_bytes_exactly_1kb() { |
| 144 |
assert_eq!(format_bytes(1024), "1.0 KB"); |
| 145 |
} |
| 146 |
|
| 147 |
#[test] |
| 148 |
fn format_bytes_exactly_1mb() { |
| 149 |
assert_eq!(format_bytes(1024 * 1024), "1.0 MB"); |
| 150 |
} |
| 151 |
|
| 152 |
#[test] |
| 153 |
fn format_bytes_exactly_1gb() { |
| 154 |
assert_eq!(format_bytes(1024 * 1024 * 1024), "1.0 GB"); |
| 155 |
} |
| 156 |
|
| 157 |
#[test] |
| 158 |
fn format_bytes_negative_clamped_to_zero() { |
| 159 |
assert_eq!(format_bytes(-999), "0 B"); |
| 160 |
} |
| 161 |
|
| 162 |
#[test] |
| 163 |
fn format_bytes_large_storage_cap() { |
| 164 |
|
| 165 |
assert_eq!(format_bytes(500 * 1024 * 1024 * 1024), "500.0 GB"); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
#[test] |
| 171 |
fn storage_breakdown_default_is_all_zeros() { |
| 172 |
let sb = StorageBreakdown::default(); |
| 173 |
assert_eq!(sb.audio_bytes, 0); |
| 174 |
assert_eq!(sb.cover_bytes, 0); |
| 175 |
assert_eq!(sb.download_bytes, 0); |
| 176 |
assert_eq!(sb.insertion_bytes, 0); |
| 177 |
assert_eq!(sb.video_bytes, 0); |
| 178 |
assert_eq!(sb.media_bytes, 0); |
| 179 |
assert_eq!(sb.total_bytes, 0); |
| 180 |
} |
| 181 |
|
| 182 |
#[test] |
| 183 |
fn storage_breakdown_total_is_sum_of_categories() { |
| 184 |
let sb = StorageBreakdown { |
| 185 |
audio_bytes: 100, |
| 186 |
cover_bytes: 200, |
| 187 |
download_bytes: 300, |
| 188 |
insertion_bytes: 400, |
| 189 |
video_bytes: 500, |
| 190 |
media_bytes: 600, |
| 191 |
gallery_bytes: 700, |
| 192 |
total_bytes: 100 + 200 + 300 + 400 + 500 + 600 + 700, |
| 193 |
}; |
| 194 |
assert_eq!( |
| 195 |
sb.total_bytes, |
| 196 |
sb.audio_bytes |
| 197 |
+ sb.cover_bytes |
| 198 |
+ sb.download_bytes |
| 199 |
+ sb.insertion_bytes |
| 200 |
+ sb.video_bytes |
| 201 |
+ sb.media_bytes |
| 202 |
+ sb.gallery_bytes, |
| 203 |
); |
| 204 |
} |
| 205 |
|
| 206 |
#[test] |
| 207 |
fn storage_breakdown_single_category() { |
| 208 |
let sb = StorageBreakdown { |
| 209 |
audio_bytes: 1_000_000, |
| 210 |
total_bytes: 1_000_000, |
| 211 |
..Default::default() |
| 212 |
}; |
| 213 |
assert_eq!(sb.total_bytes, 1_000_000); |
| 214 |
assert_eq!(sb.cover_bytes, 0); |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
#[test] |
| 220 |
fn basic_file_limit_less_than_storage_limit() { |
| 221 |
crate::tier_prices::TierPrices::install_test_default(); |
| 222 |
assert!(CreatorTier::Basic.max_file_bytes() < CreatorTier::Basic.max_storage_bytes()); |
| 223 |
} |
| 224 |
|
| 225 |
#[test] |
| 226 |
fn every_tier_file_limit_within_storage_limit() { |
| 227 |
crate::tier_prices::TierPrices::install_test_default(); |
| 228 |
for tier in [ |
| 229 |
CreatorTier::Basic, |
| 230 |
CreatorTier::SmallFiles, |
| 231 |
CreatorTier::BigFiles, |
| 232 |
CreatorTier::Everything, |
| 233 |
] { |
| 234 |
assert!( |
| 235 |
tier.max_file_bytes() <= tier.max_storage_bytes(), |
| 236 |
"{tier:?} file limit exceeds its own storage limit", |
| 237 |
); |
| 238 |
} |
| 239 |
} |
| 240 |
|