From e3996134e4c66df6c691c65793a82fcd1f9b8905 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Mon, 12 Sep 2022 01:39:37 +0530 Subject: [PATCH] chore: refactor: use api::v1::services and tests::get_ctx --- src/deploy.rs | 4 ++-- src/meta.rs | 9 ++++----- src/routes.rs | 30 +----------------------------- 3 files changed, 7 insertions(+), 36 deletions(-) diff --git a/src/deploy.rs b/src/deploy.rs index a8c0b19..d217a37 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -127,7 +127,7 @@ mod tests { #[actix_rt::test] async fn deploy_update_works() { - let (_dir, ctx) = tests::get_data().await; + let (_dir, ctx) = tests::get_ctx().await; println!("[log] test configuration {:#?}", ctx.settings); let app = get_app!(ctx).await; let page = ctx.settings.pages.get(0); @@ -157,7 +157,7 @@ mod tests { #[actix_rt::test] async fn deploy_info_works() { - let (_dir, ctx) = tests::get_data().await; + let (_dir, ctx) = tests::get_ctx().await; println!("[log] test configuration {:#?}", ctx.settings); let page = ctx.settings.pages.get(0); let page = page.unwrap(); diff --git a/src/meta.rs b/src/meta.rs index 07195e2..32e1be7 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -42,7 +42,7 @@ pub mod routes { } } -/// emmits build details of the bninary +/// emits build details of the binary #[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.meta.build_details")] async fn build_details(ctx: AppCtx) -> impl Responder { let build = BuildDetails { @@ -82,7 +82,7 @@ mod tests { #[actix_rt::test] async fn build_details_works() { - let (_dir, ctx) = tests::get_data().await; + let (_dir, ctx) = tests::get_ctx().await; println!("[log] test configuration {:#?}", ctx.settings); let app = get_app!(ctx).await; @@ -94,9 +94,8 @@ mod tests { async fn health_works() { use actix_web::test; - let settings = Settings::new().unwrap(); - let ctx = AppCtx::new(crate::ctx::Ctx::new(settings).await); - let app = test::init_service(App::new().app_data(ctx.clone()).configure(services)).await; + let (_dir, ctx) = tests::get_ctx().await; + let app = get_app!(ctx).await; let resp = test::call_service( &app, diff --git a/src/routes.rs b/src/routes.rs index d022baa..99210a9 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -14,32 +14,4 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -use actix_web::web; - -use crate::deploy::routes::Deploy; -use crate::meta::routes::Meta; -use crate::serve::routes::Serve; - -pub const ROUTES: Routes = Routes::new(); - -pub struct Routes { - pub meta: Meta, - pub deploy: Deploy, - pub serve: Serve, -} - -impl Routes { - pub const fn new() -> Self { - Self { - meta: Meta::new(), - deploy: Deploy::new(), - serve: Serve::new(), - } - } -} - -pub fn services(cfg: &mut web::ServiceConfig) { - crate::meta::services(cfg); - crate::deploy::services(cfg); - crate::serve::services(cfg); -} +pub use crate::api::v1::{routes::ROUTES, services};