diff --git a/meilisearch-http/tests/assets/v5_v0.28.0_test_dump.dump b/meilisearch-http/tests/assets/v5_v0.28.0_test_dump.dump new file mode 100644 index 000000000..bc30ea7b9 Binary files /dev/null and b/meilisearch-http/tests/assets/v5_v0.28.0_test_dump.dump differ diff --git a/meilisearch-http/tests/common/server.rs b/meilisearch-http/tests/common/server.rs index c4ba8484f..146690766 100644 --- a/meilisearch-http/tests/common/server.rs +++ b/meilisearch-http/tests/common/server.rs @@ -52,16 +52,13 @@ impl Server { } } - pub async fn new_auth() -> Self { - let dir = TempDir::new().unwrap(); - + pub async fn new_auth_with_options(mut options: Opt, dir: TempDir) -> Self { if cfg!(windows) { std::env::set_var("TMP", TEST_TEMP_DIR.path()); } else { std::env::set_var("TMPDIR", TEST_TEMP_DIR.path()); } - let mut options = default_settings(dir.path()); options.master_key = Some("MASTER_KEY".to_string()); let meilisearch = setup_meilisearch(&options).unwrap(); @@ -79,6 +76,12 @@ impl Server { } } + pub async fn new_auth() -> Self { + let dir = TempDir::new().unwrap(); + let options = default_settings(dir.path()); + Self::new_auth_with_options(options, dir).await + } + pub async fn new_with_options(options: Opt) -> Result { let meilisearch = setup_meilisearch(&options)?; let auth = AuthController::new(&options.db_path, &options.master_key)?; diff --git a/meilisearch-http/tests/dumps/data.rs b/meilisearch-http/tests/dumps/data.rs index a5d7f3426..5df09bfd1 100644 --- a/meilisearch-http/tests/dumps/data.rs +++ b/meilisearch-http/tests/dumps/data.rs @@ -18,6 +18,8 @@ pub enum GetDump { MoviesRawV4, MoviesWithSettingsV4, RubyGemsWithSettingsV4, + + TestV5, } impl GetDump { @@ -63,6 +65,9 @@ impl GetDump { GetDump::RubyGemsWithSettingsV4 => { exist_relative_path!("tests/assets/v4_v0.25.2_rubygems_with_settings.dump").into() } + GetDump::TestV5 => { + exist_relative_path!("tests/assets/v5_v0.28.0_test_dump.dump").into() + } } } } diff --git a/meilisearch-http/tests/dumps/mod.rs b/meilisearch-http/tests/dumps/mod.rs index 75562a5a2..851f502a9 100644 --- a/meilisearch-http/tests/dumps/mod.rs +++ b/meilisearch-http/tests/dumps/mod.rs @@ -1,6 +1,6 @@ mod data; -use crate::common::{default_settings, Server}; +use crate::common::{default_settings, GetAllDocumentsOptions, Server}; use meilisearch_http::Opt; use serde_json::json; @@ -605,3 +605,73 @@ async fn import_dump_v4_rubygems_with_settings() { json!({ "name": "vortex-of-agony", "summary": "You dont need to use nodejs or go, just install this plugin. It will crash your application at random", "description": "You dont need to use nodejs or go, just install this plugin. It will crash your application at random", "id": "159227", "version": "0.1.0", "total_downloads": "1007"}) ); } + +#[actix_rt::test] +#[cfg_attr(target_os = "windows", ignore)] +async fn import_dump_v5() { + let temp = tempfile::tempdir().unwrap(); + + let options = Opt { + import_dump: Some(GetDump::TestV5.path()), + ..default_settings(temp.path()) + }; + let mut server = Server::new_auth_with_options(options, temp).await; + server.use_api_key("MASTER_KEY"); + + let (indexes, code) = server.list_indexes(None, None).await; + assert_eq!(code, 200, "{indexes}"); + + assert_eq!(indexes["results"].as_array().unwrap().len(), 2); + assert_eq!(indexes["results"][0]["uid"], json!("test")); + assert_eq!(indexes["results"][1]["uid"], json!("test2")); + assert_eq!(indexes["results"][0]["primaryKey"], json!("id")); + + let expected_stats = json!({ + "numberOfDocuments": 10, + "isIndexing": false, + "fieldDistribution": { + "cast": 10, + "director": 10, + "genres": 10, + "id": 10, + "overview": 10, + "popularity": 10, + "poster_path": 10, + "producer": 10, + "production_companies": 10, + "release_date": 10, + "tagline": 10, + "title": 10, + "vote_average": 10, + "vote_count": 10 + } + }); + + let index1 = server.index("test"); + let index2 = server.index("test2"); + + let (stats, code) = index1.stats().await; + assert_eq!(code, 200); + assert_eq!(stats, expected_stats); + + let (docs, code) = index2 + .get_all_documents(GetAllDocumentsOptions::default()) + .await; + assert_eq!(code, 200); + assert_eq!(docs["results"].as_array().unwrap().len(), 10); + let (docs, code) = index1 + .get_all_documents(GetAllDocumentsOptions::default()) + .await; + assert_eq!(code, 200); + assert_eq!(docs["results"].as_array().unwrap().len(), 10); + + let (stats, code) = index2.stats().await; + assert_eq!(code, 200); + assert_eq!(stats, expected_stats); + + let (keys, code) = server.list_api_keys().await; + assert_eq!(code, 200); + let key = &keys["results"][0]; + + assert_eq!(key["name"], "my key"); +}