Add checks for booking and fix database timestamps

This commit is contained in:
Simon Goller 2024-05-09 09:45:53 +02:00
parent bc8a534353
commit e3ec694876
7 changed files with 73 additions and 7 deletions

View file

@ -170,6 +170,16 @@ where
booking.slot_id,
));
}
if self
.booking_dao
.find_by_booking_data(
booking.sales_person_id,
booking.slot_id,
booking.calendar_week,
booking.year,
).await?.is_some() {
validation.push(ValidationFailureItem::Duplicate);
}
if !validation.is_empty() {
return Err(ServiceError::ValidationError(validation.into()));

View file

@ -94,7 +94,8 @@ impl BookingServiceDependencies {
}
pub fn build_dependencies(permission: bool, role: &'static str) -> BookingServiceDependencies {
let booking_dao = MockBookingDao::new();
let mut booking_dao = MockBookingDao::new();
booking_dao.expect_find_by_booking_data().returning(|_, _, _, _| Ok(None));
let mut permission_service = MockPermissionService::new();
permission_service
.expect_check_permission()
@ -351,6 +352,34 @@ async fn test_create_sales_person_does_not_exist() {
);
}
#[tokio::test]
async fn test_create_booking_data_already_exists() {
let mut deps = build_dependencies(true, "hr");
deps.booking_dao.checkpoint();
deps.booking_dao
.expect_find_by_booking_data()
.with(eq(default_sales_person_id()), eq(default_slot_id()), eq(3), eq(2024))
.returning(|_, _, _, _| Ok(Some(default_booking_entity())));
let service = deps.build_service();
let result = service
.create(
&Booking {
id: Uuid::nil(),
version: Uuid::nil(),
created: None,
..default_booking()
},
(),
)
.await;
test_validation_error(
&result,
&ValidationFailureItem::Duplicate,
1,
);
}
#[tokio::test]
async fn test_create_slot_does_not_exist() {
let mut deps = build_dependencies(true, "hr");