From 82c3cc2c1952020ef13c330047cbc8ba1dc7cc75 Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Wed, 30 Oct 2019 13:14:09 -0400 Subject: Refactor routes and scope into routes module --- src/routes/not_understood.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/routes/not_understood.rs (limited to 'src/routes/not_understood.rs') diff --git a/src/routes/not_understood.rs b/src/routes/not_understood.rs new file mode 100644 index 0000000..c94e6e2 --- /dev/null +++ b/src/routes/not_understood.rs @@ -0,0 +1,50 @@ +use routes::*; + +// Sends a default response message when requested an undefined resource. +pub fn not_understood(req: HttpRequest) -> JsonMessage { + let message = NotUnderstood { + path: destruct_path(req.path()), + }; + + Ok(Json(message.as_outgoing())) +} + +#[cfg(test)] +mod tests { + use super::*; + use 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()); + } +} \ No newline at end of file -- cgit