2023-06-05 14:15:17 +02:00
|
|
|
use rocket::{get, http::ContentType, routes, Route, State};
|
2023-05-24 15:36:38 +02:00
|
|
|
use sqlx::SqlitePool;
|
|
|
|
|
2024-05-28 09:08:48 +02:00
|
|
|
use crate::model::event::Event;
|
2023-05-24 15:36:38 +02:00
|
|
|
|
|
|
|
#[get("/cal")]
|
2023-06-05 14:15:17 +02:00
|
|
|
async fn cal(db: &State<SqlitePool>) -> (ContentType, String) {
|
2023-07-22 12:24:29 +02:00
|
|
|
//TODO: add unit test once proper functionality is there
|
2024-05-28 09:08:48 +02:00
|
|
|
(ContentType::Calendar, Event::get_ics_feed(db).await)
|
2023-05-24 15:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn routes() -> Vec<Route> {
|
2023-10-24 14:33:22 +02:00
|
|
|
routes![cal]
|
2023-05-24 15:36:38 +02:00
|
|
|
}
|
2023-07-22 12:24:29 +02:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2023-10-28 14:48:51 +02:00
|
|
|
use rocket::{http::Status, local::asynchronous::Client};
|
2023-07-22 12:24:29 +02:00
|
|
|
use sqlx::SqlitePool;
|
|
|
|
|
|
|
|
use crate::testdb;
|
|
|
|
|
|
|
|
#[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"));
|
|
|
|
}
|
|
|
|
}
|