rustysearch/tests/hello_handler_tests.rs

23 lines
813 B
Rust

#[cfg(test)]
mod tests {
use actix_web::{http::header::ContentType, test, App};
use rustysearch::handlers::hello;
#[actix_web::test]
async fn test_index_get() {
let app = test::init_service(App::new().service(hello::say_hello)).await;
let req = test::TestRequest::default()
.insert_header(ContentType::plaintext())
.to_request();
let resp = test::call_service(&app, req).await;
assert!(resp.status().is_success());
}
#[actix_web::test]
async fn test_index_post() {
let app = test::init_service(App::new().service(hello::say_hello)).await;
let req = test::TestRequest::post().uri("/").to_request();
let resp = test::call_service(&app, req).await;
assert!(resp.status().is_client_error());
}
}