From c0311132ec2e2bb3f3ad8c2512a80917f1807dbc Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 4 Apr 2021 19:22:53 +0200 Subject: [PATCH] Started writing some tests (#5) --- src/ivago/tests.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/ivago/tests.rs b/src/ivago/tests.rs index 8b13789..2b91e48 100644 --- a/src/ivago/tests.rs +++ b/src/ivago/tests.rs @@ -1 +1,26 @@ +use rocket::http::Status; +use rocket::local::Client; +fn rocket() -> rocket::Rocket { + rocket::ignite().mount("/", super::routes()) +} + +/// 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); +} + +/// Test 404 on invalid parameters +#[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); +}