ctb_io_webui/controllers/
search.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3This file is part of Collective Toolbox, a database and document workspace and utilities.
4Copyright (C) 2026 Collective Toolbox Developers
5Contact: info@collectivetoolbox.com
6
7This program is free software: you can redistribute it and/or modify it under
8the terms of the GNU Affero General Public License as published by the Free
9Software Foundation, either version 3 of the License, or (at your option) any
10later version.
11
12This program is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
15
16You should have received a copy of the GNU Affero General Public License along
17with this program.  If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! Controller for the graph search tools.
21
22use axum::{extract::State, response::Response};
23
24use crate::json_value;
25use crate::session_auth::AuthenticatedUser;
26use crate::{AppState, RequestState, respond_page};
27
28pub async fn get_index(
29    State(state): State<AppState>,
30    req: RequestState,
31    _user: AuthenticatedUser,
32) -> Response {
33    respond_page(&state, req, "search.index", &json_value!({}))
34}
35
36#[cfg(test)]
37#[allow(
38    clippy::panic,
39    clippy::expect_used,
40    clippy::unwrap_used,
41    clippy::unwrap_in_result,
42    clippy::panic_in_result_fn,
43    clippy::indexing_slicing,
44    clippy::arithmetic_side_effects,
45    reason = "Standard repository test boilerplate"
46)]
47mod tests {
48    use crate::test_helpers::{
49        assert_eq_or_print_body, assert_or_print_body, test_get_with_login,
50    };
51
52    #[crate::ctb_test("tokio")]
53    async fn can_get_index() {
54        let Ok((status, body, _lock)) =
55            test_get_with_login("/search", None, function_name!()).await
56        else {
57            panic!("Failed to perform test_get_with_login");
58        };
59        assert_eq_or_print_body(status, 200, &body);
60        assert_or_print_body(body.contains("name=\"search-text\""), &body);
61    }
62}