From ed609cf06c6ccb210c496d957c9b5bb5d0d5a344 Mon Sep 17 00:00:00 2001 From: Simon Goller Date: Thu, 9 May 2024 15:00:50 +0200 Subject: [PATCH] Cargo clippy and cargo fmt --- dao/src/booking.rs | 8 +++- dao/src/sales_person.rs | 7 +++- dao_impl/src/booking.rs | 23 ++++++++++-- dao_impl/src/lib.rs | 11 ++---- dao_impl/src/sales_person.rs | 18 ++++++--- rest/src/booking.rs | 10 ++++- rest/src/sales_person.rs | 3 +- rest/src/slot.rs | 7 +++- service/src/booking.rs | 21 ++++++++--- service/src/permission.rs | 48 +++++++++++++++++++----- service/src/sales_person.rs | 27 ++++++++++--- service/src/slot.rs | 39 +++++++++++++++---- service/src/user_service.rs | 2 +- service_impl/src/booking.rs | 30 ++++++++++----- service_impl/src/permission.rs | 14 +++++-- service_impl/src/sales_person.rs | 22 ++++++++--- service_impl/src/slot.rs | 35 ++++++++++++++--- service_impl/src/test/booking.rs | 24 +++++++----- service_impl/src/test/error_test.rs | 1 - service_impl/src/test/permission_test.rs | 8 +++- service_impl/src/test/sales_person.rs | 10 ++++- service_impl/src/test/slot.rs | 12 ++++-- 22 files changed, 286 insertions(+), 94 deletions(-) diff --git a/dao/src/booking.rs b/dao/src/booking.rs index 30a3946..a1a6e62 100644 --- a/dao/src/booking.rs +++ b/dao/src/booking.rs @@ -24,7 +24,13 @@ pub struct BookingEntity { pub trait BookingDao { async fn all(&self) -> Result, DaoError>; async fn find_by_id(&self, id: Uuid) -> Result, DaoError>; - async fn find_by_booking_data(&self, sales_person_id: Uuid, slot_id: Uuid, calendar_week: i32, year: u32) -> Result, DaoError>; + async fn find_by_booking_data( + &self, + sales_person_id: Uuid, + slot_id: Uuid, + calendar_week: i32, + year: u32, + ) -> Result, DaoError>; async fn create(&self, entity: &BookingEntity, process: &str) -> Result<(), DaoError>; async fn update(&self, entity: &BookingEntity, process: &str) -> Result<(), DaoError>; } diff --git a/dao/src/sales_person.rs b/dao/src/sales_person.rs index c7dd821..bed9464 100644 --- a/dao/src/sales_person.rs +++ b/dao/src/sales_person.rs @@ -24,6 +24,11 @@ pub trait SalesPersonDao { async fn create(&self, entity: &SalesPersonEntity, process: &str) -> Result<(), DaoError>; async fn update(&self, entity: &SalesPersonEntity, process: &str) -> Result<(), DaoError>; async fn get_assigned_user(&self, sales_person_id: Uuid) -> Result>, DaoError>; - async fn assign_to_user(&self, sales_person_id: Uuid, user_id: &str, process: &str) -> Result<(), DaoError>; + async fn assign_to_user( + &self, + sales_person_id: Uuid, + user_id: &str, + process: &str, + ) -> Result<(), DaoError>; async fn discard_assigned_user(&self, sales_person_id: Uuid) -> Result<(), DaoError>; } diff --git a/dao_impl/src/booking.rs b/dao_impl/src/booking.rs index 6f88177..96de639 100644 --- a/dao_impl/src/booking.rs +++ b/dao_impl/src/booking.rs @@ -81,7 +81,13 @@ impl BookingDao for BookingDaoImpl { .transpose()?) } - async fn find_by_booking_data(&self, sales_person_id: Uuid, slot_id: Uuid, calendar_week: i32, year: u32) -> Result, DaoError> { + async fn find_by_booking_data( + &self, + sales_person_id: Uuid, + slot_id: Uuid, + calendar_week: i32, + year: u32, + ) -> Result, DaoError> { let sales_person_id_vec = sales_person_id.as_bytes().to_vec(); let slot_id_vec = slot_id.as_bytes().to_vec(); Ok(query_as!( @@ -100,13 +106,17 @@ impl BookingDao for BookingDaoImpl { .transpose()?) } - async fn create(&self, entity: &BookingEntity, process: &str) -> Result<(), DaoError> { let id_vec = entity.id.as_bytes().to_vec(); let sales_person_id_vec = entity.sales_person_id.as_bytes().to_vec(); let slot_id_vec = entity.slot_id.as_bytes().to_vec(); let created = entity.created.format(&Iso8601::DATE_TIME).map_db_error()?; - let deleted = entity.deleted.as_ref().map(|deleted| deleted.format(&Iso8601::DATE_TIME)).transpose().map_db_error()?; + let deleted = entity + .deleted + .as_ref() + .map(|deleted| deleted.format(&Iso8601::DATE_TIME)) + .transpose() + .map_db_error()?; let version_vec = entity.version.as_bytes().to_vec(); query!("INSERT INTO booking (id, sales_person_id, slot_id, calendar_week, year, created, deleted, update_version, update_process) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", id_vec, sales_person_id_vec, slot_id_vec, entity.calendar_week, entity.year, created, deleted, version_vec, process @@ -116,7 +126,12 @@ impl BookingDao for BookingDaoImpl { async fn update(&self, entity: &BookingEntity, process: &str) -> Result<(), DaoError> { let id_vec = entity.id.as_bytes().to_vec(); let version_vec = entity.version.as_bytes().to_vec(); - let deleted = entity.deleted.as_ref().map(|deleted| deleted.format(&Iso8601::DATE_TIME)).transpose().map_db_error()?; + let deleted = entity + .deleted + .as_ref() + .map(|deleted| deleted.format(&Iso8601::DATE_TIME)) + .transpose() + .map_db_error()?; query!( "UPDATE booking SET deleted = ?, update_version = ?, update_process = ? WHERE id = ?", deleted, diff --git a/dao_impl/src/lib.rs b/dao_impl/src/lib.rs index 988bf4f..de6211e 100644 --- a/dao_impl/src/lib.rs +++ b/dao_impl/src/lib.rs @@ -92,13 +92,10 @@ impl dao::PermissionDao for PermissionDaoImpl { Ok(()) } async fn find_user(&self, username: &str) -> Result, DaoError> { - let result = query!( - r"SELECT name FROM user WHERE name = ?", - username - ) - .fetch_optional(self.pool.as_ref()) - .await - .map_db_error()?; + let result = query!(r"SELECT name FROM user WHERE name = ?", username) + .fetch_optional(self.pool.as_ref()) + .await + .map_db_error()?; Ok(result.map(|row| dao::UserEntity { name: row.name.clone().into(), })) diff --git a/dao_impl/src/sales_person.rs b/dao_impl/src/sales_person.rs index df23339..81b0ef0 100644 --- a/dao_impl/src/sales_person.rs +++ b/dao_impl/src/sales_person.rs @@ -112,7 +112,12 @@ impl SalesPersonDao for SalesPersonDaoImpl { Ok(()) } - async fn assign_to_user(&self, sales_person_id: Uuid, user_id: &str, process: &str) -> Result<(), DaoError> { + async fn assign_to_user( + &self, + sales_person_id: Uuid, + user_id: &str, + process: &str, + ) -> Result<(), DaoError> { let sales_person_id = sales_person_id.as_bytes().to_vec(); query!("INSERT INTO sales_person_user (user_id, sales_person_id, update_process) VALUES (?, ?, ?)", user_id, sales_person_id, process) .execute(self.pool.as_ref()) @@ -123,10 +128,13 @@ impl SalesPersonDao for SalesPersonDaoImpl { async fn discard_assigned_user(&self, sales_person_id: Uuid) -> Result<(), DaoError> { let sales_person_id = sales_person_id.as_bytes().to_vec(); - query!("DELETE FROM sales_person_user WHERE sales_person_id = ?", sales_person_id) - .execute(self.pool.as_ref()) - .await - .map_db_error()?; + query!( + "DELETE FROM sales_person_user WHERE sales_person_id = ?", + sales_person_id + ) + .execute(self.pool.as_ref()) + .await + .map_db_error()?; Ok(()) } diff --git a/rest/src/booking.rs b/rest/src/booking.rs index c525784..3273bc3 100644 --- a/rest/src/booking.rs +++ b/rest/src/booking.rs @@ -90,7 +90,10 @@ pub async fn get_booking( ) -> Response { error_handler( (async { - let booking = rest_state.booking_service().get(booking_id, ().into()).await?; + let booking = rest_state + .booking_service() + .get(booking_id, ().into()) + .await?; Ok(Response::builder() .status(200) .body(Body::new( @@ -129,7 +132,10 @@ pub async fn delete_booking( ) -> Response { error_handler( (async { - rest_state.booking_service().delete(booking_id, ().into()).await?; + rest_state + .booking_service() + .delete(booking_id, ().into()) + .await?; Ok(Response::builder().status(200).body(Body::empty()).unwrap()) }) .await, diff --git a/rest/src/sales_person.rs b/rest/src/sales_person.rs index ea0e44e..8c46167 100644 --- a/rest/src/sales_person.rs +++ b/rest/src/sales_person.rs @@ -162,7 +162,6 @@ pub async fn delete_sales_person( ) } - pub async fn get_sales_person_user( rest_state: State, Path(sales_person_id): Path, @@ -213,4 +212,4 @@ pub async fn delete_sales_person_user( }) .await, ) -} \ No newline at end of file +} diff --git a/rest/src/slot.rs b/rest/src/slot.rs index 3545575..73f27f8 100644 --- a/rest/src/slot.rs +++ b/rest/src/slot.rs @@ -127,7 +127,12 @@ pub async fn get_slot( ) -> Response { error_handler( (async { - let slot = SlotTO::from(&rest_state.slot_service().get_slot(&slot_id, ().into()).await?); + let slot = SlotTO::from( + &rest_state + .slot_service() + .get_slot(&slot_id, ().into()) + .await?, + ); Ok(Response::builder() .status(200) .body(Body::new(serde_json::to_string(&slot).unwrap())) diff --git a/service/src/booking.rs b/service/src/booking.rs index 6d5dc17..dab4e19 100644 --- a/service/src/booking.rs +++ b/service/src/booking.rs @@ -1,12 +1,12 @@ -use std::sync::Arc; use std::fmt::Debug; +use std::sync::Arc; use async_trait::async_trait; use time::PrimitiveDateTime; use uuid::Uuid; -use crate::ServiceError; use crate::permission::Authentication; +use crate::ServiceError; #[derive(Debug, Clone, PartialEq, Eq)] pub struct Booking { @@ -55,12 +55,23 @@ impl TryFrom<&Booking> for dao::booking::BookingEntity { pub trait BookingService { type Context: Clone + PartialEq + Eq + Debug + Send + Sync; - async fn get_all(&self, context: Authentication) -> Result, ServiceError>; - async fn get(&self, id: Uuid, context: Authentication) -> Result; + async fn get_all( + &self, + context: Authentication, + ) -> Result, ServiceError>; + async fn get( + &self, + id: Uuid, + context: Authentication, + ) -> Result; async fn create( &self, booking: &Booking, context: Authentication, ) -> Result; - async fn delete(&self, id: Uuid, context: Authentication) -> Result<(), ServiceError>; + async fn delete( + &self, + id: Uuid, + context: Authentication, + ) -> Result<(), ServiceError>; } diff --git a/service/src/permission.rs b/service/src/permission.rs index d915e9c..f09d894 100644 --- a/service/src/permission.rs +++ b/service/src/permission.rs @@ -1,5 +1,5 @@ -use std::sync::Arc; use std::fmt::Debug; +use std::sync::Arc; use async_trait::async_trait; use mockall::automock; @@ -43,11 +43,13 @@ impl From<&dao::PrivilegeEntity> for Privilege { } #[derive(Clone, Debug, PartialEq, Eq)] -pub enum Authentication{ +pub enum Authentication { Full, Context(Context), } -impl From for Authentication { +impl From + for Authentication +{ fn from(context: Context) -> Self { Self::Context(context) } @@ -64,14 +66,40 @@ pub trait PermissionService { context: Authentication, ) -> Result<(), ServiceError>; - async fn create_user(&self, user: &str, context: Authentication) -> Result<(), ServiceError>; - async fn user_exists(&self, user: &str, context: Authentication) -> Result; - async fn delete_user(&self, user: &str, context: Authentication) -> Result<(), ServiceError>; - async fn get_all_users(&self, context: Authentication) -> Result, ServiceError>; + async fn create_user( + &self, + user: &str, + context: Authentication, + ) -> Result<(), ServiceError>; + async fn user_exists( + &self, + user: &str, + context: Authentication, + ) -> Result; + async fn delete_user( + &self, + user: &str, + context: Authentication, + ) -> Result<(), ServiceError>; + async fn get_all_users( + &self, + context: Authentication, + ) -> Result, ServiceError>; - async fn create_role(&self, role: &str, context: Authentication) -> Result<(), ServiceError>; - async fn delete_role(&self, role: &str, context: Authentication) -> Result<(), ServiceError>; - async fn get_all_roles(&self, context: Authentication) -> Result, ServiceError>; + async fn create_role( + &self, + role: &str, + context: Authentication, + ) -> Result<(), ServiceError>; + async fn delete_role( + &self, + role: &str, + context: Authentication, + ) -> Result<(), ServiceError>; + async fn get_all_roles( + &self, + context: Authentication, + ) -> Result, ServiceError>; async fn create_privilege( &self, diff --git a/service/src/sales_person.rs b/service/src/sales_person.rs index 03896d4..857b150 100644 --- a/service/src/sales_person.rs +++ b/service/src/sales_person.rs @@ -1,12 +1,12 @@ -use std::sync::Arc; use std::fmt::Debug; +use std::sync::Arc; use async_trait::async_trait; use mockall::automock; use uuid::Uuid; -use crate::ServiceError; use crate::permission::Authentication; +use crate::ServiceError; #[derive(Clone, Debug, PartialEq, Eq)] pub struct SalesPerson { @@ -44,9 +44,20 @@ impl From<&SalesPerson> for dao::sales_person::SalesPersonEntity { pub trait SalesPersonService { type Context: Clone + Debug + PartialEq + Eq + Send + Sync + 'static; - async fn get_all(&self, context: Authentication) -> Result, ServiceError>; - async fn get(&self, id: Uuid, context: Authentication) -> Result; - async fn exists(&self, id: Uuid, context: Authentication) -> Result; + async fn get_all( + &self, + context: Authentication, + ) -> Result, ServiceError>; + async fn get( + &self, + id: Uuid, + context: Authentication, + ) -> Result; + async fn exists( + &self, + id: Uuid, + context: Authentication, + ) -> Result; async fn create( &self, item: &SalesPerson, @@ -57,7 +68,11 @@ pub trait SalesPersonService { item: &SalesPerson, context: Authentication, ) -> Result; - async fn delete(&self, id: Uuid, context: Authentication) -> Result<(), ServiceError>; + async fn delete( + &self, + id: Uuid, + context: Authentication, + ) -> Result<(), ServiceError>; async fn get_assigned_user( &self, sales_person_id: Uuid, diff --git a/service/src/slot.rs b/service/src/slot.rs index b89e638..f4a0787 100644 --- a/service/src/slot.rs +++ b/service/src/slot.rs @@ -1,11 +1,11 @@ use async_trait::async_trait; use mockall::automock; +use std::fmt::Debug; use std::sync::Arc; use uuid::Uuid; -use std::fmt::Debug; -use crate::ServiceError; use crate::permission::Authentication; +use crate::ServiceError; #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum DayOfWeek { @@ -89,10 +89,33 @@ impl From<&Slot> for dao::slot::SlotEntity { pub trait SlotService { type Context: Clone + Debug + PartialEq + Eq + Send + Sync + 'static; - async fn get_slots(&self, context: Authentication) -> Result, ServiceError>; - async fn get_slot(&self, id: &Uuid, context: Authentication) -> Result; - async fn exists(&self, id: Uuid, context: Authentication) -> Result; - async fn create_slot(&self, slot: &Slot, context: Authentication) -> Result; - async fn delete_slot(&self, id: &Uuid, context: Authentication) -> Result<(), ServiceError>; - async fn update_slot(&self, slot: &Slot, context: Authentication) -> Result<(), ServiceError>; + async fn get_slots( + &self, + context: Authentication, + ) -> Result, ServiceError>; + async fn get_slot( + &self, + id: &Uuid, + context: Authentication, + ) -> Result; + async fn exists( + &self, + id: Uuid, + context: Authentication, + ) -> Result; + async fn create_slot( + &self, + slot: &Slot, + context: Authentication, + ) -> Result; + async fn delete_slot( + &self, + id: &Uuid, + context: Authentication, + ) -> Result<(), ServiceError>; + async fn update_slot( + &self, + slot: &Slot, + context: Authentication, + ) -> Result<(), ServiceError>; } diff --git a/service/src/user_service.rs b/service/src/user_service.rs index 86b8ab2..4eb376b 100644 --- a/service/src/user_service.rs +++ b/service/src/user_service.rs @@ -1,5 +1,5 @@ -use std::sync::Arc; use std::fmt::Debug; +use std::sync::Arc; use async_trait::async_trait; use mockall::automock; diff --git a/service_impl/src/booking.rs b/service_impl/src/booking.rs index d45c06e..740c5ef 100644 --- a/service_impl/src/booking.rs +++ b/service_impl/src/booking.rs @@ -1,8 +1,8 @@ use async_trait::async_trait; use service::{ booking::{Booking, BookingService}, - ServiceError, ValidationFailureItem, permission::Authentication, + ServiceError, ValidationFailureItem, }; use std::sync::Arc; use uuid::Uuid; @@ -90,7 +90,10 @@ where { type Context = PermissionService::Context; - async fn get_all(&self, context: Authentication) -> Result, ServiceError> { + async fn get_all( + &self, + context: Authentication, + ) -> Result, ServiceError> { self.permission_service .check_permission("hr", context) .await?; @@ -103,7 +106,11 @@ where .collect()) } - async fn get(&self, id: Uuid, context: Authentication) -> Result { + async fn get( + &self, + id: Uuid, + context: Authentication, + ) -> Result { self.permission_service .check_permission("hr", context) .await?; @@ -149,22 +156,20 @@ where if booking.calendar_week > 53 { validation.push(ValidationFailureItem::InvalidValue("calendar_week".into())); } - if self + if !self .sales_person_service .exists(booking.sales_person_id, context.clone()) .await? - == false { validation.push(ValidationFailureItem::IdDoesNotExist( "sales_person_id".into(), booking.sales_person_id, )); } - if self + if !self .slot_service .exists(booking.slot_id, context.clone()) .await? - == false { validation.push(ValidationFailureItem::IdDoesNotExist( "slot_id".into(), @@ -178,7 +183,10 @@ where booking.slot_id, booking.calendar_week, booking.year, - ).await?.is_some() { + ) + .await? + .is_some() + { validation.push(ValidationFailureItem::Duplicate); } @@ -202,7 +210,11 @@ where Ok(new_booking) } - async fn delete(&self, id: Uuid, context: Authentication) -> Result<(), ServiceError> { + async fn delete( + &self, + id: Uuid, + context: Authentication, + ) -> Result<(), ServiceError> { self.permission_service .check_permission("hr", context) .await?; diff --git a/service_impl/src/permission.rs b/service_impl/src/permission.rs index fe923d5..5c81e38 100644 --- a/service_impl/src/permission.rs +++ b/service_impl/src/permission.rs @@ -1,8 +1,8 @@ use std::sync::Arc; use async_trait::async_trait; -use service::ServiceError; use service::permission::Authentication; +use service::ServiceError; pub struct PermissionServiceImpl where @@ -82,9 +82,17 @@ where Ok(()) } - async fn user_exists(&self, user: &str, context: Authentication) -> Result { + async fn user_exists( + &self, + user: &str, + context: Authentication, + ) -> Result { self.check_permission("hr", context).await?; - Ok(self.permission_dao.find_user(user).await.map(|x| x.is_some())?) + Ok(self + .permission_dao + .find_user(user) + .await + .map(|x| x.is_some())?) } async fn get_all_users( diff --git a/service_impl/src/sales_person.rs b/service_impl/src/sales_person.rs index d10e98f..8f8620b 100644 --- a/service_impl/src/sales_person.rs +++ b/service_impl/src/sales_person.rs @@ -2,7 +2,9 @@ use std::sync::Arc; use async_trait::async_trait; use dao::sales_person::SalesPersonEntity; -use service::{permission::Authentication, sales_person::SalesPerson, ServiceError, ValidationFailureItem}; +use service::{ + permission::Authentication, sales_person::SalesPerson, ServiceError, ValidationFailureItem, +}; use uuid::Uuid; pub struct SalesPersonServiceImpl @@ -86,7 +88,11 @@ where .ok_or(ServiceError::EntityNotFound(id)) } - async fn exists(&self, id: Uuid, _context: Authentication) -> Result { + async fn exists( + &self, + id: Uuid, + _context: Authentication, + ) -> Result { Ok(self .sales_person_dao .find_by_id(id) @@ -172,7 +178,11 @@ where Ok(sales_person) } - async fn delete(&self, id: Uuid, context: Authentication) -> Result<(), ServiceError> { + async fn delete( + &self, + id: Uuid, + context: Authentication, + ) -> Result<(), ServiceError> { self.permission_service .check_permission("hr", context) .await?; @@ -197,7 +207,10 @@ where self.permission_service .check_permission("hr", context) .await?; - Ok(self.sales_person_dao.get_assigned_user(sales_person_id).await?) + Ok(self + .sales_person_dao + .get_assigned_user(sales_person_id) + .await?) } async fn set_user( @@ -216,7 +229,6 @@ where self.sales_person_dao .assign_to_user(sales_person_id, user.as_ref(), SALES_PERSON_SERVICE_PROCESS) .await?; - } Ok(()) } diff --git a/service_impl/src/slot.rs b/service_impl/src/slot.rs index 9acf21d..b3ff026 100644 --- a/service_impl/src/slot.rs +++ b/service_impl/src/slot.rs @@ -60,7 +60,10 @@ where { type Context = PermissionService::Context; - async fn get_slots(&self, context: Authentication) -> Result, ServiceError> { + async fn get_slots( + &self, + context: Authentication, + ) -> Result, ServiceError> { let (hr_permission, sales_permission) = join!( self.permission_service .check_permission("hr", context.clone()), @@ -76,7 +79,11 @@ where .map(Slot::from) .collect()) } - async fn get_slot(&self, id: &Uuid, context: Authentication) -> Result { + async fn get_slot( + &self, + id: &Uuid, + context: Authentication, + ) -> Result { let (hr_permission, sales_permission) = join!( self.permission_service .check_permission("hr", context.clone()), @@ -92,11 +99,19 @@ where Ok(slot) } - async fn exists(&self, id: Uuid, _context: Authentication) -> Result { + async fn exists( + &self, + id: Uuid, + _context: Authentication, + ) -> Result { Ok(self.slot_dao.get_slot(&id).await.map(|s| s.is_some())?) } - async fn create_slot(&self, slot: &Slot, context: Authentication) -> Result { + async fn create_slot( + &self, + slot: &Slot, + context: Authentication, + ) -> Result { self.permission_service .check_permission("hr", context.clone()) .await?; @@ -137,7 +152,11 @@ where Ok(slot) } - async fn delete_slot(&self, id: &Uuid, context: Authentication) -> Result<(), ServiceError> { + async fn delete_slot( + &self, + id: &Uuid, + context: Authentication, + ) -> Result<(), ServiceError> { self.permission_service .check_permission("hr", context) .await?; @@ -152,7 +171,11 @@ where .await?; Ok(()) } - async fn update_slot(&self, slot: &Slot, context: Authentication) -> Result<(), ServiceError> { + async fn update_slot( + &self, + slot: &Slot, + context: Authentication, + ) -> Result<(), ServiceError> { self.permission_service .check_permission("hr", context) .await?; diff --git a/service_impl/src/test/booking.rs b/service_impl/src/test/booking.rs index e7750e0..a262689 100644 --- a/service_impl/src/test/booking.rs +++ b/service_impl/src/test/booking.rs @@ -2,14 +2,16 @@ use crate::test::error_test::*; use dao::booking::{BookingEntity, MockBookingDao}; use mockall::predicate::eq; use service::{ - booking::Booking, clock::MockClockService, sales_person::MockSalesPersonService, slot::MockSlotService, uuid_service::MockUuidService, MockPermissionService, ValidationFailureItem + booking::Booking, clock::MockClockService, sales_person::MockSalesPersonService, + slot::MockSlotService, uuid_service::MockUuidService, MockPermissionService, + ValidationFailureItem, }; use time::{Date, Month, PrimitiveDateTime, Time}; use uuid::{uuid, Uuid}; +use super::error_test::NoneTypeExt; use crate::booking::BookingServiceImpl; use service::booking::BookingService; -use super::error_test::NoneTypeExt; pub fn default_id() -> Uuid { uuid!("CEA260A0-112B-4970-936C-F7E529955BD0") @@ -94,7 +96,9 @@ impl BookingServiceDependencies { pub fn build_dependencies(permission: bool, role: &'static str) -> BookingServiceDependencies { let mut booking_dao = MockBookingDao::new(); - booking_dao.expect_find_by_booking_data().returning(|_, _, _, _| Ok(None)); + booking_dao + .expect_find_by_booking_data() + .returning(|_, _, _, _| Ok(None)); let mut permission_service = MockPermissionService::new(); permission_service .expect_check_permission() @@ -357,7 +361,12 @@ async fn test_create_booking_data_already_exists() { 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)) + .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 @@ -371,12 +380,7 @@ async fn test_create_booking_data_already_exists() { ().auth(), ) .await; - test_validation_error( - &result, - &ValidationFailureItem::Duplicate, - 1, - ); - + test_validation_error(&result, &ValidationFailureItem::Duplicate, 1); } #[tokio::test] diff --git a/service_impl/src/test/error_test.rs b/service_impl/src/test/error_test.rs index cf9a82f..f8a7e17 100644 --- a/service_impl/src/test/error_test.rs +++ b/service_impl/src/test/error_test.rs @@ -122,5 +122,4 @@ impl NoneTypeExt for () { fn auth(&self) -> Authentication<()> { Authentication::Context(()) } - } diff --git a/service_impl/src/test/permission_test.rs b/service_impl/src/test/permission_test.rs index 626b9a2..be59e55 100644 --- a/service_impl/src/test/permission_test.rs +++ b/service_impl/src/test/permission_test.rs @@ -30,7 +30,9 @@ async fn test_check_permission() { let permission_service = PermissionServiceImpl::new(Arc::new(permission_dao), Arc::new(user_service)); - let result = permission_service.check_permission("hello", ().auth()).await; + let result = permission_service + .check_permission("hello", ().auth()) + .await; result.expect("Expected successful authorization"); } @@ -40,7 +42,9 @@ async fn test_check_permission_denied() { let permission_service = PermissionServiceImpl::new(Arc::new(permission_dao), Arc::new(user_service)); - let result = permission_service.check_permission("hello", ().auth()).await; + let result = permission_service + .check_permission("hello", ().auth()) + .await; test_forbidden(&result); } diff --git a/service_impl/src/test/sales_person.rs b/service_impl/src/test/sales_person.rs index b9d4a3a..116637e 100644 --- a/service_impl/src/test/sales_person.rs +++ b/service_impl/src/test/sales_person.rs @@ -527,7 +527,10 @@ async fn test_exists() { .with(eq(default_id())) .returning(|_| Ok(Some(default_sales_person_entity()))); let sales_person_service = dependencies.build_service(); - let result = sales_person_service.exists(default_id(), ().auth()).await.unwrap(); + let result = sales_person_service + .exists(default_id(), ().auth()) + .await + .unwrap(); assert!(result); let mut dependencies = build_dependencies(true, "hr"); @@ -537,6 +540,9 @@ async fn test_exists() { .expect_find_by_id() .with(eq(default_id())) .returning(|_| Ok(None)); - let result = sales_person_service.exists(default_id(), ().auth()).await.unwrap(); + let result = sales_person_service + .exists(default_id(), ().auth()) + .await + .unwrap(); assert_eq!(false, !result); } diff --git a/service_impl/src/test/slot.rs b/service_impl/src/test/slot.rs index 7ac43c8..fa79f72 100644 --- a/service_impl/src/test/slot.rs +++ b/service_impl/src/test/slot.rs @@ -257,7 +257,9 @@ async fn test_create_slot() { async fn test_create_slot_no_permission() { let dependencies = build_dependencies(false, "hr"); let slot_service = dependencies.build_service(); - let result = slot_service.create_slot(&generate_default_slot(), ().auth()).await; + let result = slot_service + .create_slot(&generate_default_slot(), ().auth()) + .await; test_forbidden(&result); } @@ -568,7 +570,9 @@ async fn test_delete_slot_not_found() { async fn test_update_slot_no_permission() { let dependencies = build_dependencies(false, "hr"); let slot_service = dependencies.build_service(); - let result = slot_service.update_slot(&generate_default_slot(), ().auth()).await; + let result = slot_service + .update_slot(&generate_default_slot(), ().auth()) + .await; test_forbidden(&result); } @@ -582,7 +586,9 @@ async fn test_update_slot_not_found() { .times(1) .returning(|_| Ok(None)); let slot_service = dependencies.build_service(); - let result = slot_service.update_slot(&generate_default_slot(), ().auth()).await; + let result = slot_service + .update_slot(&generate_default_slot(), ().auth()) + .await; test_not_found(&result, &default_id()); }