refactor: search engine and add debug index test

This commit is contained in:
Alex Wellnitz 2024-02-13 08:53:18 +01:00
parent d510178127
commit a75a278088
2 changed files with 21 additions and 1 deletions

View File

@ -38,7 +38,6 @@ fn normalize_string(input_string: &str) -> String {
/// println!("{} - Relevance Score: {}", url, score);
/// }
/// ```
#[derive(Default, Debug, Clone)]
pub struct SearchEngine {
index: HashMap<String, HashMap<String, i32>>,

View File

@ -81,4 +81,25 @@ mod tests {
let resp = test::call_service(&app, req).await;
assert!(resp.status() == 200);
}
#[actix_web::test]
async fn test_debug_index() {
let search_engine = SearchEngine::new(1.5, 0.75);
let app_state = web::Data::new(AppStateWithSearchEngine {
search_engine: Mutex::new(search_engine.clone()),
});
let app = test::init_service(App::new()
.app_data(app_state.clone())
.route("/search/debug", web::get().to(search::debug_index))
).await;
let req = test::TestRequest::get()
.uri("/search/debug")
.to_request();
let resp = test::call_service(&app, req).await;
assert!(resp.status() == 200);
}
}