You've already forked AstralRinth
forked from didirus/AstralRinth
Expose test utils to Labrinth dependents (#4703)
* Expose test utils to Labrinth dependents * Feature gate `labrinth::test` * Unify db migrators * Expose `NotificationBuilder::insert_many_deliveries` * Add logging utils to common crate * Remove unused console-subscriber layer * fix CI
This commit is contained in:
61
apps/labrinth/src/test/api_v3/mod.rs
Normal file
61
apps/labrinth/src/test/api_v3/mod.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use super::{
|
||||
api_common::{Api, ApiBuildable},
|
||||
environment::LocalService,
|
||||
};
|
||||
use crate::LabrinthConfig;
|
||||
use actix_web::{App, dev::ServiceResponse, test};
|
||||
use async_trait::async_trait;
|
||||
use std::rc::Rc;
|
||||
use utoipa_actix_web::AppExt;
|
||||
|
||||
pub mod collections;
|
||||
pub mod limits;
|
||||
pub mod oauth;
|
||||
pub mod oauth_clients;
|
||||
pub mod organization;
|
||||
pub mod project;
|
||||
pub mod request_data;
|
||||
pub mod tags;
|
||||
pub mod team;
|
||||
pub mod user;
|
||||
pub mod version;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ApiV3 {
|
||||
pub test_app: Rc<dyn LocalService>,
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl ApiBuildable for ApiV3 {
|
||||
async fn build(labrinth_config: LabrinthConfig) -> Self {
|
||||
let app = App::new()
|
||||
.into_utoipa_app()
|
||||
.configure(|cfg| {
|
||||
crate::utoipa_app_config(cfg, labrinth_config.clone())
|
||||
})
|
||||
.into_app()
|
||||
.configure(|cfg| crate::app_config(cfg, labrinth_config.clone()));
|
||||
let test_app: Rc<dyn LocalService> =
|
||||
Rc::new(test::init_service(app).await);
|
||||
|
||||
Self { test_app }
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl Api for ApiV3 {
|
||||
async fn call(&self, req: actix_http::Request) -> ServiceResponse {
|
||||
self.test_app.call(req).await.unwrap()
|
||||
}
|
||||
|
||||
async fn reset_search_index(&self) -> ServiceResponse {
|
||||
let req = actix_web::test::TestRequest::post()
|
||||
.uri("/_internal/admin/_force_reindex")
|
||||
.append_header((
|
||||
"Modrinth-Admin",
|
||||
dotenvy::var("LABRINTH_ADMIN_KEY").unwrap(),
|
||||
))
|
||||
.to_request();
|
||||
self.call(req).await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user