Add unit tests for the services

This commit is contained in:
Simon Goller 2024-04-27 00:03:15 +02:00
parent 926ac006e7
commit 3b20d12ba1
9 changed files with 231 additions and 12 deletions

View file

@ -3,6 +3,10 @@ name = "service"
version = "0.1.0"
edition = "2021"
[dependencies]
async-trait = "0.1.80"
mockall = "0.12.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies.thiserror]
@ -10,3 +14,6 @@ version = "1.0"
[dependencies.dao]
path = "../dao"
[dev-dependencies.tokio]
version = "1.37.0"

View file

@ -1,3 +1,5 @@
use async_trait::async_trait;
use mockall::automock;
use std::{future::Future, sync::Arc};
use thiserror::Error;
@ -10,17 +12,19 @@ pub enum ServiceError {
Forbidden,
}
#[automock]
pub trait HelloService {
fn hello(&self) -> impl Future<Output = Result<Arc<str>, ServiceError>> + Send;
}
#[automock]
#[async_trait]
pub trait PermissionService {
fn check_permission(
&self,
privilege: &str,
) -> impl Future<Output = Result<(), ServiceError>> + Send;
async fn check_permission(&self, privilege: &str) -> Result<(), ServiceError>;
}
#[automock]
#[async_trait]
pub trait UserService {
fn current_user(&self) -> impl Future<Output = Result<Arc<str>, ServiceError>> + Send;
async fn current_user(&self) -> Result<Arc<str>, ServiceError>;
}