From 1260c32d1879ccd74143ab21ad35a5eda49067ed Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 1 Dec 2022 14:01:52 +0100 Subject: [PATCH] Add reader mod test --- dump/src/reader/mod.rs | 77 +++++++++++++++++++ ...dump__reader__test__import_dump_v1-10.snap | 27 +++++++ ...dump__reader__test__import_dump_v1-11.snap | 23 ++++++ ...dump__reader__test__import_dump_v1-14.snap | 23 ++++++ .../dump__reader__test__import_dump_v1-5.snap | 37 +++++++++ .../dump__reader__test__import_dump_v1-6.snap | 37 +++++++++ .../dump__reader__test__import_dump_v1-8.snap | 27 +++++++ 7 files changed, 251 insertions(+) create mode 100644 dump/src/reader/snapshots/dump__reader__test__import_dump_v1-10.snap create mode 100644 dump/src/reader/snapshots/dump__reader__test__import_dump_v1-11.snap create mode 100644 dump/src/reader/snapshots/dump__reader__test__import_dump_v1-14.snap create mode 100644 dump/src/reader/snapshots/dump__reader__test__import_dump_v1-5.snap create mode 100644 dump/src/reader/snapshots/dump__reader__test__import_dump_v1-6.snap create mode 100644 dump/src/reader/snapshots/dump__reader__test__import_dump_v1-8.snap diff --git a/dump/src/reader/mod.rs b/dump/src/reader/mod.rs index 1368596d0..efbca06d0 100644 --- a/dump/src/reader/mod.rs +++ b/dump/src/reader/mod.rs @@ -529,4 +529,81 @@ pub(crate) mod test { assert_eq!(documents.len(), 10); meili_snap::snapshot_hash!(format!("{:#?}", documents), @"235016433dd04262c7f2da01d1e808ce"); } + + #[test] + fn import_dump_v1() { + let dump = File::open("tests/assets/v1.dump").unwrap(); + let mut dump = DumpReader::open(dump).unwrap(); + + // top level infos + assert_eq!(dump.date(), None); + assert_eq!(dump.instance_uid().unwrap(), None); + + // tasks + let tasks = dump.tasks().unwrap().collect::>>().unwrap(); + let (tasks, update_files): (Vec<_>, Vec<_>) = tasks.into_iter().unzip(); + meili_snap::snapshot_hash!(meili_snap::json_string!(tasks), @"b3e3652bfc10a76670be157d2507d761"); + assert_eq!(update_files.len(), 9); + assert!(update_files[..].iter().all(|u| u.is_none())); // no update file in dump v1 + + // keys + let keys = dump.keys().unwrap().collect::>>().unwrap(); + meili_snap::snapshot!(meili_snap::json_string!(keys), @"[]"); + meili_snap::snapshot_hash!(meili_snap::json_string!(keys), @"d751713988987e9331980363e24189ce"); + + // indexes + let mut indexes = dump.indexes().unwrap().collect::>>().unwrap(); + // the index are not ordered in any way by default + indexes.sort_by_key(|index| index.metadata().uid.to_string()); + + let mut products = indexes.pop().unwrap(); + let mut movies = indexes.pop().unwrap(); + let mut spells = indexes.pop().unwrap(); + assert!(indexes.is_empty()); + + // products + insta::assert_json_snapshot!(products.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###" + { + "uid": "products", + "primaryKey": "sku", + "createdAt": "[now]", + "updatedAt": "[now]" + } + "###); + + insta::assert_json_snapshot!(products.settings().unwrap()); + let documents = products.documents().unwrap().collect::>>().unwrap(); + assert_eq!(documents.len(), 10); + meili_snap::snapshot_hash!(format!("{:#?}", documents), @"b01c8371aea4c7171af0d4d846a2bdca"); + + // movies + insta::assert_json_snapshot!(movies.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###" + { + "uid": "movies", + "primaryKey": "id", + "createdAt": "[now]", + "updatedAt": "[now]" + } + "###); + + insta::assert_json_snapshot!(movies.settings().unwrap()); + let documents = movies.documents().unwrap().collect::>>().unwrap(); + assert_eq!(documents.len(), 10); + meili_snap::snapshot_hash!(format!("{:#?}", documents), @"b63dbed5bbc059f3e32bc471ae699bf5"); + + // spells + insta::assert_json_snapshot!(spells.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###" + { + "uid": "dnd_spells", + "primaryKey": "index", + "createdAt": "[now]", + "updatedAt": "[now]" + } + "###); + + insta::assert_json_snapshot!(spells.settings().unwrap()); + let documents = spells.documents().unwrap().collect::>>().unwrap(); + assert_eq!(documents.len(), 10); + meili_snap::snapshot_hash!(format!("{:#?}", documents), @"aa24c0cfc733d66c396237ad44263bed"); + } } diff --git a/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-10.snap b/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-10.snap new file mode 100644 index 000000000..d20fdc77e --- /dev/null +++ b/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-10.snap @@ -0,0 +1,27 @@ +--- +source: dump/src/reader/mod.rs +expression: movies.settings().unwrap() +--- +{ + "displayedAttributes": [ + "*" + ], + "searchableAttributes": [ + "*" + ], + "filterableAttributes": [ + "genres", + "id" + ], + "rankingRules": [ + "typo", + "words", + "proximity", + "attribute", + "exactness", + "release_date:asc" + ], + "stopWords": [], + "synonyms": {}, + "distinctAttribute": null +} diff --git a/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-11.snap b/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-11.snap new file mode 100644 index 000000000..997d303e7 --- /dev/null +++ b/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-11.snap @@ -0,0 +1,23 @@ +--- +source: dump/src/reader/mod.rs +expression: spells.settings().unwrap() +--- +{ + "displayedAttributes": [ + "*" + ], + "searchableAttributes": [ + "*" + ], + "filterableAttributes": [], + "rankingRules": [ + "typo", + "words", + "proximity", + "attribute", + "exactness" + ], + "stopWords": [], + "synonyms": {}, + "distinctAttribute": null +} diff --git a/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-14.snap b/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-14.snap new file mode 100644 index 000000000..997d303e7 --- /dev/null +++ b/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-14.snap @@ -0,0 +1,23 @@ +--- +source: dump/src/reader/mod.rs +expression: spells.settings().unwrap() +--- +{ + "displayedAttributes": [ + "*" + ], + "searchableAttributes": [ + "*" + ], + "filterableAttributes": [], + "rankingRules": [ + "typo", + "words", + "proximity", + "attribute", + "exactness" + ], + "stopWords": [], + "synonyms": {}, + "distinctAttribute": null +} diff --git a/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-5.snap b/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-5.snap new file mode 100644 index 000000000..282cd6ba7 --- /dev/null +++ b/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-5.snap @@ -0,0 +1,37 @@ +--- +source: dump/src/reader/mod.rs +expression: products.settings().unwrap() +--- +{ + "displayedAttributes": [ + "*" + ], + "searchableAttributes": [ + "*" + ], + "filterableAttributes": [], + "rankingRules": [ + "typo", + "words", + "proximity", + "attribute", + "exactness" + ], + "stopWords": [], + "synonyms": { + "android": [ + "phone", + "smartphone" + ], + "iphone": [ + "phone", + "smartphone" + ], + "phone": [ + "android", + "iphone", + "smartphone" + ] + }, + "distinctAttribute": null +} diff --git a/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-6.snap b/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-6.snap new file mode 100644 index 000000000..282cd6ba7 --- /dev/null +++ b/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-6.snap @@ -0,0 +1,37 @@ +--- +source: dump/src/reader/mod.rs +expression: products.settings().unwrap() +--- +{ + "displayedAttributes": [ + "*" + ], + "searchableAttributes": [ + "*" + ], + "filterableAttributes": [], + "rankingRules": [ + "typo", + "words", + "proximity", + "attribute", + "exactness" + ], + "stopWords": [], + "synonyms": { + "android": [ + "phone", + "smartphone" + ], + "iphone": [ + "phone", + "smartphone" + ], + "phone": [ + "android", + "iphone", + "smartphone" + ] + }, + "distinctAttribute": null +} diff --git a/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-8.snap b/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-8.snap new file mode 100644 index 000000000..d20fdc77e --- /dev/null +++ b/dump/src/reader/snapshots/dump__reader__test__import_dump_v1-8.snap @@ -0,0 +1,27 @@ +--- +source: dump/src/reader/mod.rs +expression: movies.settings().unwrap() +--- +{ + "displayedAttributes": [ + "*" + ], + "searchableAttributes": [ + "*" + ], + "filterableAttributes": [ + "genres", + "id" + ], + "rankingRules": [ + "typo", + "words", + "proximity", + "attribute", + "exactness", + "release_date:asc" + ], + "stopWords": [], + "synonyms": {}, + "distinctAttribute": null +}