feat: define get_username trait for forge out port
This commit is contained in:
parent
e1ae648c8b
commit
54840987b5
32
src/auth/application/port/out/forge/get_username.rs
Normal file
32
src/auth/application/port/out/forge/get_username.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use mockall::predicate::*;
|
||||
use mockall::*;
|
||||
|
||||
use super::errors::*;
|
||||
use crate::auth::domain::OAuthAccessToken;
|
||||
|
||||
#[automock]
|
||||
#[async_trait::async_trait]
|
||||
pub trait GetUsername: Send + Sync {
|
||||
async fn get_username(&self, access_token: &OAuthAccessToken) -> OutForgePortResult<String>;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use super::*;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn mock_get_username(username: String, times: Option<usize>) -> Arc<dyn GetUsername> {
|
||||
let mut m = MockGetUsername::default();
|
||||
if let Some(times) = times {
|
||||
m.expect_get_username()
|
||||
.times(times)
|
||||
.returning(move |_| Ok(username.clone()));
|
||||
} else {
|
||||
m.expect_get_username()
|
||||
.returning(move |_| Ok(username.clone()));
|
||||
}
|
||||
|
||||
Arc::new(m)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue