[#13] Further overhaul of the project structure for better testing
This commit is contained in:
parent
e78de73d83
commit
2e73d88ae9
10 changed files with 48 additions and 16 deletions
|
|
@ -1,6 +1,7 @@
|
|||
// I can probably do this way easier using an external crate, I should do that
|
||||
use rocket::http::Status;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum FejError {
|
||||
InvalidArgument,
|
||||
FailedRequest,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use std::convert::TryFrom;
|
|||
|
||||
/// This class is a simple wrapper around chrono's DateTime. Its sole purpose
|
||||
/// is to avoid error E0117.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct BasicDate(pub DateTime<Tz>);
|
||||
|
||||
/// This allows us to use BasicDate as a query parameter in our routes.
|
||||
|
|
@ -54,3 +55,15 @@ impl Serialize for BasicDate {
|
|||
serializer.serialize_str(&String::from(self))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_invalid_date() {
|
||||
let val = "2012-13-12";
|
||||
let date = BasicDate::try_from(val);
|
||||
assert_eq!(date, Err(FejError::InvalidArgument));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
mod controller;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use controller::structs::{BasicDate, PickupTime, Street};
|
||||
use controller::{get_pickup_times, search_streets};
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
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);
|
||||
}
|
||||
11
src/lib.rs
Normal file
11
src/lib.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
// Route modules
|
||||
pub mod ivago;
|
||||
|
||||
// Helper modules
|
||||
pub mod catchers;
|
||||
pub mod errors;
|
||||
|
|
@ -1,14 +1,7 @@
|
|||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
extern crate chrono_tz;
|
||||
|
||||
// Route modules
|
||||
mod catchers;
|
||||
mod errors;
|
||||
mod ivago;
|
||||
use fej_lib::{catchers, ivago};
|
||||
|
||||
fn rocket() -> rocket::Rocket {
|
||||
rocket::ignite()
|
||||
|
|
|
|||
Reference in a new issue