add first tera test
This commit is contained in:
parent
968c68e12b
commit
5a27c5a225
@ -159,3 +159,63 @@ async fn remove(db: &State<SqlitePool>, planned_event_id: i64, cox: CoxUser) ->
|
|||||||
pub fn routes() -> Vec<Route> {
|
pub fn routes() -> Vec<Route> {
|
||||||
routes![create, join, remove, remove_trip, update]
|
routes![create, join, remove, remove_trip, update]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use rocket::{
|
||||||
|
http::{ContentType, Status},
|
||||||
|
local::asynchronous::Client,
|
||||||
|
};
|
||||||
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
|
use crate::{model::trip::Trip, testdb};
|
||||||
|
|
||||||
|
#[sqlx::test]
|
||||||
|
fn test_trip_create() {
|
||||||
|
let db = testdb!();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
0,
|
||||||
|
Trip::get_for_day(&db, NaiveDate::from_ymd_opt(2999, 12, 30).unwrap())
|
||||||
|
.await
|
||||||
|
.len()
|
||||||
|
);
|
||||||
|
|
||||||
|
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
|
||||||
|
.post("/cox/trip")
|
||||||
|
.header(ContentType::Form)
|
||||||
|
.body("day=2999-12-30&planned_starting_time=12:34&max_people=42&allow_guests=false");
|
||||||
|
let response = req.dispatch().await;
|
||||||
|
|
||||||
|
assert_eq!(response.status(), Status::SeeOther);
|
||||||
|
assert_eq!(response.headers().get("Location").next(), Some("/"));
|
||||||
|
|
||||||
|
let flash_cookie = response
|
||||||
|
.cookies()
|
||||||
|
.get("_flash")
|
||||||
|
.expect("Expected flash cookie");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
flash_cookie.value(),
|
||||||
|
"7:successAusfahrt erfolgreich erstellt."
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
1,
|
||||||
|
Trip::get_for_day(&db, NaiveDate::from_ymd_opt(2999, 12, 30).unwrap())
|
||||||
|
.await
|
||||||
|
.len()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user