konduto/types/hotel/
room_type.rs

1use crate::impl_nutype_error_conversion;
2use nutype::nutype;
3
4/// Tipo de quarto (máximo 100 caracteres)
5#[nutype(
6    sanitize(trim),
7    validate(not_empty, len_char_max = 100),
8    derive(Debug, Clone, PartialEq, Eq, Display, AsRef, Deref, Serialize, Deserialize)
9)]
10pub struct RoomType(String);
11
12impl RoomType {
13    pub fn as_str(&self) -> &str {
14        self.as_ref()
15    }
16}
17
18impl_nutype_error_conversion!(RoomTypeError);
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23
24    #[test]
25    fn test_room_type_valid() {
26        let room_type = RoomType::try_new("double").unwrap();
27        assert_eq!(room_type.as_str(), "double");
28    }
29
30    #[test]
31    fn test_room_type_variants() {
32        let types = vec!["single", "double", "suite", "presidential"];
33        for t in types {
34            let room_type = RoomType::try_new(t).unwrap();
35            assert_eq!(room_type.as_str(), t);
36        }
37    }
38
39    #[test]
40    fn test_room_type_empty() {
41        let result = RoomType::try_new("");
42        assert!(result.is_err());
43    }
44
45    #[test]
46    fn test_room_type_too_long() {
47        let long = "a".repeat(101);
48        let result = RoomType::try_new(long);
49        assert!(result.is_err());
50    }
51}