add tests

This commit is contained in:
2023-10-01 13:48:21 +02:00
parent 7500b90b22
commit 6d0501d3b0
4 changed files with 209 additions and 10 deletions

View File

@ -136,7 +136,9 @@ ORDER BY amount_seats DESC
if user.is_admin {
return Self::all(db).await;
}
let boats = sqlx::query_as!(
let mut boats;
if user.is_cox {
boats = sqlx::query_as!(
Boat,
"
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external
@ -149,6 +151,21 @@ ORDER BY amount_seats DESC
.fetch_all(db)
.await
.unwrap(); //TODO: fixme
} else {
boats = sqlx::query_as!(
Boat,
"
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external
FROM boat
WHERE owner = ? OR (owner is null and amount_seats = 1)
ORDER BY amount_seats DESC
",
user.id
)
.fetch_all(db)
.await
.unwrap(); //TODO: fixme
}
Self::boats_to_details(db, boats).await
}

View File

@ -294,6 +294,16 @@ ORDER BY departure DESC
.unwrap();
}
#[cfg(test)]
pub async fn highest_id(db: &SqlitePool) -> i32 {
sqlx::query!("SELECT max(id) as id FROM logbook")
.fetch_one(db)
.await
.unwrap()
.id
.unwrap()
}
pub async fn home(
&self,
db: &SqlitePool,