Регистрация и тесты эндпоинтов

This commit is contained in:
2025-03-23 06:11:13 +04:00
parent 844c89a365
commit a95494d3be
16 changed files with 822 additions and 176 deletions

27
src/test_env.rs Normal file
View File

@@ -0,0 +1,27 @@
#[cfg(test)]
pub(crate) mod tests {
use crate::app_state::{AppState, app_state};
use actix_web::dev::{HttpServiceFactory, Service, ServiceResponse};
use actix_web::{App, test, web};
use std::sync::LazyLock;
pub fn test_env() {
dotenvy::from_path(".env.test").expect("Failed to load test environment file");
}
pub async fn test_app<F>(
app_state: web::Data<AppState>,
factory: F,
) -> impl Service<actix_http::Request, Response = ServiceResponse, Error = actix_web::Error>
where
F: HttpServiceFactory + 'static,
{
test::init_service(App::new().app_data(app_state).service(factory)).await
}
pub fn static_app_state() -> web::Data<AppState> {
static STATE: LazyLock<web::Data<AppState>> = LazyLock::new(|| app_state());
STATE.clone()
}
}