diff --git a/meilisearch-http/public/interface.html b/meilisearch-http/public/interface.html index ae221a005..1b45434b6 100644 --- a/meilisearch-http/public/interface.html +++ b/meilisearch-http/public/interface.html @@ -299,6 +299,8 @@ refreshIndexList(); search.oninput = triggerSearch; + + let select = document.getElementById("index"); select.onchange = triggerSearch; triggerSearch(); diff --git a/meilisearch-http/src/main.rs b/meilisearch-http/src/main.rs index 0537a462f..dcab2cfe7 100644 --- a/meilisearch-http/src/main.rs +++ b/meilisearch-http/src/main.rs @@ -70,7 +70,7 @@ async fn main() -> Result<(), MainError> { })); if let Some(path) = &opt.snapshot_path { - snapshot::schedule_snapshot(data.clone(), &path, opt.snapshot_interval_sec)?; + snapshot::schedule_snapshot(data.clone(), &path, opt.snapshot_interval_sec.unwrap_or(86400))?; } print_launch_resume(&opt, &data); diff --git a/meilisearch-http/src/option.rs b/meilisearch-http/src/option.rs index 2bcb62687..021890433 100644 --- a/meilisearch-http/src/option.rs +++ b/meilisearch-http/src/option.rs @@ -113,8 +113,8 @@ pub struct Opt { pub snapshot_path: Option, /// Defines time interval, in seconds, between each snapshot creation. - #[structopt(long, requires = "snapshot-path", default_value = "86400", env = "MEILI_SNAPSHOT_INTERVAL_SEC")] - pub snapshot_interval_sec: u64, + #[structopt(long, requires = "snapshot-path", env = "MEILI_SNAPSHOT_INTERVAL_SEC")] + pub snapshot_interval_sec: Option, } impl Opt { diff --git a/meilisearch-http/tests/index.rs b/meilisearch-http/tests/index.rs index 1f7e40725..6cca06898 100644 --- a/meilisearch-http/tests/index.rs +++ b/meilisearch-http/tests/index.rs @@ -663,30 +663,3 @@ async fn check_add_documents_without_primary_key() { assert_eq!(status_code, 400); } -#[actix_rt::test] -async fn check_first_update_should_bring_up_processed_status_after_first_docs_addition() { - let mut server = common::Server::with_uid("test"); - - let body = json!({ - "uid": "test", - }); - - // 1. Create Index - let (response, status_code) = server.create_index(body).await; - assert_eq!(status_code, 201); - assert_eq!(response["primaryKey"], json!(null)); - - let dataset = include_bytes!("assets/test_set.json"); - - 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).await; - - // 3. Fetch the status of the indexing done above. - 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); - assert_eq!(response[0]["status"], "processed"); -} diff --git a/meilisearch-http/tests/index_update.rs b/meilisearch-http/tests/index_update.rs new file mode 100644 index 000000000..4b8248f9f --- /dev/null +++ b/meilisearch-http/tests/index_update.rs @@ -0,0 +1,201 @@ +use assert_json_diff::assert_json_eq; +use serde_json::json; +use serde_json::Value; +use assert_json_diff::assert_json_include; + +mod common; + +#[actix_rt::test] +async fn check_first_update_should_bring_up_processed_status_after_first_docs_addition() { + let mut server = common::Server::with_uid("test"); + + let body = json!({ + "uid": "test", + }); + + // 1. Create Index + let (response, status_code) = server.create_index(body).await; + assert_eq!(status_code, 201); + assert_eq!(response["primaryKey"], json!(null)); + + let dataset = include_bytes!("assets/test_set.json"); + + 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).await; + + // 3. Fetch the status of the indexing done above. + 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); + assert_eq!(response[0]["status"], "processed"); +} + +#[actix_rt::test] +async fn return_error_when_get_update_status_of_unexisting_index() { + let mut server = common::Server::with_uid("test"); + + // 1. Fetch the status of unexisting index. + let (_, status_code) = server.get_all_updates_status().await; + + // 2. Verify the fetch returned 404 + assert_eq!(status_code, 404); +} + +#[actix_rt::test] +async fn return_empty_when_get_update_status_of_empty_index() { + let mut server = common::Server::with_uid("test"); + + let body = json!({ + "uid": "test", + }); + + // 1. Create Index + let (response, status_code) = server.create_index(body).await; + assert_eq!(status_code, 201); + assert_eq!(response["primaryKey"], json!(null)); + + // 2. Fetch the status of empty index. + let (response, status_code) = server.get_all_updates_status().await; + + // 3. Verify the fetch is successful, and no document are returned + assert_eq!(status_code, 200); + assert_eq!(response, json!([])); +} + +#[actix_rt::test] +async fn return_update_status_of_pushed_documents() { + let mut server = common::Server::with_uid("test"); + + let body = json!({ + "uid": "test", + }); + + // 1. Create Index + let (response, status_code) = server.create_index(body).await; + assert_eq!(status_code, 201); + assert_eq!(response["primaryKey"], json!(null)); + + + let bodies = vec![ + json!([{ + "title": "Test", + "comment": "comment test" + }]), + json!([{ + "title": "Test1", + "comment": "comment test1" + }]), + json!([{ + "title": "Test2", + "comment": "comment test2" + }]), + ]; + + let mut update_ids = Vec::new(); + + let url = "/indexes/test/documents?primaryKey=title"; + for body in bodies { + let (response, status_code) = server.post_request(&url, body).await; + assert_eq!(status_code, 202); + let update_id = response["updateId"].as_u64().unwrap(); + update_ids.push(update_id); + } + + // 2. Fetch the status of index. + let (response, status_code) = server.get_all_updates_status().await; + + // 3. Verify the fetch is successful, and updates are returned + + let expected = json!([{ + "type": { + "name": "DocumentsAddition", + "number": 1, + }, + "updateId": update_ids[0] + },{ + "type": { + "name": "DocumentsAddition", + "number": 1, + }, + "updateId": update_ids[1] + },{ + "type": { + "name": "DocumentsAddition", + "number": 1, + }, + "updateId": update_ids[2] + },]); + + assert_eq!(status_code, 200); + assert_json_include!(actual: json!(response), expected: expected); +} + +#[actix_rt::test] +async fn return_error_if_index_does_not_exist() { + let mut server = common::Server::with_uid("test"); + + let (response, status_code) = server.get_update_status(42).await; + + assert_eq!(status_code, 404); + assert_eq!(response["errorCode"], "index_not_found"); +} + +#[actix_rt::test] +async fn return_error_if_update_does_not_exist() { + let mut server = common::Server::with_uid("test"); + + let body = json!({ + "uid": "test", + }); + + // 1. Create Index + let (response, status_code) = server.create_index(body).await; + assert_eq!(status_code, 201); + assert_eq!(response["primaryKey"], json!(null)); + + let (response, status_code) = server.get_update_status(42).await; + + assert_eq!(status_code, 404); + assert_eq!(response["errorCode"], "not_found"); +} + +#[actix_rt::test] +async fn should_return_existing_update() { + let mut server = common::Server::with_uid("test"); + + let body = json!({ + "uid": "test", + }); + + // 1. Create Index + let (response, status_code) = server.create_index(body).await; + assert_eq!(status_code, 201); + assert_eq!(response["primaryKey"], json!(null)); + + let body = json!([{ + "title": "Test", + "comment": "comment test" + }]); + + let url = "/indexes/test/documents?primaryKey=title"; + let (response, status_code) = server.post_request(&url, body).await; + assert_eq!(status_code, 202); + + let update_id = response["updateId"].as_u64().unwrap(); + + let expected = json!({ + "type": { + "name": "DocumentsAddition", + "number": 1, + }, + "updateId": update_id + }); + + let (response, status_code) = server.get_update_status(update_id).await; + + assert_eq!(status_code, 200); + assert_json_include!(actual: json!(response), expected: expected); +}