Cargo clippy and cargo fmt

This commit is contained in:
Simon Goller 2024-05-09 15:00:50 +02:00
parent b0000c0117
commit ed609cf06c
22 changed files with 286 additions and 94 deletions

View file

@ -24,7 +24,13 @@ pub struct BookingEntity {
pub trait BookingDao {
async fn all(&self) -> Result<Arc<[BookingEntity]>, DaoError>;
async fn find_by_id(&self, id: Uuid) -> Result<Option<BookingEntity>, DaoError>;
async fn find_by_booking_data(&self, sales_person_id: Uuid, slot_id: Uuid, calendar_week: i32, year: u32) -> Result<Option<BookingEntity>, DaoError>;
async fn find_by_booking_data(
&self,
sales_person_id: Uuid,
slot_id: Uuid,
calendar_week: i32,
year: u32,
) -> Result<Option<BookingEntity>, DaoError>;
async fn create(&self, entity: &BookingEntity, process: &str) -> Result<(), DaoError>;
async fn update(&self, entity: &BookingEntity, process: &str) -> Result<(), DaoError>;
}

View file

@ -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<Option<Arc<str>>, 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>;
}

View file

@ -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<Option<BookingEntity>, DaoError> {
async fn find_by_booking_data(
&self,
sales_person_id: Uuid,
slot_id: Uuid,
calendar_week: i32,
year: u32,
) -> Result<Option<BookingEntity>, 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,

View file

@ -92,13 +92,10 @@ impl dao::PermissionDao for PermissionDaoImpl {
Ok(())
}
async fn find_user(&self, username: &str) -> Result<Option<dao::UserEntity>, 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(),
}))

View file

@ -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(())
}

View file

@ -90,7 +90,10 @@ pub async fn get_booking<RestState: RestStateDef>(
) -> 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<RestState: RestStateDef>(
) -> 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,

View file

@ -162,7 +162,6 @@ pub async fn delete_sales_person<RestState: RestStateDef>(
)
}
pub async fn get_sales_person_user<RestState: RestStateDef>(
rest_state: State<RestState>,
Path(sales_person_id): Path<Uuid>,
@ -213,4 +212,4 @@ pub async fn delete_sales_person_user<RestState: RestStateDef>(
})
.await,
)
}
}

View file

@ -127,7 +127,12 @@ pub async fn get_slot<RestState: RestStateDef>(
) -> 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()))

View file

@ -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<Self::Context>) -> Result<Arc<[Booking]>, ServiceError>;
async fn get(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<Booking, ServiceError>;
async fn get_all(
&self,
context: Authentication<Self::Context>,
) -> Result<Arc<[Booking]>, ServiceError>;
async fn get(
&self,
id: Uuid,
context: Authentication<Self::Context>,
) -> Result<Booking, ServiceError>;
async fn create(
&self,
booking: &Booking,
context: Authentication<Self::Context>,
) -> Result<Booking, ServiceError>;
async fn delete(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<(), ServiceError>;
async fn delete(
&self,
id: Uuid,
context: Authentication<Self::Context>,
) -> Result<(), ServiceError>;
}

View file

@ -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<Context: Clone + PartialEq + Eq + Send + Sync + Debug + 'static>{
pub enum Authentication<Context: Clone + PartialEq + Eq + Send + Sync + Debug + 'static> {
Full,
Context(Context),
}
impl<Context: Clone + Debug + PartialEq + Eq + Send + Sync + 'static> From<Context> for Authentication<Context> {
impl<Context: Clone + Debug + PartialEq + Eq + Send + Sync + 'static> From<Context>
for Authentication<Context>
{
fn from(context: Context) -> Self {
Self::Context(context)
}
@ -64,14 +66,40 @@ pub trait PermissionService {
context: Authentication<Self::Context>,
) -> Result<(), ServiceError>;
async fn create_user(&self, user: &str, context: Authentication<Self::Context>) -> Result<(), ServiceError>;
async fn user_exists(&self, user: &str, context: Authentication<Self::Context>) -> Result<bool, ServiceError>;
async fn delete_user(&self, user: &str, context: Authentication<Self::Context>) -> Result<(), ServiceError>;
async fn get_all_users(&self, context: Authentication<Self::Context>) -> Result<Arc<[User]>, ServiceError>;
async fn create_user(
&self,
user: &str,
context: Authentication<Self::Context>,
) -> Result<(), ServiceError>;
async fn user_exists(
&self,
user: &str,
context: Authentication<Self::Context>,
) -> Result<bool, ServiceError>;
async fn delete_user(
&self,
user: &str,
context: Authentication<Self::Context>,
) -> Result<(), ServiceError>;
async fn get_all_users(
&self,
context: Authentication<Self::Context>,
) -> Result<Arc<[User]>, ServiceError>;
async fn create_role(&self, role: &str, context: Authentication<Self::Context>) -> Result<(), ServiceError>;
async fn delete_role(&self, role: &str, context: Authentication<Self::Context>) -> Result<(), ServiceError>;
async fn get_all_roles(&self, context: Authentication<Self::Context>) -> Result<Arc<[Role]>, ServiceError>;
async fn create_role(
&self,
role: &str,
context: Authentication<Self::Context>,
) -> Result<(), ServiceError>;
async fn delete_role(
&self,
role: &str,
context: Authentication<Self::Context>,
) -> Result<(), ServiceError>;
async fn get_all_roles(
&self,
context: Authentication<Self::Context>,
) -> Result<Arc<[Role]>, ServiceError>;
async fn create_privilege(
&self,

View file

@ -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<Self::Context>) -> Result<Arc<[SalesPerson]>, ServiceError>;
async fn get(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<SalesPerson, ServiceError>;
async fn exists(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<bool, ServiceError>;
async fn get_all(
&self,
context: Authentication<Self::Context>,
) -> Result<Arc<[SalesPerson]>, ServiceError>;
async fn get(
&self,
id: Uuid,
context: Authentication<Self::Context>,
) -> Result<SalesPerson, ServiceError>;
async fn exists(
&self,
id: Uuid,
context: Authentication<Self::Context>,
) -> Result<bool, ServiceError>;
async fn create(
&self,
item: &SalesPerson,
@ -57,7 +68,11 @@ pub trait SalesPersonService {
item: &SalesPerson,
context: Authentication<Self::Context>,
) -> Result<SalesPerson, ServiceError>;
async fn delete(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<(), ServiceError>;
async fn delete(
&self,
id: Uuid,
context: Authentication<Self::Context>,
) -> Result<(), ServiceError>;
async fn get_assigned_user(
&self,
sales_person_id: Uuid,

View file

@ -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<Self::Context>) -> Result<Arc<[Slot]>, ServiceError>;
async fn get_slot(&self, id: &Uuid, context: Authentication<Self::Context>) -> Result<Slot, ServiceError>;
async fn exists(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<bool, ServiceError>;
async fn create_slot(&self, slot: &Slot, context: Authentication<Self::Context>) -> Result<Slot, ServiceError>;
async fn delete_slot(&self, id: &Uuid, context: Authentication<Self::Context>) -> Result<(), ServiceError>;
async fn update_slot(&self, slot: &Slot, context: Authentication<Self::Context>) -> Result<(), ServiceError>;
async fn get_slots(
&self,
context: Authentication<Self::Context>,
) -> Result<Arc<[Slot]>, ServiceError>;
async fn get_slot(
&self,
id: &Uuid,
context: Authentication<Self::Context>,
) -> Result<Slot, ServiceError>;
async fn exists(
&self,
id: Uuid,
context: Authentication<Self::Context>,
) -> Result<bool, ServiceError>;
async fn create_slot(
&self,
slot: &Slot,
context: Authentication<Self::Context>,
) -> Result<Slot, ServiceError>;
async fn delete_slot(
&self,
id: &Uuid,
context: Authentication<Self::Context>,
) -> Result<(), ServiceError>;
async fn update_slot(
&self,
slot: &Slot,
context: Authentication<Self::Context>,
) -> Result<(), ServiceError>;
}

View file

@ -1,5 +1,5 @@
use std::sync::Arc;
use std::fmt::Debug;
use std::sync::Arc;
use async_trait::async_trait;
use mockall::automock;

View file

@ -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<Self::Context>) -> Result<Arc<[Booking]>, ServiceError> {
async fn get_all(
&self,
context: Authentication<Self::Context>,
) -> Result<Arc<[Booking]>, ServiceError> {
self.permission_service
.check_permission("hr", context)
.await?;
@ -103,7 +106,11 @@ where
.collect())
}
async fn get(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<Booking, ServiceError> {
async fn get(
&self,
id: Uuid,
context: Authentication<Self::Context>,
) -> Result<Booking, ServiceError> {
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<Self::Context>) -> Result<(), ServiceError> {
async fn delete(
&self,
id: Uuid,
context: Authentication<Self::Context>,
) -> Result<(), ServiceError> {
self.permission_service
.check_permission("hr", context)
.await?;

View file

@ -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<PermissionDao, UserService>
where
@ -82,9 +82,17 @@ where
Ok(())
}
async fn user_exists(&self, user: &str, context: Authentication<Self::Context>) -> Result<bool, ServiceError> {
async fn user_exists(
&self,
user: &str,
context: Authentication<Self::Context>,
) -> Result<bool, ServiceError> {
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(

View file

@ -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<SalesPersonDao, PermissionService, ClockService, UuidService>
@ -86,7 +88,11 @@ where
.ok_or(ServiceError::EntityNotFound(id))
}
async fn exists(&self, id: Uuid, _context: Authentication<Self::Context>) -> Result<bool, ServiceError> {
async fn exists(
&self,
id: Uuid,
_context: Authentication<Self::Context>,
) -> Result<bool, ServiceError> {
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<Self::Context>) -> Result<(), ServiceError> {
async fn delete(
&self,
id: Uuid,
context: Authentication<Self::Context>,
) -> 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(())
}

View file

@ -60,7 +60,10 @@ where
{
type Context = PermissionService::Context;
async fn get_slots(&self, context: Authentication<Self::Context>) -> Result<Arc<[Slot]>, ServiceError> {
async fn get_slots(
&self,
context: Authentication<Self::Context>,
) -> Result<Arc<[Slot]>, 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<Self::Context>) -> Result<Slot, ServiceError> {
async fn get_slot(
&self,
id: &Uuid,
context: Authentication<Self::Context>,
) -> Result<Slot, ServiceError> {
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<Self::Context>) -> Result<bool, ServiceError> {
async fn exists(
&self,
id: Uuid,
_context: Authentication<Self::Context>,
) -> Result<bool, ServiceError> {
Ok(self.slot_dao.get_slot(&id).await.map(|s| s.is_some())?)
}
async fn create_slot(&self, slot: &Slot, context: Authentication<Self::Context>) -> Result<Slot, ServiceError> {
async fn create_slot(
&self,
slot: &Slot,
context: Authentication<Self::Context>,
) -> Result<Slot, ServiceError> {
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<Self::Context>) -> Result<(), ServiceError> {
async fn delete_slot(
&self,
id: &Uuid,
context: Authentication<Self::Context>,
) -> 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<Self::Context>) -> Result<(), ServiceError> {
async fn update_slot(
&self,
slot: &Slot,
context: Authentication<Self::Context>,
) -> Result<(), ServiceError> {
self.permission_service
.check_permission("hr", context)
.await?;

View file

@ -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]

View file

@ -122,5 +122,4 @@ impl NoneTypeExt for () {
fn auth(&self) -> Authentication<()> {
Authentication::Context(())
}
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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());
}