From 77c0a0fba5a4e3c917719c0f0b3fd24cf2aacf1d Mon Sep 17 00:00:00 2001 From: mpostma Date: Mon, 15 Mar 2021 10:36:12 +0100 Subject: [PATCH] add test get document displayed attributes --- meilisearch-http/src/index/mod.rs | 1 + .../tests/documents/get_documents.rs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/meilisearch-http/src/index/mod.rs b/meilisearch-http/src/index/mod.rs index 991746db3..fd5aa3004 100644 --- a/meilisearch-http/src/index/mod.rs +++ b/meilisearch-http/src/index/mod.rs @@ -114,6 +114,7 @@ impl Index { None => fields_ids_map.iter().map(|(id, _)| id).collect(), }, }; + let internal_id = self .external_documents_ids(&txn)? .get(doc_id.as_bytes()) diff --git a/meilisearch-http/tests/documents/get_documents.rs b/meilisearch-http/tests/documents/get_documents.rs index 5affb8a7a..c9ed83316 100644 --- a/meilisearch-http/tests/documents/get_documents.rs +++ b/meilisearch-http/tests/documents/get_documents.rs @@ -1,6 +1,8 @@ use crate::common::Server; use crate::common::GetAllDocumentsOptions; +use serde_json::json; + // TODO: partial test since we are testing error, amd error is not yet fully implemented in // transplant #[actix_rt::test] @@ -147,3 +149,22 @@ async fn test_get_all_documents_attributes_to_retrieve() { assert_eq!(response.as_array().unwrap().len(), 20); assert_eq!(response.as_array().unwrap()[0].as_object().unwrap().keys().count(), 2); } + +#[actix_rt::test] +async fn get_documents_displayed_attributes() { + let server = Server::new().await; + let index = server.index("test"); + index.update_settings(json!({"displayedAttributes": ["gender"]})).await; + index.load_test_set().await; + + let (response, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await; + assert_eq!(code, 200); + assert_eq!(response.as_array().unwrap().len(), 20); + assert_eq!(response.as_array().unwrap()[0].as_object().unwrap().keys().count(), 1); + assert!(response.as_array().unwrap()[0].as_object().unwrap().get("gender").is_some()); + + let (response, code) = index.get_document(0, None).await; + assert_eq!(code, 200); + assert_eq!(response.as_object().unwrap().keys().count(), 1); + assert!(response.as_object().unwrap().get("gender").is_some()); +}