// This client code really just serves as the url router for the main website where we describe what the project is about #![feature(proc_macro_hygiene, decl_macro, plugin)] //#[macro_use] extern crate serde_derive; #[macro_use] extern crate serde_derive; #[macro_use] extern crate rocket; extern crate rocket_contrib; extern crate chrono; use rocket_contrib::serve::StaticFiles; use rocket_contrib::templates::Template; mod website; use website::*; mod invites; use invites::*; fn rocket() -> rocket::Rocket { rocket::ignite() .mount("/static", StaticFiles::from("/static")) .mount("/", routes![ homepage, about_page, server_info, static_css, static_js, static_media ]) .mount("/invite", routes![ generate_invite ]) .attach(Template::fairing()) } fn main() { website::init(); rocket().launch(); } // Integrating some basic tests just for this module #[cfg(test)] mod test { use super::rocket; use rocket::local::Client; use rocket::http::Status; macro_rules! check_get { ($client:expr, $file:expr) => { let response = $client.get($file).dispatch(); assert_eq!(response.status(), Status::Ok); }; ($client:expr, $file:expr, $code:expr) => { let response = $client.get($file).dispatch(); assert_eq!(response.status(), $code); }; } #[test] fn pageroutes_get() { // Just make sure that when request the home page we actually get the html back let client = Client::new(rocket()).expect("Valid rocket instance"); check_get!(client, "/"); check_get!(client, "/about"); } // Next we test the static resource routes #[test] fn static_css_get() { let client = Client::new(rocket()).expect("Valid rocket instance"); check_get!(client, "/static/css/index.css"); check_get!(client, "/static/css/about.css"); } // this one is meant to fail for now because we don't have any js to serve #[test] fn static_media_get() { let client = Client::new(rocket()).expect("Valid rocket instance"); check_get!(client, "/static/media/favicon.png"); } #[test] fn static_js_get() { let client = Client::new(rocket()).expect("Valid rocket instance"); check_get!(client, "/static/js/jquery.js", Status::NotFound); } }