add final tests for trip.rs

This commit is contained in:
2023-04-28 18:18:00 +02:00
parent 38732df6c8
commit 4d532e5846
3 changed files with 50 additions and 3 deletions

View File

@ -221,7 +221,7 @@ pub enum CoxHelpError {
AlreadyRegisteredAsCox,
}
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub enum TripDeleteError {
SomebodyAlreadyRegistered,
NotYourTrip,
@ -238,8 +238,10 @@ mod test {
use crate::{
model::{
planned_event::PlannedEvent,
trip::TripDeleteError,
tripdetails::TripDetails,
user::{CoxUser, User},
usertrip::UserTrip,
},
testdb,
};
@ -377,4 +379,48 @@ mod test {
assert!(Trip::find_by_id(&pool, 1).await.is_none());
}
#[sqlx::test]
fn test_fail_delete_diff_cox() {
let pool = testdb!();
let cox: CoxUser = User::find_by_name(&pool, "cox2".into())
.await
.unwrap()
.try_into()
.unwrap();
let trip = Trip::find_by_id(&pool, 1).await.unwrap();
let result = trip
.delete(&pool, &cox)
.await
.expect_err("It should not be possible to delete trips from others");
let expected = TripDeleteError::NotYourTrip;
assert_eq!(result, expected);
}
#[sqlx::test]
fn test_fail_delete_someone_registered() {
let pool = testdb!();
let cox: CoxUser = User::find_by_name(&pool, "cox2".into())
.await
.unwrap()
.try_into()
.unwrap();
let trip = Trip::find_by_id(&pool, 1).await.unwrap();
UserTrip::create(&pool, 2, 2).await.unwrap();
let result = trip
.delete(&pool, &cox)
.await
.expect_err("It should not be possible to delete trips if somebody already registered");
let expected = TripDeleteError::SomebodyAlreadyRegistered;
assert_eq!(result, expected);
}
}

View File

@ -78,6 +78,7 @@ impl UserTrip {
}
}
#[derive(Debug)]
pub enum UserTripError {
AlreadyRegistered,
AlreadyRegisteredAsCox,