add test for tera/admin/boat.rs

Fixes #33
This commit is contained in:
2023-07-31 19:38:53 +02:00
parent 47b534f8c3
commit 8b5be3fb41
3 changed files with 239 additions and 14 deletions

View File

@ -125,7 +125,7 @@ ORDER BY amount_seats DESC
res
}
pub async fn create(db: &SqlitePool, boat: BoatToAdd<'_>) -> bool {
pub async fn create(db: &SqlitePool, boat: BoatToAdd<'_>) -> Result<(), String> {
sqlx::query!(
"INSERT INTO boat(name, amount_seats, year_built, boatbuilder, default_shipmaster_only_steering, skull, external, location_id, owner) VALUES (?,?,?,?,?,?,?,?,?)",
boat.name,
@ -139,7 +139,8 @@ ORDER BY amount_seats DESC
boat.owner
)
.execute(db)
.await.is_ok()
.await.map_err(|e| e.to_string())?;
Ok(())
}
pub async fn update(&self, db: &SqlitePool, boat: BoatToUpdate<'_>) -> Result<(), String> {
@ -221,7 +222,7 @@ mod test {
}
)
.await,
true
Ok(())
);
}
@ -245,7 +246,10 @@ mod test {
}
)
.await,
false
Err(
"error returned from database: (code: 2067) UNIQUE constraint failed: boat.name"
.into()
)
);
}