faker_rust/default/
invoice.rs1use crate::config::FakerConfig;
4
5pub fn reference() -> String {
7 let config = FakerConfig::current();
8 let prefix = config.rand_char(&['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']);
9 let numbers: String = (0..8)
10 .map(|_| config.rand_char(&['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']))
11 .collect();
12 format!("{}{}", prefix, numbers)
13}
14
15pub fn amount() -> String {
17 let config = FakerConfig::current();
18 let dollars = config.rand_range(10, 10000);
19 let cents = config.rand_range(0, 100);
20 format!("{}.{:02}", dollars, cents)
21}
22
23pub fn line_item() -> String {
25 let items = [
26 "Consulting Services", "Software License", "Hardware Maintenance",
27 "Cloud Hosting", "Training Session", "Support Contract",
28 "Professional Services", "Implementation Fee", "Setup Fee",
29 ];
30 sample(&items).to_string()
31}
32
33use crate::base::sample;
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn test_reference() {
41 let ref_num = reference();
42 assert_eq!(ref_num.len(), 9);
43 assert!(ref_num.chars().next().unwrap().is_alphabetic());
44 }
45
46 #[test]
47 fn test_amount() {
48 let amt = amount();
49 assert!(amt.contains('.'));
50 }
51
52 #[test]
53 fn test_line_item() {
54 assert!(!line_item().is_empty());
55 }
56}