[#26] Moved lib & bin to own folders; Moved server tests; wrote some readmes

This commit is contained in:
Jef Roosens 2021-04-16 09:18:50 +02:00
parent 4b51ee20ca
commit 45c4a4e257
Signed by: Jef Roosens
GPG key ID: 955C0660072F691F
13 changed files with 46 additions and 31 deletions

View file

@ -2,6 +2,10 @@
#[macro_use]
extern crate rocket;
#[cfg(test)]
mod tests;
mod catchers;
mod routes;

29
src/server/tests.rs Normal file
View file

@ -0,0 +1,29 @@
/// In here, any non-unit tests are placed.
use rocket::http::Status;
use rocket::local::Client;
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", super::routes::ivago())
}
/// Test 404 response
#[test]
fn test_404_response() {
let client = Client::new(rocket()).expect("valid rocket instance");
let response = client.get("/").dispatch();
assert_eq!(response.status(), Status::NotFound);
// TODO add text check as well
}
/// Test 404 on invalid parameters
// TODO make this check a 400 instead
#[test]
fn test_invalid_parameters() {
let client = Client::new(rocket()).expect("valid rocket instance");
let response = client
.get("/?street=astreet+(city)&number=500&start_date=2021-04-04&end_date=2021-04-555")
.dispatch();
assert_eq!(response.status(), Status::NotFound);
}