From 520d37983c74f22a88af53420011d60d4948137e Mon Sep 17 00:00:00 2001 From: mpostma Date: Tue, 6 Jul 2021 11:54:09 +0200 Subject: [PATCH] implement index search methods --- meilisearch-http/Cargo.toml | 2 +- meilisearch-http/tests/common/index.rs | 29 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index aa0f2a974..5931d8d06 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -97,7 +97,7 @@ actix-rt = "2.1.0" assert-json-diff = { branch = "master", git = "https://github.com/qdequele/assert-json-diff" } mockall = "0.9.1" paste = "1.0.5" -serde_url_params = "0.2.0" +serde_url_params = "0.2.1" tempdir = "0.3.7" urlencoding = "1.1.1" diff --git a/meilisearch-http/tests/common/index.rs b/meilisearch-http/tests/common/index.rs index 7d98d0733..021b11ec4 100644 --- a/meilisearch-http/tests/common/index.rs +++ b/meilisearch-http/tests/common/index.rs @@ -1,4 +1,4 @@ -use std::time::Duration; +use std::{panic::{UnwindSafe, catch_unwind, resume_unwind}, time::Duration}; use actix_web::http::StatusCode; use paste::paste; @@ -185,6 +185,33 @@ impl Index<'_> { self.service.get(url).await } + pub async fn search(&self, query: Value, test: impl Fn(Value, StatusCode) + UnwindSafe + Clone) { + let (response, code) = self.search_post(query.clone()).await; + let t = test.clone(); + if let Err(e) = catch_unwind(move || t(response, code)) { + eprintln!("Error with post search"); + resume_unwind(e); + + } + + let (response, code) = self.search_get(query).await; + if let Err(e) = catch_unwind(move || test(response, code)) { + eprintln!("Error with get search"); + resume_unwind(e); + } + } + + pub async fn search_post(&self, query: Value) -> (Value, StatusCode) { + let url = format!("/indexes/{}/search", self.uid); + self.service.post(url, query).await + } + + pub async fn search_get(&self, query: Value) -> (Value, StatusCode) { + let params = serde_url_params::to_string(&query).unwrap(); + let url = format!("/indexes/{}/search?{}", self.uid, params); + self.service.get(url).await + } + make_settings_test_routes!(distinct_attribute); }