ForgeFlux/src/auth/application/port/out/db/oauth_state_exists.rs

43 lines
1 KiB
Rust

use mockall::predicate::*;
use mockall::*;
use url::Url;
use super::errors::*;
#[automock]
#[async_trait::async_trait]
pub trait OAuthStateExists: Send + Sync {
/// Save OAuth state code generated during authorization request, which will later be used to
/// validate authorization response from OAuth server
async fn oauth_state_exists(
&self,
state: &str,
oauth_provider: &str,
redirect_uri: &Url,
) -> OutDBPortResult<bool>;
}
#[cfg(test)]
pub mod tests {
use super::*;
use std::sync::Arc;
pub fn mock_oauth_state_exists(
times: Option<usize>,
return_val: bool,
) -> Arc<dyn OAuthStateExists> {
let mut m = MockOAuthStateExists::default();
if let Some(times) = times {
m.expect_oauth_state_exists()
.times(times)
.returning(move |_, _, _| Ok(return_val));
} else {
m.expect_oauth_state_exists()
.returning(move |_, _, _| Ok(return_val));
}
Arc::new(m)
}
}