70 lines
1.9 KiB
Rust
70 lines
1.9 KiB
Rust
use rocket::{get, http::ContentType, routes, Route, State};
|
|
use rocket_dyn_templates::{context, Template};
|
|
use sqlx::SqlitePool;
|
|
|
|
use crate::model::{planned_event::PlannedEvent, user::User};
|
|
|
|
#[get("/faq")]
|
|
async fn faq(user: User) -> Template {
|
|
Template::render("faq", context!(loggedin_user: user))
|
|
}
|
|
|
|
#[get("/cal")]
|
|
async fn cal(db: &State<SqlitePool>) -> (ContentType, String) {
|
|
//TODO: add unit test once proper functionality is there
|
|
(ContentType::Calendar, PlannedEvent::get_ics_feed(db).await)
|
|
}
|
|
|
|
pub fn routes() -> Vec<Route> {
|
|
routes![faq, cal]
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use rocket::{
|
|
http::{ContentType, Status},
|
|
local::asynchronous::Client,
|
|
};
|
|
use sqlx::SqlitePool;
|
|
|
|
use crate::testdb;
|
|
|
|
#[sqlx::test]
|
|
fn test_faq() {
|
|
let db = testdb!();
|
|
|
|
let rocket = rocket::build().manage(db.clone());
|
|
let rocket = crate::tera::config(rocket);
|
|
|
|
let client = Client::tracked(rocket).await.unwrap();
|
|
let login = client
|
|
.post("/auth")
|
|
.header(ContentType::Form) // Set the content type to form
|
|
.body("name=cox&password=cox"); // Add the form data to the request body;
|
|
login.dispatch().await;
|
|
|
|
let req = client.get("/faq");
|
|
let response = req.dispatch().await;
|
|
|
|
assert_eq!(response.status(), Status::Ok);
|
|
|
|
assert!(response.into_string().await.unwrap().contains("FAQs"));
|
|
}
|
|
|
|
#[sqlx::test]
|
|
fn test_without_login() {
|
|
let db = testdb!();
|
|
|
|
let rocket = rocket::build().manage(db.clone());
|
|
let rocket = crate::tera::config(rocket);
|
|
|
|
let client = Client::tracked(rocket).await.unwrap();
|
|
|
|
let req = client.get("/");
|
|
let response = req.dispatch().await;
|
|
|
|
assert_eq!(response.status(), Status::SeeOther);
|
|
assert_eq!(response.headers().get("Location").next(), Some("/auth"));
|
|
}
|
|
}
|