Lines
95.45 %
Functions
81.82 %
Branches
100 %
use actix_http::body::MessageBody;
use actix_web::{dev::ServiceResponse, http::header::ContentType, test, web, App};
use fs_extra::dir::{copy, CopyOptions};
use ngi0review::{app, data::Data, ReviewRequestForm};
use tempfile::{tempdir, TempDir};
fn create_data() -> (TempDir, web::Data<Data>) {
let tempdir = tempdir().unwrap();
copy("tests/data", tempdir.path(), &CopyOptions::new()).unwrap();
let data = web::Data::new(Data::new(tempdir.path().join("data")).unwrap());
(tempdir, data)
}
#[actix_web::test]
async fn test_form_get() {
let (tempdir, data) = create_data();
let cors = actix_cors::Cors::default();
let app = test::init_service(app!(data, cors)).await;
let req = test::TestRequest::get()
.uri("/static/form.html")
.insert_header(ContentType::plaintext())
.to_request();
let resp = test::call_service(&app, req).await;
assert!(resp.status().is_success());
drop(tempdir);
async fn test_form(form: ReviewRequestForm) -> ServiceResponse<impl MessageBody> {
let req = test::TestRequest::post()
.uri("/NGI0/review/form.cgi")
.set_form(form)
let result = test::call_service(&app, req).await;
result
async fn test_incomplete_form_cgi_post() {
let resp = test_form(ReviewRequestForm {
name: "HELLO".to_string(),
..Default::default()
})
.await;
assert!(resp.status().is_client_error());
async fn test_minimal_form_cgi_post() {
projectname: "HELLO".to_string(),
email: "user@example.com".to_string(),
programme: "NGI SomeProgramme".to_string(),
www: "HELLO.com".to_string(),