From 4117f797cec89927fe3363543b8c8b11a311b90c Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Mon, 4 Nov 2019 14:06:58 -0500 Subject: Move FormatMsg to routes and add unit tests --- src/routes/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/routes/mod.rs') diff --git a/src/routes/mod.rs b/src/routes/mod.rs index dd7a526..759375d 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -3,9 +3,11 @@ use actix_web::http::StatusCode; use messages::*; use std::collections::HashMap; +pub mod format_msg; mod callback; mod not_understood; +pub use self::format_msg::FormatMsg; use self::callback::callback; use self::not_understood::not_understood; @@ -32,7 +34,7 @@ mod tests { use super::*; use actix_web::{http::Method, test::TestRequest}; use actix_web::{App, dev::Service, test::{block_on, init_service}}; - use actix_web::dev::{Body, ServiceResponse}; + use actix_web::{HttpResponse, dev::Body}; use serde::Deserialize; use std::str; @@ -49,7 +51,7 @@ mod tests { // Assert assert_eq!(resp.status(), StatusCode::OK); - let content = get_message::>(resp); + let content = get_message::>(resp.response()); assert_eq!(content.result_type, "CALLBACK"); assert_eq!(content.content.path, vec!["api", "callback"]); } @@ -67,7 +69,7 @@ mod tests { // Assert assert_eq!(resp.status(), StatusCode::NOT_FOUND); - let content = get_message::>(resp); + let content = get_message::>(resp.response()); assert_eq!(content.result_type, "NOT_UNDERSTOOD"); assert_eq!(content.content.path, vec!["api", "404"]); } @@ -137,8 +139,8 @@ mod tests { Query::from_query(&query_str).unwrap() } - fn get_message<'a, T: Deserialize<'a>>(response: &'a ServiceResponse) -> T { - let body = response.response().body().as_ref().unwrap(); + pub fn get_message<'a, T: Deserialize<'a>>(response: &'a HttpResponse) -> T { + let body = response.body().as_ref().unwrap(); let mut array = &[b'0';0][..]; match body { Body::Bytes(b) => { -- cgit