1use serde::{Deserialize, Serialize};
2use validator::Validate;
3
4#[derive(Validate, Serialize, Deserialize, Debug)]
5pub struct ThankYouMessage {
6 #[validate(
7 length(min = 1, message = "Input needs to be at least one character long"),
8 length(
9 max = 50,
10 message = "Tool name can't be longer than 50 characters, sorry!"
11 )
12 )]
13 pub program: String,
14
15 #[validate(length(
16 max = 2048,
17 message = "Note too long! Please keep it under 2048 characters."
18 ))]
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub note: Option<String>,
21}
22
23#[derive(Serialize, Deserialize, Debug)]
24pub struct ThankYouStats {
25 pub program: String,
26 pub count: i64,
27 pub note_count: i64,
28}
29
30#[derive(Serialize, Deserialize, Debug)]
31pub struct ThankYouDetail {
32 pub program: String,
33 pub notes: Vec<String>,
34}
35
36#[test]
37fn program_length_good() {
38 let ty_message = ThankYouMessage {
39 program: "good".to_string(),
40 note: None,
41 };
42
43 assert!(ty_message.validate().is_ok())
44}
45
46#[test]
47fn program_length_too_long() {
48 let ty_message = ThankYouMessage {
49 program: "Is this way too long or maybe just one character to long?".to_string(),
50 note: None,
51 };
52 assert!(ty_message.validate().is_err())
53}
54
55#[test]
56fn note_too_long() {
57 let ty_message = ThankYouMessage {
58 program: "good".to_string(),
59 note: Some(include_str!("bad_note").to_string()),
60 };
61 assert!(ty_message.validate().is_err())
62}
63
64#[test]
65fn note_unicode_good() {
66 let ty_message = ThankYouMessage {
67 program: "good".to_string(),
68 note: Some(include_str!("good_emoji_note").to_string()),
69 };
70 assert!(ty_message.validate().is_ok())
71}
72
73#[test]
74fn note_unicode_long() {
75 let ty_message = ThankYouMessage {
76 program: "good".to_string(),
77 note: Some(include_str!("bad_emoji_note").to_string()),
78 };
79 assert!(ty_message.validate().is_err())
80}
81
82#[test]
83fn note_length_good() {
84 let ty_message = ThankYouMessage {
85 program: "good".to_string(),
86 note: Some(include_str!("good_note").to_string()),
87 };
88 assert!(ty_message.validate().is_ok())
89}