meilisearch/meilisearch-http/tests/updates/mod.rs

98 lines
2.7 KiB
Rust
Raw Normal View History

2021-02-24 02:15:42 +08:00
use crate::common::Server;
2021-10-21 20:42:01 +08:00
use serde_json::json;
2021-02-24 02:15:42 +08:00
#[actix_rt::test]
2021-10-21 20:42:01 +08:00
async fn error_get_update_unexisting_index() {
2021-02-24 02:15:42 +08:00
let server = Server::new().await;
2021-10-21 20:42:01 +08:00
let (response, code) = server.index("test").get_update(0).await;
let expected_response = json!({
"message": "Index test not found.",
"code": "index_not_found",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_not_found"
});
assert_eq!(response, expected_response);
2021-06-16 04:21:52 +08:00
assert_eq!(code, 404);
2021-02-24 02:15:42 +08:00
}
#[actix_rt::test]
2021-10-21 20:42:01 +08:00
async fn error_get_unexisting_update_status() {
2021-02-24 02:15:42 +08:00
let server = Server::new().await;
let index = server.index("test");
index.create(None).await;
2021-10-21 20:42:01 +08:00
let (response, code) = index.get_update(0).await;
let expected_response = json!({
"message": "Task 0 not found.",
"code": "task_not_found",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#task_not_found"
});
assert_eq!(response, expected_response);
2021-06-16 04:21:52 +08:00
assert_eq!(code, 404);
2021-02-24 02:15:42 +08:00
}
#[actix_rt::test]
async fn get_update_status() {
let server = Server::new().await;
let index = server.index("test");
index.create(None).await;
2021-03-16 01:11:10 +08:00
index
.add_documents(
serde_json::json!([{
"id": 1,
"content": "foobar",
}]),
None,
)
.await;
2021-02-24 02:15:42 +08:00
let (_response, code) = index.get_update(0).await;
assert_eq!(code, 200);
// TODO check resonse format, as per #48
}
#[actix_rt::test]
2021-10-21 20:42:01 +08:00
async fn error_list_updates_unexisting_index() {
2021-02-24 02:15:42 +08:00
let server = Server::new().await;
2021-10-21 20:42:01 +08:00
let (response, code) = server.index("test").list_updates().await;
let expected_response = json!({
"message": "Index test not found.",
"code": "index_not_found",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_not_found"
});
assert_eq!(response, expected_response);
2021-06-16 04:21:52 +08:00
assert_eq!(code, 404);
2021-02-24 02:15:42 +08:00
}
#[actix_rt::test]
async fn list_no_updates() {
let server = Server::new().await;
let index = server.index("test");
index.create(None).await;
let (response, code) = index.list_updates().await;
assert_eq!(code, 200);
assert!(response.as_array().unwrap().is_empty());
}
#[actix_rt::test]
async fn list_updates() {
let server = Server::new().await;
let index = server.index("test");
index.create(None).await;
2021-03-16 01:11:10 +08:00
index
.add_documents(
serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(),
None,
)
.await;
2021-02-24 02:15:42 +08:00
let (response, code) = index.list_updates().await;
assert_eq!(code, 200);
assert_eq!(response.as_array().unwrap().len(), 1);
}