mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 00:31:02 +00:00
add test for search + update ci for test in release
This commit is contained in:
@ -1,16 +1,18 @@
|
||||
#![allow(dead_code)]
|
||||
use std::error::Error;
|
||||
use std::time::Duration;
|
||||
|
||||
use tempdir::TempDir;
|
||||
use tide::server::Service;
|
||||
use http_service::Body;
|
||||
use http_service_mock::{make_server, TestBackend};
|
||||
use meilisearch_http::data::Data;
|
||||
use meilisearch_http::option::Opt;
|
||||
use meilisearch_http::routes;
|
||||
use serde_json::json;
|
||||
use tempdir::TempDir;
|
||||
use tide::server::Service;
|
||||
use async_std::task::{block_on, sleep};
|
||||
|
||||
use http_service_mock::{make_server, TestBackend};
|
||||
|
||||
|
||||
pub fn setup_server() -> Result<TestBackend<Service<Data>>, Box<dyn Error>>{
|
||||
|
||||
pub fn setup_server() -> Result<TestBackend<Service<Data>>, Box<dyn Error>> {
|
||||
let tmp_dir = TempDir::new("meilisearch")?;
|
||||
|
||||
let opt = Opt {
|
||||
@ -26,3 +28,86 @@ pub fn setup_server() -> Result<TestBackend<Service<Data>>, Box<dyn Error>>{
|
||||
let http_server = app.into_http_service();
|
||||
Ok(make_server(http_server)?)
|
||||
}
|
||||
|
||||
pub fn enrich_server_with_movies_index(server: &mut TestBackend<Service<Data>>) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
}).to_string().into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
|
||||
println!("enrich_server_with_movies_index: {:?}", res.status());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn enrich_server_with_movies_settings(server: &mut TestBackend<Service<Data>>) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let json = json!({
|
||||
"rankingRules": [
|
||||
"_typo",
|
||||
"_words",
|
||||
"_proximity",
|
||||
"_attribute",
|
||||
"_words_position",
|
||||
"dsc(popularity)",
|
||||
"_exact",
|
||||
"dsc(vote_average)",
|
||||
],
|
||||
"rankingDistinct": null,
|
||||
"attributeIdentifier": "id",
|
||||
"attributesSearchable": [
|
||||
"title",
|
||||
"tagline",
|
||||
"overview",
|
||||
"cast",
|
||||
"director",
|
||||
"producer",
|
||||
"production_companies",
|
||||
"genres",
|
||||
],
|
||||
"attributesDisplayed": [
|
||||
"title",
|
||||
"director",
|
||||
"producer",
|
||||
"tagline",
|
||||
"genres",
|
||||
"id",
|
||||
"overview",
|
||||
"vote_count",
|
||||
"vote_average",
|
||||
"poster_path",
|
||||
"popularity",
|
||||
],
|
||||
"stopWords": null,
|
||||
"synonyms": null
|
||||
});
|
||||
|
||||
let body = json.to_string().into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes/movies/settings").body(Body::from(body)).unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
|
||||
println!("enrich_server_with_movies_settings: {:?}", res.status());
|
||||
|
||||
block_on(sleep(Duration::from_secs(5)));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn enrich_server_with_movies_documents(server: &mut TestBackend<Service<Data>>) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let body = include_bytes!("assets/movies.json").to_vec();
|
||||
|
||||
let req = http::Request::post("/indexes/movies/documents").body(Body::from(body)).unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
|
||||
println!("enrich_server_with_movies_documents: {:?}", res.status());
|
||||
|
||||
block_on(sleep(Duration::from_secs(5)));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user