Skip to content

Commit

Permalink
refactor(api): [torrust#178] axum API, 'about' context migrated
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Jun 8, 2023
1 parent 488cd07 commit 1924365
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/web/api/v1/contexts/about/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ pub async fn about_page_handler(State(_app_data): State<Arc<AppData>>) -> Respon
)
.into_response()
}

#[allow(clippy::unused_async)]
pub async fn license_page_handler(State(_app_data): State<Arc<AppData>>) -> Response {
(
StatusCode::OK,
[(header::CONTENT_TYPE, "text/html; charset=utf-8")],
about::license_page(),
)
.into_response()
}
12 changes: 10 additions & 2 deletions src/web/api/v1/contexts/about/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ use std::sync::Arc;
use axum::routing::get;
use axum::Router;

use super::handlers::about_page_handler;
use super::handlers::{about_page_handler, license_page_handler};
use crate::common::AppData;

/// It adds the routes to the router for the [`about`](crate::web::api::v1::contexts::about) API context.
pub fn add(prefix: &str, router: Router, app_data: Arc<AppData>) -> Router {
router.route(&format!("{prefix}/about"), get(about_page_handler).with_state(app_data))
router
.route(
&format!("{prefix}/about"),
get(about_page_handler).with_state(app_data.clone()),
)
.route(
&format!("{prefix}/about/license"),
get(license_page_handler).with_state(app_data),
)
}
12 changes: 12 additions & 0 deletions tests/e2e/contexts/about/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,16 @@ mod with_axum_implementation {
assert_text_ok(&response);
assert_response_title(&response, "About");
}

#[tokio::test]
async fn it_should_load_the_license_page_at_the_api_entrypoint() {
let mut env = TestEnv::new();
env.start(api::Implementation::Axum).await;
let client = Client::unauthenticated(&env.server_socket_addr().unwrap());

let response = client.license().await;

assert_text_ok(&response);
assert_response_title(&response, "Licensing");
}
}

0 comments on commit 1924365

Please sign in to comment.