forked from Ruderverein-Donau-Linz/rowt
parent
8b5be3fb41
commit
3730940aed
@ -347,9 +347,9 @@ mod test {
|
||||
fn test_on_water() {
|
||||
let pool = testdb!();
|
||||
let logbook = Logbook::find_by_id(&pool, 1).await.unwrap();
|
||||
let logbookWithDetails = Logbook::on_water(&pool).await;
|
||||
let logbook_with_details = Logbook::on_water(&pool).await;
|
||||
|
||||
assert_eq!(logbookWithDetails[0].logbook, logbook);
|
||||
assert_eq!(logbook_with_details[0].logbook, logbook);
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
|
@ -86,7 +86,6 @@ pub fn routes() -> Vec<Route> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use chrono::NaiveDate;
|
||||
use rocket::{
|
||||
http::{ContentType, Status},
|
||||
local::asynchronous::Client,
|
||||
@ -94,7 +93,7 @@ mod test {
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::tera::admin::boat::Boat;
|
||||
use crate::{model::trip::Trip, testdb};
|
||||
use crate::testdb;
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_boat_index() {
|
||||
|
162
src/tera/log.rs
162
src/tera/log.rs
@ -220,4 +220,164 @@ pub fn routes() -> Vec<Route> {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {}
|
||||
mod test {
|
||||
use rocket::http::ContentType;
|
||||
use rocket::{http::Status, local::asynchronous::Client};
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::testdb;
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_kiosk_cookie() {
|
||||
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("/log");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/auth"));
|
||||
|
||||
let req = client.get("/log/kiosk/ekrv2019");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/log"));
|
||||
|
||||
let req = client.get("/log");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
let text = response.into_string().await.unwrap();
|
||||
assert!(text.contains("Logbuch"));
|
||||
assert!(text.contains("Neue Ausfahrt"));
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_index() {
|
||||
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=admin&password=admin"); // Add the form data to the request body;
|
||||
login.dispatch().await;
|
||||
|
||||
let req = client.get("/log");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
let text = response.into_string().await.unwrap();
|
||||
assert!(text.contains("Logbuch"));
|
||||
assert!(text.contains("Neue Ausfahrt"));
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_show() {
|
||||
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=admin&password=admin"); // Add the form data to the request body;
|
||||
login.dispatch().await;
|
||||
|
||||
let req = client.get("/log/show");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
let text = response.into_string().await.unwrap();
|
||||
assert!(text.contains("Logbuch"));
|
||||
assert!(text.contains("Bootsname: Joe"));
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_show_kiosk() {
|
||||
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("/log/kiosk/ekrv2019");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
let req = client.get("/log/show");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
let text = response.into_string().await.unwrap();
|
||||
assert!(text.contains("Logbuch"));
|
||||
assert!(text.contains("Bootsname: Joe"));
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_create() {
|
||||
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=admin&password=admin"); // Add the form data to the request body;
|
||||
login.dispatch().await;
|
||||
|
||||
let req = client
|
||||
.post("/log")
|
||||
.header(ContentType::Form)
|
||||
.body("boat_id=1&shipmaster=4&departure=2199-12-31T10:00");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/log"));
|
||||
|
||||
let flash_cookie = response
|
||||
.cookies()
|
||||
.get("_flash")
|
||||
.expect("Expected flash cookie");
|
||||
|
||||
assert_eq!(
|
||||
flash_cookie.value(),
|
||||
"7:successAusfahrt erfolgreich hinzugefügt"
|
||||
);
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_home_kiosk() {
|
||||
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("/log/kiosk/ekrv2019");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
let req = client
|
||||
.post("/log/1")
|
||||
.header(ContentType::Form)
|
||||
.body("destination=Ottensheim&distance_in_km=25");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/log"));
|
||||
|
||||
let flash_cookie = response
|
||||
.cookies()
|
||||
.get("_flash")
|
||||
.expect("Expected flash cookie");
|
||||
|
||||
assert_eq!(flash_cookie.value(), "7:successSuccessfully updated log");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user