update tests & fix the broken code

This commit is contained in:
Quentin de Quelen 2020-04-16 11:09:47 +02:00 committed by qdequele
parent 5e2861ff55
commit 27b3b53bc5
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
17 changed files with 554 additions and 555 deletions

View File

@ -47,7 +47,7 @@ actix-http = "1"
actix-files = "0.2.1"
actix-cors = "0.2.0"
actix-service = "1.0.5"
tokio = { version = "0.2.0", features = ["macros"] }
tokio = { version = "0.2.18", features = ["macros", "time"] }
[dev-dependencies]
http-service = "0.4.0"

View File

@ -26,8 +26,8 @@ pub enum ResponseError {
impl fmt::Display for ResponseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Internal(err) => write!(f, "Internal server error: {}", err),
Self::BadRequest(err) => write!(f, "Bad request: {}", err),
Self::Internal(err) => write!(f, "{}", err),
Self::BadRequest(err) => write!(f, "{}", err),
Self::MissingAuthorizationHeader => write!(f, "You must have an authorization token"),
Self::InvalidToken(err) => write!(f, "Invalid API key: {}", err),
Self::NotFound(err) => write!(f, "{} not found", err),

View File

@ -28,6 +28,7 @@ pub fn create_app(
> {
App::new()
.app_data(web::Data::new(data.clone()))
.app_data(web::JsonConfig::default().limit(1024 * 1024 * 10)) // Json Limit of 10Mb
.wrap(helpers::Authentication::Public)
.service(routes::load_html)
.service(routes::load_css)

View File

@ -22,7 +22,7 @@ pub struct DocumentParam {
pub async fn get_document(
data: web::Data<Data>,
path: web::Path<DocumentParam>,
) -> aweb::Result<web::Json<Document>> {
) -> aweb::Result<HttpResponse> {
let index = data
.db
.open_index(&path.index_uid)
@ -39,7 +39,7 @@ pub async fn get_document(
.map_err(|_| ResponseError::DocumentNotFound(path.document_id.clone()))?
.ok_or(ResponseError::DocumentNotFound(path.document_id.clone()))?;
Ok(web::Json(response))
Ok(HttpResponse::Ok().json(response))
}
#[delete("/indexes/{index_uid}/documents/{document_id}")]
@ -85,7 +85,7 @@ pub async fn get_all_documents(
data: web::Data<Data>,
path: web::Path<IndexParam>,
params: web::Query<BrowseQuery>,
) -> aweb::Result<web::Json<Vec<Document>>> {
) -> aweb::Result<HttpResponse> {
let index = data
.db
.open_index(&path.index_uid)
@ -114,14 +114,14 @@ pub async fn get_all_documents(
.clone()
.map(|a| a.split(',').map(|a| a.to_string()).collect());
let mut response_body = Vec::<Document>::new();
let mut response = Vec::<Document>::new();
for document_id in documents_ids {
if let Ok(Some(document)) = index.document(&reader, attributes.clone(), document_id) {
response_body.push(document);
response.push(document);
}
}
Ok(web::Json(response_body))
Ok(HttpResponse::Ok().json(response))
}
fn find_primary_key(document: &IndexMap<String, Value>) -> Option<String> {
@ -168,7 +168,7 @@ async fn update_multiple_documents(
let id = match params.primary_key.clone() {
Some(id) => id,
None => body.first().and_then(|docs| find_primary_key(docs)).ok_or(
ResponseError::BadRequest("Impossible to infer the primary key".to_string()),
ResponseError::BadRequest("Could not infer a primary key".to_string()),
)?,
};

View File

@ -1,8 +1,7 @@
use actix_web as aweb;
use actix_web::{delete, get, post, web, HttpResponse};
use actix_web::{delete, get, post, put, web, HttpResponse};
use chrono::{DateTime, Utc};
use log::error;
use meilisearch_core::UpdateStatus;
use rand::seq::SliceRandom;
use serde::{Deserialize, Serialize};
@ -30,13 +29,13 @@ pub struct IndexResponse {
}
#[get("/indexes")]
pub async fn list_indexes(data: web::Data<Data>) -> aweb::Result<web::Json<Vec<IndexResponse>>> {
pub async fn list_indexes(data: web::Data<Data>) -> aweb::Result<HttpResponse> {
let reader = data
.db
.main_read_txn()
.map_err(|err| ResponseError::Internal(err.to_string()))?;
let mut response_body = Vec::new();
let mut response = Vec::new();
for index_uid in data.db.indexes_uids() {
let index = data.db.open_index(&index_uid);
@ -80,7 +79,7 @@ pub async fn list_indexes(data: web::Data<Data>) -> aweb::Result<web::Json<Vec<I
updated_at,
primary_key,
};
response_body.push(index_response);
response.push(index_response);
}
None => error!(
"Index {} is referenced in the indexes list but cannot be found",
@ -89,14 +88,14 @@ pub async fn list_indexes(data: web::Data<Data>) -> aweb::Result<web::Json<Vec<I
}
}
Ok(web::Json(response_body))
Ok(HttpResponse::Ok().json(response))
}
#[get("/indexes/{index_uid}")]
pub async fn get_index(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> aweb::Result<web::Json<IndexResponse>> {
) -> aweb::Result<HttpResponse> {
let index = data
.db
.open_index(path.index_uid.clone())
@ -137,7 +136,7 @@ pub async fn get_index(
_ => None,
};
Ok(web::Json(IndexResponse {
Ok(HttpResponse::Ok().json(IndexResponse {
name,
uid: path.index_uid.clone(),
created_at,
@ -158,7 +157,7 @@ pub struct IndexCreateRequest {
pub async fn create_index(
data: web::Data<Data>,
body: web::Json<IndexCreateRequest>,
) -> aweb::Result<web::Json<IndexResponse>> {
) -> aweb::Result<HttpResponse> {
if let (None, None) = (body.name.clone(), body.uid.clone()) {
return Err(
ResponseError::BadRequest("Index creation must have an uid".to_string()).into(),
@ -232,7 +231,7 @@ pub async fn create_index(
.commit()
.map_err(|err| ResponseError::Internal(err.to_string()))?;
Ok(web::Json(IndexResponse {
Ok(HttpResponse::Created().json(IndexResponse {
name,
uid,
created_at,
@ -258,12 +257,12 @@ pub struct UpdateIndexResponse {
primary_key: Option<String>,
}
#[post("/indexes/{index_uid}")]
#[put("/indexes/{index_uid}")]
pub async fn update_index(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<IndexCreateRequest>,
) -> aweb::Result<web::Json<IndexResponse>> {
) -> aweb::Result<HttpResponse> {
let index = data
.db
.open_index(path.index_uid.clone())
@ -350,7 +349,7 @@ pub async fn update_index(
_ => None,
};
Ok(web::Json(IndexResponse {
Ok(HttpResponse::Ok().json(IndexResponse {
name,
uid: path.index_uid.clone(),
created_at,
@ -381,7 +380,7 @@ pub struct UpdateParam {
pub async fn get_update_status(
data: web::Data<Data>,
path: web::Path<UpdateParam>,
) -> aweb::Result<web::Json<UpdateStatus>> {
) -> aweb::Result<HttpResponse> {
let index = data
.db
.open_index(path.index_uid.clone())
@ -397,7 +396,7 @@ pub async fn get_update_status(
.map_err(|e| ResponseError::Internal(e.to_string()))?;
match status {
Some(status) => Ok(web::Json(status)),
Some(status) => Ok(HttpResponse::Ok().json(status)),
None => Err(ResponseError::NotFound(format!("Update {} not found", path.update_id)).into()),
}
}
@ -406,7 +405,7 @@ pub async fn get_update_status(
pub async fn get_all_updates_status(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> aweb::Result<web::Json<Vec<UpdateStatus>>> {
) -> aweb::Result<HttpResponse> {
let index = data
.db
.open_index(path.index_uid.clone())
@ -421,5 +420,5 @@ pub async fn get_all_updates_status(
.all_updates_status(&reader)
.map_err(|err| ResponseError::Internal(err.to_string()))?;
Ok(web::Json(response))
Ok(HttpResponse::Ok().json(response))
}

View File

@ -11,6 +11,35 @@ use crate::Data;
pub async fn update_all(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<Settings>,
) -> aweb::Result<HttpResponse> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
let mut writer = data
.db
.update_write_txn()
.map_err(|err| ResponseError::Internal(err.to_string()))?;
let settings = body
.into_inner()
.into_update()
.map_err(|e| ResponseError::BadRequest(e.to_string()))?;
let update_id = index
.settings_update(&mut writer, settings)
.map_err(|err| ResponseError::Internal(err.to_string()))?;
writer
.commit()
.map_err(|err| ResponseError::Internal(err.to_string()))?;
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
}
#[get("/indexes/{index_uid}/settings")]
pub async fn get_all(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> aweb::Result<HttpResponse> {
let index = data
.db
@ -106,35 +135,6 @@ pub async fn update_all(
Ok(HttpResponse::Ok().json(settings))
}
#[get("/indexes/{index_uid}/settings")]
pub async fn get_all(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<Settings>,
) -> aweb::Result<HttpResponse> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::IndexNotFound(path.index_uid.clone()))?;
let mut writer = data
.db
.update_write_txn()
.map_err(|err| ResponseError::Internal(err.to_string()))?;
let settings = body
.into_inner()
.into_update()
.map_err(|e| ResponseError::BadRequest(e.to_string()))?;
let update_id = index
.settings_update(&mut writer, settings)
.map_err(|err| ResponseError::Internal(err.to_string()))?;
writer
.commit()
.map_err(|err| ResponseError::Internal(err.to_string()))?;
Ok(HttpResponse::Accepted().json(IndexUpdateResponse::with_id(update_id)))
}
#[delete("/indexes/{index_uid}/settings")]
pub async fn delete_all(
data: web::Data<Data>,

View File

@ -1,23 +1,17 @@
#![allow(dead_code)]
use http::StatusCode;
use serde_json::Value;
use serde_json::{json, Value};
use std::time::Duration;
use async_std::io::prelude::*;
use async_std::task::{block_on, sleep};
use http_service::Body;
use http_service_mock::{make_server, TestBackend};
use actix_web::{http::StatusCode, test};
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 tokio::time::delay_for;
pub struct Server {
uid: String,
mock: TestBackend<Service<Data>>,
data: Data,
}
impl Server {
@ -33,20 +27,16 @@ impl Server {
};
let data = Data::new(opt.clone());
let mut app = tide::with_state(data);
routes::load_routes(&mut app);
let http_server = app.into_http_service();
let mock = make_server(http_server).unwrap();
Server {
uid: uid.to_string(),
mock,
data: data,
}
}
pub fn wait_update_id(&mut self, update_id: u64) {
pub async fn wait_update_id(&mut self, update_id: u64) {
loop {
let (response, status_code) = self.get_update_status(update_id);
let (response, status_code) = self.get_update_status(update_id).await;
assert_eq!(status_code, 200);
if response["status"] == "processed" || response["status"] == "error" {
@ -54,350 +44,365 @@ impl Server {
return;
}
block_on(sleep(Duration::from_secs(1)));
delay_for(Duration::from_secs(1)).await;
}
}
// Global Http request GET/POST/DELETE async or sync
pub fn get_request(&mut self, url: &str) -> (Value, StatusCode) {
pub async fn get_request(&mut self, url: &str) -> (Value, StatusCode) {
eprintln!("get_request: {}", url);
let req = http::Request::get(url).body(Body::empty()).unwrap();
let res = self.mock.simulate(req).unwrap();
let mut app = test::init_service(meilisearch_http::create_app(&self.data)).await;
let req = test::TestRequest::get().uri(url).to_request();
let res = test::call_service(&mut app, req).await;
let status_code = res.status().clone();
let mut buf = Vec::new();
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let response = serde_json::from_slice(&buf).unwrap_or_default();
let body = test::read_body(res).await;
let response = serde_json::from_slice(&body).unwrap_or_default();
(response, status_code)
}
pub fn post_request(&mut self, url: &str, body: Value) -> (Value, StatusCode) {
pub async fn post_request(&mut self, url: &str, body: Value) -> (Value, StatusCode) {
eprintln!("post_request: {}", url);
let body_bytes = body.to_string().into_bytes();
let req = http::Request::post(url)
.body(Body::from(body_bytes))
.unwrap();
let res = self.mock.simulate(req).unwrap();
let mut app = test::init_service(meilisearch_http::create_app(&self.data)).await;
let req = test::TestRequest::post()
.uri(url)
.set_json(&body)
.to_request();
let res = test::call_service(&mut app, req).await;
let status_code = res.status().clone();
let mut buf = Vec::new();
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let response = serde_json::from_slice(&buf).unwrap_or_default();
let body = test::read_body(res).await;
let response = serde_json::from_slice(&body).unwrap_or_default();
(response, status_code)
}
pub fn post_request_async(&mut self, url: &str, body: Value) -> (Value, StatusCode) {
pub async fn post_request_async(&mut self, url: &str, body: Value) -> (Value, StatusCode) {
eprintln!("post_request_async: {}", url);
let (response, status_code) = self.post_request(url, body);
let (response, status_code) = self.post_request(url, body).await;
assert_eq!(status_code, 202);
assert!(response["updateId"].as_u64().is_some());
self.wait_update_id(response["updateId"].as_u64().unwrap());
self.wait_update_id(response["updateId"].as_u64().unwrap())
.await;
(response, status_code)
}
pub fn put_request(&mut self, url: &str, body: Value) -> (Value, StatusCode) {
pub async fn put_request(&mut self, url: &str, body: Value) -> (Value, StatusCode) {
eprintln!("put_request: {}", url);
let body_bytes = body.to_string().into_bytes();
let req = http::Request::put(url)
.body(Body::from(body_bytes))
.unwrap();
let res = self.mock.simulate(req).unwrap();
let mut app = test::init_service(meilisearch_http::create_app(&self.data)).await;
let req = test::TestRequest::put()
.uri(url)
.set_json(&body)
.to_request();
let res = test::call_service(&mut app, req).await;
let status_code = res.status().clone();
let mut buf = Vec::new();
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let response = serde_json::from_slice(&buf).unwrap_or_default();
let body = test::read_body(res).await;
let response = serde_json::from_slice(&body).unwrap_or_default();
(response, status_code)
}
pub fn put_request_async(&mut self, url: &str, body: Value) -> (Value, StatusCode) {
pub async fn put_request_async(&mut self, url: &str, body: Value) -> (Value, StatusCode) {
eprintln!("put_request_async: {}", url);
let (response, status_code) = self.put_request(url, body);
let (response, status_code) = self.put_request(url, body).await;
assert!(response["updateId"].as_u64().is_some());
assert_eq!(status_code, 202);
self.wait_update_id(response["updateId"].as_u64().unwrap());
self.wait_update_id(response["updateId"].as_u64().unwrap())
.await;
(response, status_code)
}
pub fn delete_request(&mut self, url: &str) -> (Value, StatusCode) {
pub async fn delete_request(&mut self, url: &str) -> (Value, StatusCode) {
eprintln!("delete_request: {}", url);
let req = http::Request::delete(url).body(Body::empty()).unwrap();
let res = self.mock.simulate(req).unwrap();
let mut app = test::init_service(meilisearch_http::create_app(&self.data)).await;
let req = test::TestRequest::delete().uri(url).to_request();
let res = test::call_service(&mut app, req).await;
let status_code = res.status().clone();
let mut buf = Vec::new();
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let response = serde_json::from_slice(&buf).unwrap_or_default();
let body = test::read_body(res).await;
let response = serde_json::from_slice(&body).unwrap_or_default();
(response, status_code)
}
pub fn delete_request_async(&mut self, url: &str) -> (Value, StatusCode) {
pub async fn delete_request_async(&mut self, url: &str) -> (Value, StatusCode) {
eprintln!("delete_request_async: {}", url);
let (response, status_code) = self.delete_request(url);
let (response, status_code) = self.delete_request(url).await;
assert!(response["updateId"].as_u64().is_some());
assert_eq!(status_code, 202);
self.wait_update_id(response["updateId"].as_u64().unwrap());
self.wait_update_id(response["updateId"].as_u64().unwrap())
.await;
(response, status_code)
}
// All Routes
pub fn list_indexes(&mut self) -> (Value, StatusCode) {
self.get_request("/indexes")
pub async fn list_indexes(&mut self) -> (Value, StatusCode) {
self.get_request("/indexes").await
}
pub fn create_index(&mut self, body: Value) -> (Value, StatusCode) {
self.post_request("/indexes", body)
pub async fn create_index(&mut self, body: Value) -> (Value, StatusCode) {
self.post_request("/indexes", body).await
}
pub fn search_multi_index(&mut self, query: &str) -> (Value, StatusCode) {
pub async fn search_multi_index(&mut self, query: &str) -> (Value, StatusCode) {
let url = format!("/indexes/search?{}", query);
self.get_request(&url)
self.get_request(&url).await
}
pub fn get_index(&mut self) -> (Value, StatusCode) {
pub async fn get_index(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn update_index(&mut self, body: Value) -> (Value, StatusCode) {
pub async fn update_index(&mut self, body: Value) -> (Value, StatusCode) {
let url = format!("/indexes/{}", self.uid);
self.put_request(&url, body)
self.put_request(&url, body).await
}
pub fn delete_index(&mut self) -> (Value, StatusCode) {
pub async fn delete_index(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}", self.uid);
self.delete_request(&url)
self.delete_request(&url).await
}
pub fn search(&mut self, query: &str) -> (Value, StatusCode) {
pub async fn search(&mut self, query: &str) -> (Value, StatusCode) {
let url = format!("/indexes/{}/search?{}", self.uid, query);
self.get_request(&url)
self.get_request(&url).await
}
pub fn get_all_updates_status(&mut self) -> (Value, StatusCode) {
pub async fn get_all_updates_status(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/updates", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn get_update_status(&mut self, update_id: u64) -> (Value, StatusCode) {
pub async fn get_update_status(&mut self, update_id: u64) -> (Value, StatusCode) {
let url = format!("/indexes/{}/updates/{}", self.uid, update_id);
self.get_request(&url)
self.get_request(&url).await
}
pub fn get_all_documents(&mut self) -> (Value, StatusCode) {
pub async fn get_all_documents(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/documents", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn add_or_replace_multiple_documents(&mut self, body: Value) {
pub async fn add_or_replace_multiple_documents(&mut self, body: Value) {
let url = format!("/indexes/{}/documents", self.uid);
self.post_request_async(&url, body);
self.post_request_async(&url, body).await;
}
pub fn add_or_replace_multiple_documents_sync(&mut self, body: Value) -> (Value, StatusCode) {
pub async fn add_or_replace_multiple_documents_sync(
&mut self,
body: Value,
) -> (Value, StatusCode) {
let url = format!("/indexes/{}/documents", self.uid);
self.post_request(&url, body)
self.post_request(&url, body).await
}
pub fn add_or_update_multiple_documents(&mut self, body: Value) {
pub async fn add_or_update_multiple_documents(&mut self, body: Value) {
let url = format!("/indexes/{}/documents", self.uid);
self.put_request_async(&url, body);
self.put_request_async(&url, body).await;
}
pub fn clear_all_documents(&mut self) {
pub async fn clear_all_documents(&mut self) {
let url = format!("/indexes/{}/documents", self.uid);
self.delete_request_async(&url);
self.delete_request_async(&url).await;
}
pub fn get_document(&mut self, document_id: impl ToString) -> (Value, StatusCode) {
pub async fn get_document(&mut self, document_id: impl ToString) -> (Value, StatusCode) {
let url = format!(
"/indexes/{}/documents/{}",
self.uid,
document_id.to_string()
);
self.get_request(&url)
self.get_request(&url).await
}
pub fn delete_document(&mut self, document_id: impl ToString) -> (Value, StatusCode) {
pub async fn delete_document(&mut self, document_id: impl ToString) -> (Value, StatusCode) {
let url = format!(
"/indexes/{}/documents/{}",
self.uid,
document_id.to_string()
);
self.delete_request_async(&url)
self.delete_request_async(&url).await
}
pub fn delete_multiple_documents(&mut self, body: Value) {
pub async fn delete_multiple_documents(&mut self, body: Value) {
let url = format!("/indexes/{}/documents/delete-batch", self.uid);
self.post_request_async(&url, body);
self.post_request_async(&url, body).await;
}
pub fn get_all_settings(&mut self) -> (Value, StatusCode) {
pub async fn get_all_settings(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn update_all_settings(&mut self, body: Value) {
pub async fn update_all_settings(&mut self, body: Value) {
let url = format!("/indexes/{}/settings", self.uid);
self.post_request_async(&url, body);
self.post_request_async(&url, body).await;
}
pub fn delete_all_settings(&mut self) -> (Value, StatusCode) {
pub async fn delete_all_settings(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings", self.uid);
self.delete_request_async(&url)
self.delete_request_async(&url).await
}
pub fn get_ranking_rules(&mut self) -> (Value, StatusCode) {
pub async fn get_ranking_rules(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/ranking-rules", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn update_ranking_rules(&mut self, body: Value) {
pub async fn update_ranking_rules(&mut self, body: Value) {
let url = format!("/indexes/{}/settings/ranking-rules", self.uid);
self.post_request_async(&url, body);
self.post_request_async(&url, body).await;
}
pub fn update_ranking_rules_sync(&mut self, body: Value) -> (Value, StatusCode) {
pub async fn update_ranking_rules_sync(&mut self, body: Value) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/ranking-rules", self.uid);
self.post_request(&url, body)
self.post_request(&url, body).await
}
pub fn delete_ranking_rules(&mut self) -> (Value, StatusCode) {
pub async fn delete_ranking_rules(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/ranking-rules", self.uid);
self.delete_request_async(&url)
self.delete_request_async(&url).await
}
pub fn get_distinct_attribute(&mut self) -> (Value, StatusCode) {
pub async fn get_distinct_attribute(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/distinct-attribute", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn update_distinct_attribute(&mut self, body: Value) {
pub async fn update_distinct_attribute(&mut self, body: Value) {
let url = format!("/indexes/{}/settings/distinct-attribute", self.uid);
self.post_request_async(&url, body);
self.post_request_async(&url, body).await;
}
pub fn delete_distinct_attribute(&mut self) -> (Value, StatusCode) {
pub async fn delete_distinct_attribute(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/distinct-attribute", self.uid);
self.delete_request_async(&url)
self.delete_request_async(&url).await
}
pub fn get_primary_key(&mut self) -> (Value, StatusCode) {
pub async fn get_primary_key(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/primary_key", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn get_searchable_attributes(&mut self) -> (Value, StatusCode) {
pub async fn get_searchable_attributes(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/searchable-attributes", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn update_searchable_attributes(&mut self, body: Value) {
pub async fn update_searchable_attributes(&mut self, body: Value) {
let url = format!("/indexes/{}/settings/searchable-attributes", self.uid);
self.post_request_async(&url, body);
self.post_request_async(&url, body).await;
}
pub fn delete_searchable_attributes(&mut self) -> (Value, StatusCode) {
pub async fn delete_searchable_attributes(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/searchable-attributes", self.uid);
self.delete_request_async(&url)
self.delete_request_async(&url).await
}
pub fn get_displayed_attributes(&mut self) -> (Value, StatusCode) {
pub async fn get_displayed_attributes(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/displayed-attributes", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn update_displayed_attributes(&mut self, body: Value) {
pub async fn update_displayed_attributes(&mut self, body: Value) {
let url = format!("/indexes/{}/settings/displayed-attributes", self.uid);
self.post_request_async(&url, body);
self.post_request_async(&url, body).await;
}
pub fn delete_displayed_attributes(&mut self) -> (Value, StatusCode) {
pub async fn delete_displayed_attributes(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/displayed-attributes", self.uid);
self.delete_request_async(&url)
self.delete_request_async(&url).await
}
pub fn get_accept_new_fields(&mut self) -> (Value, StatusCode) {
pub async fn get_accept_new_fields(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/accept-new-fields", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn update_accept_new_fields(&mut self, body: Value) {
pub async fn update_accept_new_fields(&mut self, body: Value) {
let url = format!("/indexes/{}/settings/accept-new-fields", self.uid);
self.post_request_async(&url, body);
self.post_request_async(&url, body).await;
}
pub fn get_synonyms(&mut self) -> (Value, StatusCode) {
pub async fn get_synonyms(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/synonyms", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn update_synonyms(&mut self, body: Value) {
pub async fn update_synonyms(&mut self, body: Value) {
let url = format!("/indexes/{}/settings/synonyms", self.uid);
self.post_request_async(&url, body);
self.post_request_async(&url, body).await;
}
pub fn delete_synonyms(&mut self) -> (Value, StatusCode) {
pub async fn delete_synonyms(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/synonyms", self.uid);
self.delete_request_async(&url)
self.delete_request_async(&url).await
}
pub fn get_stop_words(&mut self) -> (Value, StatusCode) {
pub async fn get_stop_words(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/stop-words", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn update_stop_words(&mut self, body: Value) {
pub async fn update_stop_words(&mut self, body: Value) {
let url = format!("/indexes/{}/settings/stop-words", self.uid);
self.post_request_async(&url, body);
self.post_request_async(&url, body).await;
}
pub fn delete_stop_words(&mut self) -> (Value, StatusCode) {
pub async fn delete_stop_words(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/settings/stop-words", self.uid);
self.delete_request_async(&url)
self.delete_request_async(&url).await
}
pub fn get_index_stats(&mut self) -> (Value, StatusCode) {
pub async fn get_index_stats(&mut self) -> (Value, StatusCode) {
let url = format!("/indexes/{}/stats", self.uid);
self.get_request(&url)
self.get_request(&url).await
}
pub fn list_keys(&mut self) -> (Value, StatusCode) {
self.get_request("/keys")
pub async fn list_keys(&mut self) -> (Value, StatusCode) {
self.get_request("/keys").await
}
pub fn get_health(&mut self) -> (Value, StatusCode) {
self.get_request("/health")
pub async fn get_health(&mut self) -> (Value, StatusCode) {
self.get_request("/health").await
}
pub fn update_health(&mut self, body: Value) -> (Value, StatusCode) {
self.put_request("/health", body)
pub async fn update_health(&mut self, body: Value) -> (Value, StatusCode) {
self.put_request("/health", body).await
}
pub fn get_version(&mut self) -> (Value, StatusCode) {
self.get_request("/version")
pub async fn get_version(&mut self) -> (Value, StatusCode) {
self.get_request("/version").await
}
pub fn get_sys_info(&mut self) -> (Value, StatusCode) {
self.get_request("/sys-info")
pub async fn get_sys_info(&mut self) -> (Value, StatusCode) {
self.get_request("/sys-info").await
}
pub fn get_sys_info_pretty(&mut self) -> (Value, StatusCode) {
self.get_request("/sys-info/pretty")
pub async fn get_sys_info_pretty(&mut self) -> (Value, StatusCode) {
self.get_request("/sys-info/pretty").await
}
// Populate routes
pub fn populate_movies(&mut self) {
pub async fn populate_movies(&mut self) {
let body = json!({
"uid": "movies",
"primaryKey": "id",
});
self.create_index(body);
self.create_index(body).await;
let body = json!({
"rankingRules": [
@ -436,12 +441,12 @@ impl Server {
"acceptNewFields": false,
});
self.update_all_settings(body);
self.update_all_settings(body).await;
let dataset = include_bytes!("assets/movies.json");
let body: Value = serde_json::from_slice(dataset).unwrap();
self.add_or_replace_multiple_documents(body);
self.add_or_replace_multiple_documents(body).await;
}
}

View File

@ -3,8 +3,8 @@ use serde_json::json;
mod common;
// Test issue https://github.com/meilisearch/MeiliSearch/issues/519
#[test]
fn check_add_documents_with_primary_key_param() {
#[actix_rt::test]
async fn check_add_documents_with_primary_key_param() {
let mut server = common::Server::with_uid("movies");
// 1 - Create the index with no primary_key
@ -12,7 +12,7 @@ fn check_add_documents_with_primary_key_param() {
let body = json!({
"uid": "movies",
});
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
@ -24,28 +24,28 @@ fn check_add_documents_with_primary_key_param() {
}]);
let url = "/indexes/movies/documents?primaryKey=title";
let (response, status_code) = server.post_request(&url, body);
let (response, status_code) = server.post_request(&url, body).await;
eprintln!("{:#?}", response);
assert_eq!(status_code, 202);
let update_id = response["updateId"].as_u64().unwrap();
server.wait_update_id(update_id);
server.wait_update_id(update_id).await;
// 3 - Check update success
let (response, status_code) = server.get_update_status(update_id);
let (response, status_code) = server.get_update_status(update_id).await;
assert_eq!(status_code, 200);
assert_eq!(response["status"], "processed");
}
// Test issue https://github.com/meilisearch/MeiliSearch/issues/568
#[test]
fn check_add_documents_with_nested_boolean() {
#[actix_rt::test]
async fn check_add_documents_with_nested_boolean() {
let mut server = common::Server::with_uid("tasks");
// 1 - Create the index with no primary_key
let body = json!({ "uid": "tasks" });
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
@ -64,28 +64,28 @@ fn check_add_documents_with_nested_boolean() {
}]);
let url = "/indexes/tasks/documents";
let (response, status_code) = server.post_request(&url, body);
let (response, status_code) = server.post_request(&url, body).await;
eprintln!("{:#?}", response);
assert_eq!(status_code, 202);
let update_id = response["updateId"].as_u64().unwrap();
server.wait_update_id(update_id);
server.wait_update_id(update_id).await;
// 3 - Check update success
let (response, status_code) = server.get_update_status(update_id);
let (response, status_code) = server.get_update_status(update_id).await;
assert_eq!(status_code, 200);
assert_eq!(response["status"], "processed");
}
// Test issue https://github.com/meilisearch/MeiliSearch/issues/571
#[test]
fn check_add_documents_with_nested_null() {
#[actix_rt::test]
async fn check_add_documents_with_nested_null() {
let mut server = common::Server::with_uid("tasks");
// 1 - Create the index with no primary_key
let body = json!({ "uid": "tasks" });
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
@ -99,28 +99,28 @@ fn check_add_documents_with_nested_null() {
}]);
let url = "/indexes/tasks/documents";
let (response, status_code) = server.post_request(&url, body);
let (response, status_code) = server.post_request(&url, body).await;
eprintln!("{:#?}", response);
assert_eq!(status_code, 202);
let update_id = response["updateId"].as_u64().unwrap();
server.wait_update_id(update_id);
server.wait_update_id(update_id).await;
// 3 - Check update success
let (response, status_code) = server.get_update_status(update_id);
let (response, status_code) = server.get_update_status(update_id).await;
assert_eq!(status_code, 200);
assert_eq!(response["status"], "processed");
}
// Test issue https://github.com/meilisearch/MeiliSearch/issues/574
#[test]
fn check_add_documents_with_nested_sequence() {
#[actix_rt::test]
async fn check_add_documents_with_nested_sequence() {
let mut server = common::Server::with_uid("tasks");
// 1 - Create the index with no primary_key
let body = json!({ "uid": "tasks" });
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
@ -158,20 +158,20 @@ fn check_add_documents_with_nested_sequence() {
}]);
let url = "/indexes/tasks/documents";
let (response, status_code) = server.post_request(&url, body.clone());
let (response, status_code) = server.post_request(&url, body.clone()).await;
eprintln!("{:#?}", response);
assert_eq!(status_code, 202);
let update_id = response["updateId"].as_u64().unwrap();
server.wait_update_id(update_id);
server.wait_update_id(update_id).await;
// 3 - Check update success
let (response, status_code) = server.get_update_status(update_id);
let (response, status_code) = server.get_update_status(update_id).await;
assert_eq!(status_code, 200);
assert_eq!(response["status"], "processed");
let url = "/indexes/tasks/search?q=leesz";
let (response, status_code) = server.get_request(&url);
let (response, status_code) = server.get_request(&url).await;
assert_eq!(status_code, 200);
assert_eq!(response["hits"], body);
}

View File

@ -1,31 +1,31 @@
mod common;
#[test]
fn delete() {
#[actix_rt::test]
async fn delete() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
let (_response, status_code) = server.get_document(419704);
let (_response, status_code) = server.get_document(419704).await;
assert_eq!(status_code, 200);
server.delete_document(419704);
server.delete_document(419704).await;
let (_response, status_code) = server.get_document(419704);
let (_response, status_code) = server.get_document(419704).await;
assert_eq!(status_code, 404);
}
// Resolve teh issue https://github.com/meilisearch/MeiliSearch/issues/493
#[test]
fn delete_batch() {
#[actix_rt::test]
async fn delete_batch() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
let (_response, status_code) = server.get_document(419704);
let (_response, status_code) = server.get_document(419704).await;
assert_eq!(status_code, 200);
let body = serde_json::json!([419704, 512200, 181812]);
server.delete_multiple_documents(body);
server.delete_multiple_documents(body).await;
let (_response, status_code) = server.get_document(419704);
let (_response, status_code) = server.get_document(419704).await;
assert_eq!(status_code, 404);
}

View File

@ -3,36 +3,36 @@ use std::convert::Into;
mod common;
#[test]
fn test_healthyness() {
#[actix_rt::test]
async fn test_healthyness() {
let mut server = common::Server::with_uid("movies");
// Check that the server is healthy
let (_response, status_code) = server.get_health();
let (_response, status_code) = server.get_health().await;
assert_eq!(status_code, 200);
// Set the serve Unhealthy
let body = json!({
"health": false,
});
let (_response, status_code) = server.update_health(body);
let (_response, status_code) = server.update_health(body).await;
assert_eq!(status_code, 200);
// Check that the server is unhealthy
let (_response, status_code) = server.get_health();
let (_response, status_code) = server.get_health().await;
assert_eq!(status_code, 503);
// Set the server healthy
let body = json!({
"health": true,
});
let (_response, status_code) = server.update_health(body);
let (_response, status_code) = server.update_health(body).await;
assert_eq!(status_code, 200);
// Check if the server is healthy
let (_response, status_code) = server.get_health();
let (_response, status_code) = server.get_health().await;
assert_eq!(status_code, 200);
}

View File

@ -4,8 +4,8 @@ use serde_json::Value;
mod common;
#[test]
fn create_index_with_name() {
#[actix_rt::test]
async fn create_index_with_name() {
let mut server = common::Server::with_uid("movies");
// 1 - Create a new index
@ -14,7 +14,7 @@ fn create_index_with_name() {
"name": "movies",
});
let (res1_value, status_code) = server.create_index(body);
let (res1_value, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(res1_value.as_object().unwrap().len(), 5);
@ -29,7 +29,7 @@ fn create_index_with_name() {
// 2 - Check the list of indexes
let (res2_value, status_code) = server.list_indexes();
let (res2_value, status_code) = server.list_indexes().await;
assert_eq!(status_code, 200);
assert_eq!(res2_value.as_array().unwrap().len(), 1);
@ -44,8 +44,8 @@ fn create_index_with_name() {
assert_eq!(r2_updated_at.len(), r1_updated_at.len());
}
#[test]
fn create_index_with_uid() {
#[actix_rt::test]
async fn create_index_with_uid() {
let mut server = common::Server::with_uid("movies");
// 1 - Create a new index
@ -54,7 +54,7 @@ fn create_index_with_uid() {
"uid": "movies",
});
let (res1_value, status_code) = server.create_index(body);
let (res1_value, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(res1_value.as_object().unwrap().len(), 5);
@ -69,7 +69,7 @@ fn create_index_with_uid() {
// 2 - Check the list of indexes
let (res2_value, status_code) = server.list_indexes();
let (res2_value, status_code) = server.list_indexes().await;
assert_eq!(status_code, 200);
assert_eq!(res2_value.as_array().unwrap().len(), 1);
@ -84,8 +84,8 @@ fn create_index_with_uid() {
assert_eq!(r2_updated_at.len(), r1_updated_at.len());
}
#[test]
fn create_index_with_name_and_uid() {
#[actix_rt::test]
async fn create_index_with_name_and_uid() {
let mut server = common::Server::with_uid("movies");
// 1 - Create a new index
@ -94,7 +94,7 @@ fn create_index_with_name_and_uid() {
"name": "Films",
"uid": "fr_movies",
});
let (res1_value, status_code) = server.create_index(body);
let (res1_value, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(res1_value.as_object().unwrap().len(), 5);
@ -109,7 +109,7 @@ fn create_index_with_name_and_uid() {
// 2 - Check the list of indexes
let (res2_value, status_code) = server.list_indexes();
let (res2_value, status_code) = server.list_indexes().await;
assert_eq!(status_code, 200);
assert_eq!(res2_value.as_array().unwrap().len(), 1);
@ -124,8 +124,8 @@ fn create_index_with_name_and_uid() {
assert_eq!(r2_updated_at.len(), r1_updated_at.len());
}
#[test]
fn rename_index() {
#[actix_rt::test]
async fn rename_index() {
let mut server = common::Server::with_uid("movies");
// 1 - Create a new index
@ -135,7 +135,7 @@ fn rename_index() {
"uid": "movies",
});
let (res1_value, status_code) = server.create_index(body);
let (res1_value, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(res1_value.as_object().unwrap().len(), 5);
@ -154,7 +154,7 @@ fn rename_index() {
"name": "TV Shows",
});
let (res2_value, status_code) = server.update_index(body);
let (res2_value, status_code) = server.update_index(body).await;
assert_eq!(status_code, 200);
assert_eq!(res2_value.as_object().unwrap().len(), 5);
@ -169,7 +169,7 @@ fn rename_index() {
// 3 - Check the list of indexes
let (res3_value, status_code) = server.list_indexes();
let (res3_value, status_code) = server.list_indexes().await;
assert_eq!(status_code, 200);
assert_eq!(res3_value.as_array().unwrap().len(), 1);
@ -184,8 +184,8 @@ fn rename_index() {
assert_eq!(r3_updated_at.len(), r2_updated_at.len());
}
#[test]
fn delete_index_and_recreate_it() {
#[actix_rt::test]
async fn delete_index_and_recreate_it() {
let mut server = common::Server::with_uid("movies");
// 1 - Create a new index
@ -195,7 +195,7 @@ fn delete_index_and_recreate_it() {
"uid": "movies",
});
let (res1_value, status_code) = server.create_index(body);
let (res1_value, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(res1_value.as_object().unwrap().len(), 5);
@ -210,7 +210,7 @@ fn delete_index_and_recreate_it() {
// 2 - Check the list of indexes
let (res2_value, status_code) = server.list_indexes();
let (res2_value, status_code) = server.list_indexes().await;
assert_eq!(status_code, 200);
assert_eq!(res2_value.as_array().unwrap().len(), 1);
@ -226,13 +226,13 @@ fn delete_index_and_recreate_it() {
// 3- Delete an index
let (_res2_value, status_code) = server.delete_index();
let (_res2_value, status_code) = server.delete_index().await;
assert_eq!(status_code, 204);
// 4 - Check the list of indexes
let (res2_value, status_code) = server.list_indexes();
let (res2_value, status_code) = server.list_indexes().await;
assert_eq!(status_code, 200);
assert_eq!(res2_value.as_array().unwrap().len(), 0);
@ -243,7 +243,7 @@ fn delete_index_and_recreate_it() {
"name": "movies",
});
let (res1_value, status_code) = server.create_index(body);
let (res1_value, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(res1_value.as_object().unwrap().len(), 5);
@ -258,7 +258,7 @@ fn delete_index_and_recreate_it() {
// 6 - Check the list of indexes
let (res2_value, status_code) = server.list_indexes();
let (res2_value, status_code) = server.list_indexes().await;
assert_eq!(status_code, 200);
assert_eq!(res2_value.as_array().unwrap().len(), 1);
assert_eq!(res2_value[0].as_object().unwrap().len(), 5);
@ -272,8 +272,8 @@ fn delete_index_and_recreate_it() {
assert_eq!(r2_updated_at.len(), r1_updated_at.len());
}
#[test]
fn check_multiples_indexes() {
#[actix_rt::test]
async fn check_multiples_indexes() {
let mut server = common::Server::with_uid("movies");
// 1 - Create a new index
@ -282,7 +282,7 @@ fn check_multiples_indexes() {
"name": "movies",
});
let (res1_value, status_code) = server.create_index(body);
let (res1_value, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(res1_value.as_object().unwrap().len(), 5);
@ -297,7 +297,7 @@ fn check_multiples_indexes() {
// 2 - Check the list of indexes
let (res2_value, status_code) = server.list_indexes();
let (res2_value, status_code) = server.list_indexes().await;
assert_eq!(status_code, 200);
assert_eq!(res2_value.as_array().unwrap().len(), 1);
@ -317,7 +317,7 @@ fn check_multiples_indexes() {
"name": "films",
});
let (res3_value, status_code) = server.create_index(body);
let (res3_value, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(res3_value.as_object().unwrap().len(), 5);
@ -332,7 +332,7 @@ fn check_multiples_indexes() {
// 4 - Check the list of indexes
let (res4_value, status_code) = server.list_indexes();
let (res4_value, status_code) = server.list_indexes().await;
assert_eq!(status_code, 200);
assert_eq!(res4_value.as_array().unwrap().len(), 2);
@ -370,15 +370,15 @@ fn check_multiples_indexes() {
}
}
#[test]
fn create_index_failed() {
#[actix_rt::test]
async fn create_index_failed() {
let mut server = common::Server::with_uid("movies");
// 2 - Push index creation with empty json body
let body = json!({});
let (res_value, status_code) = server.create_index(body);
let (res_value, status_code) = server.create_index(body).await;
assert_eq!(status_code, 400);
let message = res_value["message"].as_str().unwrap();
@ -392,12 +392,9 @@ fn create_index_failed() {
"active": true
});
let (res_value, status_code) = server.create_index(body);
let (_res_value, status_code) = server.create_index(body).await;
assert_eq!(status_code, 400);
let message = res_value["message"].as_str().unwrap();
assert_eq!(res_value.as_object().unwrap().len(), 1);
assert_eq!(message, "invalid data");
// 3 - Create a index with wrong data type
@ -406,17 +403,14 @@ fn create_index_failed() {
"uid": 0
});
let (res_value, status_code) = server.create_index(body);
let (_res_value, status_code) = server.create_index(body).await;
assert_eq!(status_code, 400);
let message = res_value["message"].as_str().unwrap();
assert_eq!(res_value.as_object().unwrap().len(), 1);
assert_eq!(message, "invalid data");
}
// Resolve issue https://github.com/meilisearch/MeiliSearch/issues/492
#[test]
fn create_index_with_primary_key_and_index() {
#[actix_rt::test]
async fn create_index_with_primary_key_and_index() {
let mut server = common::Server::with_uid("movies");
// 1 - Create the index
@ -426,7 +420,7 @@ fn create_index_with_primary_key_and_index() {
"primaryKey": "id",
});
let (_response, status_code) = server.create_index(body);
let (_response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
// 2 - Add content
@ -436,11 +430,11 @@ fn create_index_with_primary_key_and_index() {
"text": "The mask"
}]);
server.add_or_replace_multiple_documents(body.clone());
server.add_or_replace_multiple_documents(body.clone()).await;
// 3 - Retreive document
let (response, _status_code) = server.get_document(123);
let (response, _status_code) = server.get_document(123).await;
let expect = json!({
"id": 123,
@ -454,8 +448,8 @@ fn create_index_with_primary_key_and_index() {
// Test when the given index uid is not valid
// Should have a 400 status code
// Should have the right error message
#[test]
fn create_index_with_invalid_uid() {
#[actix_rt::test]
async fn create_index_with_invalid_uid() {
let mut server = common::Server::with_uid("");
// 1 - Create the index with invalid uid
@ -464,7 +458,7 @@ fn create_index_with_invalid_uid() {
"uid": "the movies"
});
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 400);
let message = response["message"].as_str().unwrap();
@ -477,7 +471,7 @@ fn create_index_with_invalid_uid() {
"uid": "%$#"
});
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 400);
let message = response["message"].as_str().unwrap();
@ -490,7 +484,7 @@ fn create_index_with_invalid_uid() {
"uid": "the~movies"
});
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 400);
let message = response["message"].as_str().unwrap();
@ -503,7 +497,7 @@ fn create_index_with_invalid_uid() {
"uid": "🎉"
});
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 400);
let message = response["message"].as_str().unwrap();
@ -512,8 +506,8 @@ fn create_index_with_invalid_uid() {
}
// Test that it's possible to add primary_key if it's not already set on index creation
#[test]
fn create_index_and_add_indentifier_after() {
#[actix_rt::test]
async fn create_index_and_add_indentifier_after() {
let mut server = common::Server::with_uid("movies");
// 1 - Create the index with no primary_key
@ -521,7 +515,7 @@ fn create_index_and_add_indentifier_after() {
let body = json!({
"uid": "movies",
});
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
@ -531,21 +525,21 @@ fn create_index_and_add_indentifier_after() {
"primaryKey": "id",
});
let (response, status_code) = server.update_index(body);
let (response, status_code) = server.update_index(body).await;
assert_eq!(status_code, 200);
eprintln!("response: {:#?}", response);
assert_eq!(response["primaryKey"].as_str().unwrap(), "id");
// 3 - Get index to verify if the primary_key is good
let (response, status_code) = server.get_index();
let (response, status_code) = server.get_index().await;
assert_eq!(status_code, 200);
assert_eq!(response["primaryKey"].as_str().unwrap(), "id");
}
// Test that it's impossible to change the primary_key
#[test]
fn create_index_and_update_indentifier_after() {
#[actix_rt::test]
async fn create_index_and_update_indentifier_after() {
let mut server = common::Server::with_uid("movies");
// 1 - Create the index with no primary_key
@ -554,7 +548,7 @@ fn create_index_and_update_indentifier_after() {
"uid": "movies",
"primaryKey": "id",
});
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"].as_str().unwrap(), "id");
@ -564,19 +558,19 @@ fn create_index_and_update_indentifier_after() {
"primaryKey": "skuid",
});
let (_response, status_code) = server.update_index(body);
let (_response, status_code) = server.update_index(body).await;
assert_eq!(status_code, 400);
// 3 - Get index to verify if the primary_key still the first one
let (response, status_code) = server.get_index();
let (response, status_code) = server.get_index().await;
assert_eq!(status_code, 200);
assert_eq!(response["primaryKey"].as_str().unwrap(), "id");
}
// Test that schema inference work well
#[test]
fn create_index_without_primary_key_and_add_document() {
#[actix_rt::test]
async fn create_index_without_primary_key_and_add_document() {
let mut server = common::Server::with_uid("movies");
// 1 - Create the index with no primary_key
@ -584,7 +578,7 @@ fn create_index_without_primary_key_and_add_document() {
let body = json!({
"uid": "movies",
});
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
@ -595,18 +589,18 @@ fn create_index_without_primary_key_and_add_document() {
"title": "I'm a legend",
}]);
server.add_or_update_multiple_documents(body);
server.add_or_update_multiple_documents(body).await;
// 3 - Get index to verify if the primary_key is good
let (response, status_code) = server.get_index();
let (response, status_code) = server.get_index().await;
assert_eq!(status_code, 200);
assert_eq!(response["primaryKey"].as_str().unwrap(), "id");
}
// Test search with no primary_key
#[test]
fn create_index_without_primary_key_and_search() {
#[actix_rt::test]
async fn create_index_without_primary_key_and_search() {
let mut server = common::Server::with_uid("movies");
// 1 - Create the index with no primary_key
@ -614,7 +608,7 @@ fn create_index_without_primary_key_and_search() {
let body = json!({
"uid": "movies",
});
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
@ -622,15 +616,15 @@ fn create_index_without_primary_key_and_search() {
let query = "q=captain&limit=3";
let (response, status_code) = server.search(&query);
let (response, status_code) = server.search(&query).await;
assert_eq!(status_code, 200);
assert_eq!(response["hits"].as_array().unwrap().len(), 0);
}
// Test the error message when we push an document update and impossibility to find primary key
// Test issue https://github.com/meilisearch/MeiliSearch/issues/517
#[test]
fn check_add_documents_without_primary_key() {
#[actix_rt::test]
async fn check_add_documents_without_primary_key() {
let mut server = common::Server::with_uid("movies");
// 1 - Create the index with no primary_key
@ -638,7 +632,7 @@ fn check_add_documents_without_primary_key() {
let body = json!({
"uid": "movies",
});
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
@ -649,7 +643,7 @@ fn check_add_documents_without_primary_key() {
"comment": "comment test"
}]);
let (response, status_code) = server.add_or_replace_multiple_documents_sync(body);
let (response, status_code) = server.add_or_replace_multiple_documents_sync(body).await;
let expected = json!({
"message": "Could not infer a primary key"
@ -659,8 +653,8 @@ fn check_add_documents_without_primary_key() {
assert_json_eq!(response, expected, ordered: false);
}
#[test]
fn check_first_update_should_bring_up_processed_status_after_first_docs_addition() {
#[actix_rt::test]
async fn check_first_update_should_bring_up_processed_status_after_first_docs_addition() {
let mut server = common::Server::with_uid("movies");
let body = json!({
@ -668,7 +662,7 @@ fn check_first_update_should_bring_up_processed_status_after_first_docs_addition
});
// 1. Create Index
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
@ -677,10 +671,10 @@ fn check_first_update_should_bring_up_processed_status_after_first_docs_addition
let body: Value = serde_json::from_slice(dataset).unwrap();
// 2. Index the documents from movies.json, present inside of assets directory
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 3. Fetch the status of the indexing done above.
let (response, status_code) = server.get_all_updates_status();
let (response, status_code) = server.get_all_updates_status().await;
// 4. Verify the fetch is successful and indexing status is 'processed'
assert_eq!(status_code, 200);

View File

@ -16,8 +16,8 @@ static GLOBAL_SERVER: Lazy<Mutex<common::Server>> = Lazy::new(|| {
// Search
// q: Captain
// limit: 3
#[test]
fn search_with_limit() {
#[actix_rt::test]
async fn search_with_limit() {
let query = "q=captain&limit=3";
let expected = json!([
@ -74,7 +74,7 @@ fn search_with_limit() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -82,8 +82,8 @@ fn search_with_limit() {
// q: Captain
// limit: 3
// offset: 1
#[test]
fn search_with_offset() {
#[actix_rt::test]
async fn search_with_offset() {
let query = "q=captain&limit=3&offset=1";
let expected = json!([
@ -141,7 +141,7 @@ fn search_with_offset() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -149,8 +149,8 @@ fn search_with_offset() {
// q: Captain
// limit: 1
// attributeToHighlight: *
#[test]
fn search_with_attribute_to_highlight_wildcard() {
#[actix_rt::test]
async fn search_with_attribute_to_highlight_wildcard() {
let query = "q=captain&limit=1&attributesToHighlight=*";
let expected = json!([
@ -190,7 +190,7 @@ fn search_with_attribute_to_highlight_wildcard() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -198,8 +198,8 @@ fn search_with_attribute_to_highlight_wildcard() {
// q: Captain
// limit: 1
// attributeToHighlight: title
#[test]
fn search_with_attribute_to_highlight_1() {
#[actix_rt::test]
async fn search_with_attribute_to_highlight_1() {
let query = "q=captain&limit=1&attributesToHighlight=title";
let expected = json!([
@ -239,7 +239,7 @@ fn search_with_attribute_to_highlight_1() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -247,8 +247,8 @@ fn search_with_attribute_to_highlight_1() {
// q: Captain
// limit: 1
// attributeToHighlight: title,tagline
#[test]
fn search_with_attribute_to_highlight_title_tagline() {
#[actix_rt::test]
async fn search_with_attribute_to_highlight_title_tagline() {
let query = "q=captain&limit=1&attributesToHighlight=title,tagline";
let expected = json!([
@ -288,7 +288,7 @@ fn search_with_attribute_to_highlight_title_tagline() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -296,8 +296,8 @@ fn search_with_attribute_to_highlight_title_tagline() {
// q: Captain
// limit: 1
// attributeToHighlight: title,overview
#[test]
fn search_with_attribute_to_highlight_title_overview() {
#[actix_rt::test]
async fn search_with_attribute_to_highlight_title_overview() {
let query = "q=captain&limit=1&attributesToHighlight=title,overview";
let expected = json!([
@ -337,7 +337,7 @@ fn search_with_attribute_to_highlight_title_overview() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -345,8 +345,8 @@ fn search_with_attribute_to_highlight_title_overview() {
// q: Captain
// limit: 1
// matches: true
#[test]
fn search_with_matches() {
#[actix_rt::test]
async fn search_with_matches() {
let query = "q=captain&limit=1&matches=true";
let expected = json!([
@ -383,7 +383,7 @@ fn search_with_matches() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -392,8 +392,8 @@ fn search_with_matches() {
// limit: 1
// attributesToCrop: overview
// cropLength: 20
#[test]
fn search_witch_crop() {
#[actix_rt::test]
async fn search_witch_crop() {
let query = "q=captain&limit=1&attributesToCrop=overview&cropLength=20";
let expected = json!([
@ -433,7 +433,7 @@ fn search_witch_crop() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -441,8 +441,8 @@ fn search_witch_crop() {
// q: Captain
// limit: 1
// attributesToRetrieve: [title,tagline,overview,poster_path]
#[test]
fn search_with_attributes_to_retrieve() {
#[actix_rt::test]
async fn search_with_attributes_to_retrieve() {
let query = "q=captain&limit=1&attributesToRetrieve=title,tagline,overview,poster_path";
let expected = json!([
@ -454,7 +454,7 @@ fn search_with_attributes_to_retrieve() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -462,8 +462,8 @@ fn search_with_attributes_to_retrieve() {
// q: Captain
// limit: 1
// attributesToRetrieve: *
#[test]
fn search_with_attributes_to_retrieve_wildcard() {
#[actix_rt::test]
async fn search_with_attributes_to_retrieve_wildcard() {
let query = "q=captain&limit=1&attributesToRetrieve=*";
let expected = json!([
@ -486,7 +486,7 @@ fn search_with_attributes_to_retrieve_wildcard() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -494,8 +494,8 @@ fn search_with_attributes_to_retrieve_wildcard() {
// q: Captain
// limit: 3
// filters: director:Anthony%20Russo
#[test]
fn search_with_filter() {
#[actix_rt::test]
async fn search_with_filter() {
let query = "q=captain&filters=director%20%3D%20%22Anthony%20Russo%22&limit=3";
let expected = json!([
{
@ -744,8 +744,8 @@ fn search_with_filter() {
// limit: 1
// attributesToHighlight: [title,overview]
// matches: true
#[test]
fn search_with_attributes_to_highlight_and_matches() {
#[actix_rt::test]
async fn search_with_attributes_to_highlight_and_matches() {
let query = "q=captain&limit=1&attributesToHighlight=title,overview&matches=true";
let expected = json!( [
@ -799,7 +799,7 @@ fn search_with_attributes_to_highlight_and_matches() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -810,8 +810,8 @@ fn search_with_attributes_to_highlight_and_matches() {
// matches: true
// cropLength: 20
// attributesToCrop: overview
#[test]
fn search_with_attributes_to_highlight_and_matches_and_crop() {
#[actix_rt::test]
async fn search_with_attributes_to_highlight_and_matches_and_crop() {
let query = "q=captain&limit=1&attributesToCrop=overview&cropLength=20&attributesToHighlight=title,overview&matches=true";
let expected = json!([
@ -865,7 +865,7 @@ fn search_with_attributes_to_highlight_and_matches_and_crop() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -874,8 +874,8 @@ fn search_with_attributes_to_highlight_and_matches_and_crop() {
// limit: 1
// attributesToRetrieve: [title,producer,director]
// attributesToHighlight: [title]
#[test]
fn search_with_differents_attributes() {
#[actix_rt::test]
async fn search_with_differents_attributes() {
let query = "q=captain&limit=1&attributesToRetrieve=title,producer,director&attributesToHighlight=title";
let expected = json!([
@ -889,7 +889,7 @@ fn search_with_differents_attributes() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -899,8 +899,8 @@ fn search_with_differents_attributes() {
// attributesToRetrieve: [title,producer,director]
// attributesToCrop: [overview]
// cropLength: 10
#[test]
fn search_with_differents_attributes_2() {
#[actix_rt::test]
async fn search_with_differents_attributes_2() {
let query = "q=captain&limit=1&attributesToRetrieve=title,producer,director&attributesToCrop=overview&cropLength=10";
let expected = json!([
@ -914,7 +914,7 @@ fn search_with_differents_attributes_2() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -923,8 +923,8 @@ fn search_with_differents_attributes_2() {
// limit: 1
// attributesToRetrieve: [title,producer,director]
// attributesToCrop: [overview:10]
#[test]
fn search_with_differents_attributes_3() {
#[actix_rt::test]
async fn search_with_differents_attributes_3() {
let query = "q=captain&limit=1&attributesToRetrieve=title,producer,director&attributesToCrop=overview:10";
let expected = json!([
@ -938,7 +938,7 @@ fn search_with_differents_attributes_3() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -947,8 +947,8 @@ fn search_with_differents_attributes_3() {
// limit: 1
// attributesToRetrieve: [title,producer,director]
// attributesToCrop: [overview:10,title:0]
#[test]
fn search_with_differents_attributes_4() {
#[actix_rt::test]
async fn search_with_differents_attributes_4() {
let query = "q=captain&limit=1&attributesToRetrieve=title,producer,director&attributesToCrop=overview:10,title:0";
let expected = json!([
@ -963,7 +963,7 @@ fn search_with_differents_attributes_4() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -972,8 +972,8 @@ fn search_with_differents_attributes_4() {
// limit: 1
// attributesToRetrieve: [title,producer,director]
// attributesToCrop: [*,overview:10]
#[test]
fn search_with_differents_attributes_5() {
#[actix_rt::test]
async fn search_with_differents_attributes_5() {
let query = "q=captain&limit=1&attributesToRetrieve=title,producer,director&attributesToCrop=*,overview:10";
let expected = json!([
@ -990,7 +990,7 @@ fn search_with_differents_attributes_5() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -1000,8 +1000,8 @@ fn search_with_differents_attributes_5() {
// attributesToRetrieve: [title,producer,director]
// attributesToCrop: [*,overview:10]
// attributesToHighlight: [title]
#[test]
fn search_with_differents_attributes_6() {
#[actix_rt::test]
async fn search_with_differents_attributes_6() {
let query = "q=captain&limit=1&attributesToRetrieve=title,producer,director&attributesToCrop=*,overview:10&attributesToHighlight=title";
let expected = json!([
@ -1018,7 +1018,7 @@ fn search_with_differents_attributes_6() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -1028,8 +1028,8 @@ fn search_with_differents_attributes_6() {
// attributesToRetrieve: [title,producer,director]
// attributesToCrop: [*,overview:10]
// attributesToHighlight: [*]
#[test]
fn search_with_differents_attributes_7() {
#[actix_rt::test]
async fn search_with_differents_attributes_7() {
let query = "q=captain&limit=1&attributesToRetrieve=title,producer,director&attributesToCrop=*,overview:10&attributesToHighlight=*";
let expected = json!([
@ -1046,7 +1046,7 @@ fn search_with_differents_attributes_7() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}
@ -1056,8 +1056,8 @@ fn search_with_differents_attributes_7() {
// attributesToRetrieve: [title,producer,director]
// attributesToCrop: [*,overview:10]
// attributesToHighlight: [*,tagline]
#[test]
fn search_with_differents_attributes_8() {
#[actix_rt::test]
async fn search_with_differents_attributes_8() {
let query = "q=captain&limit=1&attributesToRetrieve=title,producer,director&attributesToCrop=*,overview:10&attributesToHighlight=*,tagline";
let expected = json!([
@ -1075,6 +1075,6 @@ fn search_with_differents_attributes_8() {
}
]);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query);
let (response, _status_code) = GLOBAL_SERVER.lock().unwrap().search(query).await;
assert_json_eq!(expected, response["hits"].clone(), ordered: false);
}

View File

@ -4,10 +4,10 @@ use std::convert::Into;
mod common;
#[test]
fn search_with_settings_basic() {
#[actix_rt::test]
async fn search_with_settings_basic() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
let config = json!({
"rankingRules": [
@ -49,7 +49,7 @@ fn search_with_settings_basic() {
"acceptNewFields": false,
});
server.update_all_settings(config);
server.update_all_settings(config).await;
let query = "q=the%20avangers&limit=3";
let expect = json!([
@ -106,14 +106,14 @@ fn search_with_settings_basic() {
}
]);
let (response, _status_code) = server.search(query);
let (response, _status_code) = server.search(query).await;
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
}
#[test]
fn search_with_settings_stop_words() {
#[actix_rt::test]
async fn search_with_settings_stop_words() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
let config = json!({
"rankingRules": [
@ -155,7 +155,7 @@ fn search_with_settings_stop_words() {
"acceptNewFields": false,
});
server.update_all_settings(config);
server.update_all_settings(config).await;
let query = "q=the%20avangers&limit=3";
let expect = json!([
@ -212,14 +212,14 @@ fn search_with_settings_stop_words() {
}
]);
let (response, _status_code) = server.search(query);
let (response, _status_code) = server.search(query).await;
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
}
#[test]
fn search_with_settings_synonyms() {
#[actix_rt::test]
async fn search_with_settings_synonyms() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
let config = json!({
"rankingRules": [
@ -266,7 +266,7 @@ fn search_with_settings_synonyms() {
"acceptNewFields": false,
});
server.update_all_settings(config);
server.update_all_settings(config).await;
let query = "q=avangers&limit=3";
let expect = json!([
@ -323,14 +323,14 @@ fn search_with_settings_synonyms() {
}
]);
let (response, _status_code) = server.search(query);
let (response, _status_code) = server.search(query).await;
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
}
#[test]
fn search_with_settings_ranking_rules() {
#[actix_rt::test]
async fn search_with_settings_ranking_rules() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
let config = json!({
"rankingRules": [
@ -372,7 +372,7 @@ fn search_with_settings_ranking_rules() {
"acceptNewFields": false,
});
server.update_all_settings(config);
server.update_all_settings(config).await;
let query = "q=avangers&limit=3";
let expect = json!([
@ -429,14 +429,14 @@ fn search_with_settings_ranking_rules() {
}
]);
let (response, _status_code) = server.search(query);
let (response, _status_code) = server.search(query).await;
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
}
#[test]
fn search_with_settings_searchable_attributes() {
#[actix_rt::test]
async fn search_with_settings_searchable_attributes() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
let config = json!({
"rankingRules": [
@ -477,7 +477,7 @@ fn search_with_settings_searchable_attributes() {
"acceptNewFields": false,
});
server.update_all_settings(config);
server.update_all_settings(config).await;
let query = "q=avangers&limit=3";
let expect = json!([
@ -534,14 +534,14 @@ fn search_with_settings_searchable_attributes() {
}
]);
let (response, _status_code) = server.search(query);
let (response, _status_code) = server.search(query).await;
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
}
#[test]
fn search_with_settings_displayed_attributes() {
#[actix_rt::test]
async fn search_with_settings_displayed_attributes() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
let config = json!({
"rankingRules": [
@ -577,7 +577,7 @@ fn search_with_settings_displayed_attributes() {
"acceptNewFields": false,
});
server.update_all_settings(config);
server.update_all_settings(config).await;
let query = "q=avangers&limit=3";
let expect = json!([
@ -604,14 +604,14 @@ fn search_with_settings_displayed_attributes() {
}
]);
let (response, _status_code) = server.search(query);
let (response, _status_code) = server.search(query).await;
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
}
#[test]
fn search_with_settings_searchable_attributes_2() {
#[actix_rt::test]
async fn search_with_settings_searchable_attributes_2() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
let config = json!({
"rankingRules": [
@ -647,7 +647,7 @@ fn search_with_settings_searchable_attributes_2() {
"acceptNewFields": false,
});
server.update_all_settings(config);
server.update_all_settings(config).await;
let query = "q=avangers&limit=3";
let expect = json!([
@ -674,6 +674,6 @@ fn search_with_settings_searchable_attributes_2() {
}
]);
let (response, _status_code) = server.search(query);
let (response, _status_code) = server.search(query).await;
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
}

View File

@ -4,10 +4,10 @@ use std::convert::Into;
mod common;
#[test]
fn write_all_and_delete() {
#[actix_rt::test]
async fn write_all_and_delete() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
// 2 - Send the settings
@ -51,21 +51,21 @@ fn write_all_and_delete() {
"acceptNewFields": false,
});
server.update_all_settings(body.clone());
server.update_all_settings(body.clone()).await;
// 3 - Get all settings and compare to the previous one
let (response, _status_code) = server.get_all_settings();
let (response, _status_code) = server.get_all_settings().await;
assert_json_eq!(body, response, ordered: false);
// 4 - Delete all settings
server.delete_all_settings();
server.delete_all_settings().await;
// 5 - Get all settings and check if they are set to default values
let (response, _status_code) = server.get_all_settings();
let (response, _status_code) = server.get_all_settings().await;
let expect = json!({
"rankingRules": [
@ -125,10 +125,10 @@ fn write_all_and_delete() {
assert_json_eq!(expect, response, ordered: false);
}
#[test]
fn write_all_and_update() {
#[actix_rt::test]
async fn write_all_and_update() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
// 2 - Send the settings
@ -172,11 +172,11 @@ fn write_all_and_update() {
"acceptNewFields": false,
});
server.update_all_settings(body.clone());
server.update_all_settings(body.clone()).await;
// 3 - Get all settings and compare to the previous one
let (response, _status_code) = server.get_all_settings();
let (response, _status_code) = server.get_all_settings().await;
assert_json_eq!(body, response, ordered: false);
@ -213,11 +213,11 @@ fn write_all_and_update() {
"acceptNewFields": false,
});
server.update_all_settings(body);
server.update_all_settings(body).await;
// 5 - Get all settings and check if the content is the same of (4)
let (response, _status_code) = server.get_all_settings();
let (response, _status_code) = server.get_all_settings().await;
let expected = json!({
"rankingRules": [
@ -253,13 +253,13 @@ fn write_all_and_update() {
assert_json_eq!(expected, response, ordered: false);
}
#[test]
fn test_default_settings() {
#[actix_rt::test]
async fn test_default_settings() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
});
server.create_index(body);
server.create_index(body).await;
// 1 - Get all settings and compare to the previous one
@ -280,19 +280,19 @@ fn test_default_settings() {
"acceptNewFields": true,
});
let (response, _status_code) = server.get_all_settings();
let (response, _status_code) = server.get_all_settings().await;
assert_json_eq!(body, response, ordered: false);
}
#[test]
fn test_default_settings_2() {
#[actix_rt::test]
async fn test_default_settings_2() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
"primaryKey": "id",
});
server.create_index(body);
server.create_index(body).await;
// 1 - Get all settings and compare to the previous one
@ -317,19 +317,19 @@ fn test_default_settings_2() {
"acceptNewFields": true,
});
let (response, _status_code) = server.get_all_settings();
let (response, _status_code) = server.get_all_settings().await;
assert_json_eq!(body, response, ordered: false);
}
// Test issue https://github.com/meilisearch/MeiliSearch/issues/516
#[test]
fn write_setting_and_update_partial() {
#[actix_rt::test]
async fn write_setting_and_update_partial() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
});
server.create_index(body);
server.create_index(body).await;
// 2 - Send the settings
@ -352,7 +352,7 @@ fn write_setting_and_update_partial() {
]
});
server.update_all_settings(body.clone());
server.update_all_settings(body.clone()).await;
// 2 - Send the settings
@ -380,7 +380,7 @@ fn write_setting_and_update_partial() {
"acceptNewFields": false,
});
server.update_all_settings(body.clone());
server.update_all_settings(body.clone()).await;
// 2 - Send the settings
@ -424,7 +424,7 @@ fn write_setting_and_update_partial() {
"acceptNewFields": false,
});
let (response, _status_code) = server.get_all_settings();
let (response, _status_code) = server.get_all_settings().await;
assert_json_eq!(expected, response, ordered: false);
}

View File

@ -3,14 +3,14 @@ use serde_json::json;
mod common;
#[test]
fn index_new_fields_default() {
#[actix_rt::test]
async fn index_new_fields_default() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
"primaryKey": "id",
});
server.create_index(body);
server.create_index(body).await;
// 1 - Add a document
@ -19,7 +19,7 @@ fn index_new_fields_default() {
"title": "I'm a legend",
}]);
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 2 - Get the complete document
@ -28,7 +28,7 @@ fn index_new_fields_default() {
"title": "I'm a legend",
});
let (response, status_code) = server.get_document(1);
let (response, status_code) = server.get_document(1).await;
assert_eq!(status_code, 200);
assert_json_eq!(response, expected);
@ -40,7 +40,7 @@ fn index_new_fields_default() {
"description": "A bad copy of the original movie I'm a lengend"
}]);
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 4 - Get the complete document
@ -50,23 +50,23 @@ fn index_new_fields_default() {
"description": "A bad copy of the original movie I'm a lengend"
});
let (response, status_code) = server.get_document(2);
let (response, status_code) = server.get_document(2).await;
assert_eq!(status_code, 200);
assert_json_eq!(response, expected);
}
#[test]
fn index_new_fields_true() {
#[actix_rt::test]
async fn index_new_fields_true() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
"primaryKey": "id",
});
server.create_index(body);
server.create_index(body).await;
// 1 - Set indexNewFields = true
server.update_accept_new_fields(json!(true));
server.update_accept_new_fields(json!(true)).await;
// 2 - Add a document
@ -75,7 +75,7 @@ fn index_new_fields_true() {
"title": "I'm a legend",
}]);
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 3 - Get the complete document
@ -84,7 +84,7 @@ fn index_new_fields_true() {
"title": "I'm a legend",
});
let (response, status_code) = server.get_document(1);
let (response, status_code) = server.get_document(1).await;
assert_eq!(status_code, 200);
assert_json_eq!(response, expected);
@ -96,7 +96,7 @@ fn index_new_fields_true() {
"description": "A bad copy of the original movie I'm a lengend"
}]);
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 5 - Get the complete document
@ -106,23 +106,23 @@ fn index_new_fields_true() {
"description": "A bad copy of the original movie I'm a lengend"
});
let (response, status_code) = server.get_document(2);
let (response, status_code) = server.get_document(2).await;
assert_eq!(status_code, 200);
assert_json_eq!(response, expected);
}
#[test]
fn index_new_fields_false() {
#[actix_rt::test]
async fn index_new_fields_false() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
"primaryKey": "id",
});
server.create_index(body);
server.create_index(body).await;
// 1 - Set indexNewFields = false
server.update_accept_new_fields(json!(false));
server.update_accept_new_fields(json!(false)).await;
// 2 - Add a document
@ -131,7 +131,7 @@ fn index_new_fields_false() {
"title": "I'm a legend",
}]);
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 3 - Get the complete document
@ -139,7 +139,7 @@ fn index_new_fields_false() {
"id": 1,
});
let (response, status_code) = server.get_document(1);
let (response, status_code) = server.get_document(1).await;
assert_eq!(status_code, 200);
assert_json_eq!(response, expected);
@ -151,7 +151,7 @@ fn index_new_fields_false() {
"description": "A bad copy of the original movie I'm a lengend"
}]);
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 5 - Get the complete document
@ -159,23 +159,23 @@ fn index_new_fields_false() {
"id": 2,
});
let (response, status_code) = server.get_document(2);
let (response, status_code) = server.get_document(2).await;
assert_eq!(status_code, 200);
assert_json_eq!(response, expected);
}
#[test]
fn index_new_fields_true_then_false() {
#[actix_rt::test]
async fn index_new_fields_true_then_false() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
"primaryKey": "id",
});
server.create_index(body);
server.create_index(body).await;
// 1 - Set indexNewFields = true
server.update_accept_new_fields(json!(true));
server.update_accept_new_fields(json!(true)).await;
// 2 - Add a document
@ -184,7 +184,7 @@ fn index_new_fields_true_then_false() {
"title": "I'm a legend",
}]);
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 3 - Get the complete document
@ -193,13 +193,13 @@ fn index_new_fields_true_then_false() {
"title": "I'm a legend",
});
let (response, status_code) = server.get_document(1);
let (response, status_code) = server.get_document(1).await;
assert_eq!(status_code, 200);
assert_json_eq!(response, expected);
// 4 - Set indexNewFields = false
server.update_accept_new_fields(json!(false));
server.update_accept_new_fields(json!(false)).await;
// 5 - Add a document with more fields
@ -209,7 +209,7 @@ fn index_new_fields_true_then_false() {
"description": "A bad copy of the original movie I'm a lengend"
}]);
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 6 - Get the complete document
@ -218,23 +218,23 @@ fn index_new_fields_true_then_false() {
"title": "I'm not a legend",
});
let (response, status_code) = server.get_document(2);
let (response, status_code) = server.get_document(2).await;
assert_eq!(status_code, 200);
assert_json_eq!(response, expected);
}
#[test]
fn index_new_fields_false_then_true() {
#[actix_rt::test]
async fn index_new_fields_false_then_true() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
"primaryKey": "id",
});
server.create_index(body);
server.create_index(body).await;
// 1 - Set indexNewFields = false
server.update_accept_new_fields(json!(false));
server.update_accept_new_fields(json!(false)).await;
// 2 - Add a document
@ -243,7 +243,7 @@ fn index_new_fields_false_then_true() {
"title": "I'm a legend",
}]);
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 3 - Get the complete document
@ -251,13 +251,13 @@ fn index_new_fields_false_then_true() {
"id": 1,
});
let (response, status_code) = server.get_document(1);
let (response, status_code) = server.get_document(1).await;
assert_eq!(status_code, 200);
assert_json_eq!(response, expected);
// 4 - Set indexNewFields = false
server.update_accept_new_fields(json!(true));
server.update_accept_new_fields(json!(true)).await;
// 5 - Add a document with more fields
@ -267,7 +267,7 @@ fn index_new_fields_false_then_true() {
"description": "A bad copy of the original movie I'm a lengend"
}]);
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 6 - Get the complete document
@ -275,7 +275,7 @@ fn index_new_fields_false_then_true() {
"id": 1,
});
let (response, status_code) = server.get_document(1);
let (response, status_code) = server.get_document(1).await;
assert_eq!(status_code, 200);
assert_json_eq!(response, expected);
@ -284,14 +284,14 @@ fn index_new_fields_false_then_true() {
"description": "A bad copy of the original movie I'm a lengend"
});
let (response, status_code) = server.get_document(2);
let (response, status_code) = server.get_document(2).await;
assert_eq!(status_code, 200);
assert_json_eq!(response, expected);
}
// Fix issue https://github.com/meilisearch/MeiliSearch/issues/518
#[test]
fn accept_new_fields_does_not_take_into_account_the_primary_key() {
#[actix_rt::test]
async fn accept_new_fields_does_not_take_into_account_the_primary_key() {
let mut server = common::Server::with_uid("movies");
// 1 - Create an index with no primary-key
@ -299,7 +299,7 @@ fn accept_new_fields_does_not_take_into_account_the_primary_key() {
let body = json!({
"uid": "movies",
});
let (response, status_code) = server.create_index(body);
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
@ -311,7 +311,7 @@ fn accept_new_fields_does_not_take_into_account_the_primary_key() {
"acceptNewFields": false,
});
server.update_all_settings(body);
server.update_all_settings(body).await;
// 4 - Add a document
@ -321,11 +321,11 @@ fn accept_new_fields_does_not_take_into_account_the_primary_key() {
"comment": "comment test"
}]);
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 5 - Get settings, they should not changed
let (response, _status_code) = server.get_all_settings();
let (response, _status_code) = server.get_all_settings().await;
let expected = json!({
"rankingRules": [

View File

@ -3,10 +3,10 @@ use serde_json::json;
mod common;
#[test]
fn write_all_and_delete() {
#[actix_rt::test]
async fn write_all_and_delete() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
// 2 - Send the settings
@ -21,21 +21,21 @@ fn write_all_and_delete() {
"desc(rank)",
]);
server.update_ranking_rules(body.clone());
server.update_ranking_rules(body.clone()).await;
// 3 - Get all settings and compare to the previous one
let (response, _status_code) = server.get_ranking_rules();
let (response, _status_code) = server.get_ranking_rules().await;
assert_json_eq!(body, response, ordered: false);
// 4 - Delete all settings
server.delete_ranking_rules();
server.delete_ranking_rules().await;
// 5 - Get all settings and check if they are empty
let (response, _status_code) = server.get_ranking_rules();
let (response, _status_code) = server.get_ranking_rules().await;
let expected = json!([
"typo",
@ -49,10 +49,10 @@ fn write_all_and_delete() {
assert_json_eq!(expected, response, ordered: false);
}
#[test]
fn write_all_and_update() {
#[actix_rt::test]
async fn write_all_and_update() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
// 2 - Send the settings
@ -67,11 +67,11 @@ fn write_all_and_update() {
"desc(rank)",
]);
server.update_ranking_rules(body.clone());
server.update_ranking_rules(body.clone()).await;
// 3 - Get all settings and compare to the previous one
let (response, _status_code) = server.get_ranking_rules();
let (response, _status_code) = server.get_ranking_rules().await;
assert_json_eq!(body, response, ordered: false);
@ -87,11 +87,11 @@ fn write_all_and_update() {
"desc(release_date)",
]);
server.update_ranking_rules(body);
server.update_ranking_rules(body).await;
// 5 - Get all settings and check if the content is the same of (4)
let (response, _status_code) = server.get_ranking_rules();
let (response, _status_code) = server.get_ranking_rules().await;
let expected = json!([
"typo",
@ -106,51 +106,51 @@ fn write_all_and_update() {
assert_json_eq!(expected, response, ordered: false);
}
#[test]
fn send_undefined_rule() {
#[actix_rt::test]
async fn send_undefined_rule() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
"primaryKey": "id",
});
server.create_index(body);
server.create_index(body).await;
let body = json!(["typos",]);
let (_response, status_code) = server.update_ranking_rules_sync(body);
let (_response, status_code) = server.update_ranking_rules_sync(body).await;
assert_eq!(status_code, 400);
}
#[test]
fn send_malformed_custom_rule() {
#[actix_rt::test]
async fn send_malformed_custom_rule() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
"primaryKey": "id",
});
server.create_index(body);
server.create_index(body).await;
let body = json!(["dsc(truc)",]);
let (_response, status_code) = server.update_ranking_rules_sync(body);
let (_response, status_code) = server.update_ranking_rules_sync(body).await;
assert_eq!(status_code, 400);
}
// Test issue https://github.com/meilisearch/MeiliSearch/issues/521
#[test]
fn write_custom_ranking_and_index_documents() {
#[actix_rt::test]
async fn write_custom_ranking_and_index_documents() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
"primaryKey": "id",
});
server.create_index(body);
server.create_index(body).await;
// 1 - Add ranking rules with one custom ranking on a string
let body = json!(["asc(title)", "typo"]);
server.update_ranking_rules(body);
server.update_ranking_rules(body).await;
// 2 - Add documents
@ -167,7 +167,7 @@ fn write_custom_ranking_and_index_documents() {
}
]);
server.add_or_replace_multiple_documents(body);
server.add_or_replace_multiple_documents(body).await;
// 3 - Get the first document and compare
@ -177,7 +177,7 @@ fn write_custom_ranking_and_index_documents() {
"author": "Exupéry"
});
let (response, status_code) = server.get_document(1);
let (response, status_code) = server.get_document(1).await;
assert_eq!(status_code, 200);
assert_json_eq!(response, expected, ordered: false);

View File

@ -3,54 +3,54 @@ use serde_json::json;
mod common;
#[test]
fn update_stop_words() {
#[actix_rt::test]
async fn update_stop_words() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
// 1 - Get stop words
let (response, _status_code) = server.get_stop_words();
let (response, _status_code) = server.get_stop_words().await;
assert_eq!(response.as_array().unwrap().is_empty(), true);
// 2 - Update stop words
let body = json!(["the", "a"]);
server.update_stop_words(body.clone());
server.update_stop_words(body.clone()).await;
// 3 - Get all stop words and compare to the previous one
let (response, _status_code) = server.get_stop_words();
let (response, _status_code) = server.get_stop_words().await;
assert_json_eq!(body, response, ordered: false);
// 4 - Delete all stop words
server.delete_stop_words();
server.delete_stop_words().await;
// 5 - Get all stop words and check if they are empty
let (response, _status_code) = server.get_stop_words();
let (response, _status_code) = server.get_stop_words().await;
assert_eq!(response.as_array().unwrap().is_empty(), true);
}
#[test]
fn add_documents_and_stop_words() {
#[actix_rt::test]
async fn add_documents_and_stop_words() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
server.populate_movies().await;
// 2 - Update stop words
let body = json!(["the", "of"]);
server.update_stop_words(body.clone());
server.update_stop_words(body.clone()).await;
// 3 - Search for a document with stop words
let (response, _status_code) = server.search("q=the%20mask");
let (response, _status_code) = server.search("q=the%20mask").await;
assert!(!response["hits"].as_array().unwrap().is_empty());
// 4 - Search for documents with *only* stop words
let (response, _status_code) = server.search("q=the%20of");
let (response, _status_code) = server.search("q=the%20of").await;
assert!(response["hits"].as_array().unwrap().is_empty());
// 5 - Delete all stop words