1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use super::base::{ErrorType, MappedErrors};

pub fn creation_err(
    msg: String,
    exp: Option<bool>,
    prev: Option<MappedErrors>,
) -> MappedErrors {
    MappedErrors::new(msg, exp, prev, ErrorType::CreationError)
}

pub fn updating_err(
    msg: String,
    exp: Option<bool>,
    prev: Option<MappedErrors>,
) -> MappedErrors {
    MappedErrors::new(msg, exp, prev, ErrorType::UpdatingError)
}

pub fn fetching_err(
    msg: String,
    exp: Option<bool>,
    prev: Option<MappedErrors>,
) -> MappedErrors {
    MappedErrors::new(msg, exp, prev, ErrorType::FetchingError)
}

pub fn deletion_err(
    msg: String,
    exp: Option<bool>,
    prev: Option<MappedErrors>,
) -> MappedErrors {
    MappedErrors::new(msg, exp, prev, ErrorType::DeletionError)
}

pub fn use_case_err(
    msg: String,
    exp: Option<bool>,
    prev: Option<MappedErrors>,
) -> MappedErrors {
    MappedErrors::new(msg, exp, prev, ErrorType::UseCaseError)
}

pub fn execution_err(
    msg: String,
    exp: Option<bool>,
    prev: Option<MappedErrors>,
) -> MappedErrors {
    MappedErrors::new(msg, exp, prev, ErrorType::ExecutionError)
}

pub fn invalid_repo_err(
    msg: String,
    exp: Option<bool>,
    prev: Option<MappedErrors>,
) -> MappedErrors {
    MappedErrors::new(msg, exp, prev, ErrorType::InvalidRepositoryError)
}

pub fn invalid_arg_err(
    msg: String,
    exp: Option<bool>,
    prev: Option<MappedErrors>,
) -> MappedErrors {
    MappedErrors::new(msg, exp, prev, ErrorType::InvalidArgumentError)
}

// ? ---------------------------------------------------------------------------
// ? TESTS
// ? ---------------------------------------------------------------------------

#[cfg(test)]
mod tests {
    use super::{
        creation_err, deletion_err, fetching_err, updating_err, ErrorType,
    };

    #[test]
    fn creation_err_works() {
        assert_eq!(
            creation_err("msg".to_string(), None, None).error_type(),
            ErrorType::CreationError
        );
    }

    #[test]
    fn deletion_err_works() {
        assert_eq!(
            deletion_err("msg".to_string(), None, None).error_type(),
            ErrorType::DeletionError
        );
    }

    #[test]
    fn fetching_err_works() {
        assert_eq!(
            fetching_err("msg".to_string(), None, None).error_type(),
            ErrorType::FetchingError
        );
    }

    #[test]
    fn updating_err_works() {
        assert_eq!(
            updating_err("msg".to_string(), None, None).error_type(),
            ErrorType::UpdatingError
        );
    }
}