aboutsummaryrefslogtreecommitdiff
path: root/src/routes/not_understood.rs
blob: 7ca5ed2a33bf7c71233910a780b24fe224385416 (plain) (blame)
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
use crate::routes::*;

// Sends a default response message when requested an undefined resource.
pub fn not_understood(req: HttpRequest) -> JsonMessage<NotUnderstood> {
    let message = NotUnderstood {
        path: destruct_path(req.path()),
    };

    Ok(FormatMsg {
        message: message.as_outgoing(),
        code: StatusCode::NOT_FOUND,
    })
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::routes::tests::*;

    #[test]
    fn test_not_understood() {
        // Arrange
        let uri = "/api/phpmyadmin/index.rs";
        let req = gen_request(uri, None);

        // Act
        let result = not_understood(req);

        // Assert
        assert!(result.is_ok());

        let val = result.unwrap().into_inner();
        assert_eq!(val.result_type, "NOT_UNDERSTOOD");
        assert_eq!(val.content.path, vec!["api", "phpmyadmin", "index.rs"]);
    }

    #[test]
    fn test_not_understood_blank() {
        // Arrange
        let uri = "/";
        let req = gen_request(uri, None);

        // Act
        let result = not_understood(req);

        // Assert
        assert!(result.is_ok());

        let val = result.unwrap().into_inner();
        assert_eq!(val.result_type, "NOT_UNDERSTOOD");
        assert!(val.content.path.is_empty());
    }
}