2021-12-02 16:03:26 +01:00
|
|
|
use serde_json::json;
|
2022-02-14 15:32:41 +01:00
|
|
|
use time::format_description::well_known::Rfc3339;
|
|
|
|
use time::OffsetDateTime;
|
2021-12-02 16:03:26 +01:00
|
|
|
|
2022-10-20 18:00:07 +02:00
|
|
|
use crate::common::Server;
|
|
|
|
|
2021-12-02 16:03:26 +01:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn error_get_unexisting_task_status() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
index.create(None).await;
|
|
|
|
index.wait_task(0).await;
|
|
|
|
let (response, code) = index.get_task(1).await;
|
|
|
|
|
|
|
|
let expected_response = json!({
|
|
|
|
"message": "Task `1` not found.",
|
|
|
|
"code": "task_not_found",
|
|
|
|
"type": "invalid_request",
|
|
|
|
"link": "https://docs.meilisearch.com/errors#task_not_found"
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_eq!(response, expected_response);
|
|
|
|
assert_eq!(code, 404);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn get_task_status() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
index.create(None).await;
|
|
|
|
index
|
|
|
|
.add_documents(
|
|
|
|
serde_json::json!([{
|
|
|
|
"id": 1,
|
|
|
|
"content": "foobar",
|
|
|
|
}]),
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
.await;
|
|
|
|
index.wait_task(0).await;
|
|
|
|
let (_response, code) = index.get_task(1).await;
|
|
|
|
assert_eq!(code, 200);
|
2022-06-28 00:58:11 +02:00
|
|
|
// TODO check response format, as per #48
|
2021-12-02 16:03:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn list_tasks() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
index.create(None).await;
|
|
|
|
index.wait_task(0).await;
|
|
|
|
index
|
2022-10-20 18:00:07 +02:00
|
|
|
.add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None)
|
2021-12-02 16:03:26 +01:00
|
|
|
.await;
|
|
|
|
let (response, code) = index.list_tasks().await;
|
|
|
|
assert_eq!(code, 200);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 2);
|
|
|
|
}
|
|
|
|
|
2022-05-30 13:59:27 +02:00
|
|
|
#[actix_rt::test]
|
2022-05-30 17:12:53 +02:00
|
|
|
async fn list_tasks_with_star_filters() {
|
2022-05-30 13:59:27 +02:00
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
index.create(None).await;
|
|
|
|
index.wait_task(0).await;
|
|
|
|
index
|
2022-10-20 18:00:07 +02:00
|
|
|
.add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None)
|
2022-05-30 13:59:27 +02:00
|
|
|
.await;
|
|
|
|
let (response, code) = index.service.get("/tasks?indexUid=test").await;
|
|
|
|
assert_eq!(code, 200);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 2);
|
|
|
|
|
|
|
|
let (response, code) = index.service.get("/tasks?indexUid=*").await;
|
|
|
|
assert_eq!(code, 200);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 2);
|
|
|
|
|
|
|
|
let (response, code) = index.service.get("/tasks?indexUid=*,pasteque").await;
|
|
|
|
assert_eq!(code, 200);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 2);
|
2022-05-30 17:12:53 +02:00
|
|
|
|
|
|
|
let (response, code) = index.service.get("/tasks?type=*").await;
|
|
|
|
assert_eq!(code, 200);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 2);
|
|
|
|
|
2022-10-20 18:00:07 +02:00
|
|
|
let (response, code) =
|
|
|
|
index.service.get("/tasks?type=*,documentAdditionOrUpdate&status=*").await;
|
2022-05-30 17:12:53 +02:00
|
|
|
assert_eq!(code, 200, "{:?}", response);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 2);
|
|
|
|
|
|
|
|
let (response, code) = index
|
|
|
|
.service
|
|
|
|
.get("/tasks?type=*,documentAdditionOrUpdate&status=*,failed&indexUid=test")
|
|
|
|
.await;
|
|
|
|
assert_eq!(code, 200, "{:?}", response);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 2);
|
|
|
|
|
|
|
|
let (response, code) = index
|
|
|
|
.service
|
|
|
|
.get("/tasks?type=*,documentAdditionOrUpdate&status=*,failed&indexUid=test,*")
|
|
|
|
.await;
|
|
|
|
assert_eq!(code, 200, "{:?}", response);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 2);
|
2022-05-30 13:59:27 +02:00
|
|
|
}
|
|
|
|
|
2022-05-18 12:07:06 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn list_tasks_status_filtered() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
index.create(None).await;
|
|
|
|
index.wait_task(0).await;
|
|
|
|
index
|
2022-10-20 18:00:07 +02:00
|
|
|
.add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None)
|
2022-05-18 12:07:06 +02:00
|
|
|
.await;
|
|
|
|
|
|
|
|
let (response, code) = index.filtered_tasks(&[], &["succeeded"]).await;
|
|
|
|
assert_eq!(code, 200, "{}", response);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 1);
|
|
|
|
|
2022-05-25 12:05:24 +02:00
|
|
|
// We can't be sure that the update isn't already processed so we can't test this
|
|
|
|
// let (response, code) = index.filtered_tasks(&[], &["processing"]).await;
|
|
|
|
// assert_eq!(code, 200, "{}", response);
|
|
|
|
// assert_eq!(response["results"].as_array().unwrap().len(), 1);
|
2022-05-18 12:07:06 +02:00
|
|
|
|
|
|
|
index.wait_task(1).await;
|
|
|
|
|
|
|
|
let (response, code) = index.filtered_tasks(&[], &["succeeded"]).await;
|
|
|
|
assert_eq!(code, 200, "{}", response);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn list_tasks_type_filtered() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
index.create(None).await;
|
|
|
|
index.wait_task(0).await;
|
|
|
|
index
|
2022-10-20 18:00:07 +02:00
|
|
|
.add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None)
|
2022-05-18 12:07:06 +02:00
|
|
|
.await;
|
|
|
|
|
|
|
|
let (response, code) = index.filtered_tasks(&["indexCreation"], &[]).await;
|
|
|
|
assert_eq!(code, 200, "{}", response);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 1);
|
|
|
|
|
2022-10-20 18:00:07 +02:00
|
|
|
let (response, code) =
|
|
|
|
index.filtered_tasks(&["indexCreation", "documentAdditionOrUpdate"], &[]).await;
|
2022-05-18 12:07:06 +02:00
|
|
|
assert_eq!(code, 200, "{}", response);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn list_tasks_status_and_type_filtered() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
index.create(None).await;
|
|
|
|
index.wait_task(0).await;
|
|
|
|
index
|
2022-10-20 18:00:07 +02:00
|
|
|
.add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None)
|
2022-05-18 12:07:06 +02:00
|
|
|
.await;
|
|
|
|
|
|
|
|
let (response, code) = index.filtered_tasks(&["indexCreation"], &["failed"]).await;
|
|
|
|
assert_eq!(code, 200, "{}", response);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 0);
|
|
|
|
|
|
|
|
let (response, code) = index
|
|
|
|
.filtered_tasks(
|
2022-05-25 12:05:24 +02:00
|
|
|
&["indexCreation", "documentAdditionOrUpdate"],
|
2022-06-02 10:21:19 +02:00
|
|
|
&["succeeded", "processing", "enqueued"],
|
2022-05-18 12:07:06 +02:00
|
|
|
)
|
|
|
|
.await;
|
|
|
|
assert_eq!(code, 200, "{}", response);
|
|
|
|
assert_eq!(response["results"].as_array().unwrap().len(), 2);
|
|
|
|
}
|
|
|
|
|
2021-12-02 16:03:26 +01:00
|
|
|
macro_rules! assert_valid_summarized_task {
|
|
|
|
($response:expr, $task_type:literal, $index:literal) => {{
|
|
|
|
assert_eq!($response.as_object().unwrap().len(), 5);
|
2022-05-17 11:17:32 +02:00
|
|
|
assert!($response["taskUid"].as_u64().is_some());
|
2021-12-02 16:03:26 +01:00
|
|
|
assert_eq!($response["indexUid"], $index);
|
|
|
|
assert_eq!($response["status"], "enqueued");
|
|
|
|
assert_eq!($response["type"], $task_type);
|
|
|
|
let date = $response["enqueuedAt"].as_str().expect("missing date");
|
2022-02-14 15:32:41 +01:00
|
|
|
|
|
|
|
OffsetDateTime::parse(date, &Rfc3339).unwrap();
|
2021-12-02 16:03:26 +01:00
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_web::test]
|
|
|
|
async fn test_summarized_task_view() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
|
|
|
|
let (response, _) = index.create(None).await;
|
|
|
|
assert_valid_summarized_task!(response, "indexCreation", "test");
|
|
|
|
|
|
|
|
let (response, _) = index.update(None).await;
|
|
|
|
assert_valid_summarized_task!(response, "indexUpdate", "test");
|
|
|
|
|
|
|
|
let (response, _) = index.update_settings(json!({})).await;
|
|
|
|
assert_valid_summarized_task!(response, "settingsUpdate", "test");
|
|
|
|
|
|
|
|
let (response, _) = index.update_documents(json!([{"id": 1}]), None).await;
|
2022-05-25 12:05:24 +02:00
|
|
|
assert_valid_summarized_task!(response, "documentAdditionOrUpdate", "test");
|
2021-12-02 16:03:26 +01:00
|
|
|
|
|
|
|
let (response, _) = index.add_documents(json!([{"id": 1}]), None).await;
|
2022-05-25 12:05:24 +02:00
|
|
|
assert_valid_summarized_task!(response, "documentAdditionOrUpdate", "test");
|
2021-12-02 16:03:26 +01:00
|
|
|
|
|
|
|
let (response, _) = index.delete_document(1).await;
|
2021-12-15 09:49:39 +01:00
|
|
|
assert_valid_summarized_task!(response, "documentDeletion", "test");
|
2021-12-02 16:03:26 +01:00
|
|
|
|
|
|
|
let (response, _) = index.clear_all_documents().await;
|
2022-05-25 12:05:24 +02:00
|
|
|
assert_valid_summarized_task!(response, "documentDeletion", "test");
|
2021-12-02 16:03:26 +01:00
|
|
|
|
|
|
|
let (response, _) = index.delete().await;
|
|
|
|
assert_valid_summarized_task!(response, "indexDeletion", "test");
|
|
|
|
}
|