create tests for model/rower.rs, Closes #32
This commit is contained in:
@ -57,6 +57,7 @@ pub struct LogbookWithBoatAndRowers {
|
||||
pub enum LogbookUpdateError {
|
||||
NotYourEntry,
|
||||
TooManyRowers(usize, usize),
|
||||
RowerCreateError(i64, String),
|
||||
}
|
||||
|
||||
pub enum LogbookCreateError {
|
||||
@ -66,6 +67,7 @@ pub enum LogbookCreateError {
|
||||
TooManyRowers(usize, usize),
|
||||
ShipmasterAlreadyOnWater,
|
||||
RowerAlreadyOnWater(User),
|
||||
RowerCreateError(i64, String),
|
||||
}
|
||||
|
||||
impl Logbook {
|
||||
@ -164,8 +166,8 @@ ORDER BY departure DESC
|
||||
|
||||
pub async fn create(db: &SqlitePool, log: LogToAdd) -> Result<(), LogbookCreateError> {
|
||||
let Some(boat) = Boat::find_by_id(db, log.boat_id).await else {
|
||||
return Err(LogbookCreateError::BoatNotFound);
|
||||
};
|
||||
return Err(LogbookCreateError::BoatNotFound);
|
||||
};
|
||||
|
||||
if boat.is_locked(db).await {
|
||||
return Err(LogbookCreateError::BoatLocked);
|
||||
@ -217,7 +219,11 @@ ORDER BY departure DESC
|
||||
.await.unwrap();
|
||||
|
||||
for rower in &log.rower {
|
||||
Rower::create(&mut tx, inserted_row.id, *rower).await;
|
||||
Rower::create(&mut tx, inserted_row.id, *rower)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
return LogbookCreateError::RowerCreateError(*rower, e.to_string());
|
||||
})?;
|
||||
}
|
||||
|
||||
tx.commit().await.unwrap();
|
||||
@ -289,7 +295,9 @@ ORDER BY departure DESC
|
||||
self.remove_rowers(&mut tx).await;
|
||||
|
||||
for rower in &log.rower {
|
||||
Rower::create(&mut tx, self.id, *rower).await;
|
||||
Rower::create(&mut tx, self.id, *rower).await.map_err(|e| {
|
||||
return LogbookUpdateError::RowerCreateError(*rower, e.to_string());
|
||||
})?;
|
||||
}
|
||||
|
||||
tx.commit().await.unwrap();
|
||||
|
Reference in New Issue
Block a user