mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 11:57:07 +02:00
makes the analytics available for all the routes
This commit is contained in:
parent
664d09e86a
commit
d72c887422
6 changed files with 69 additions and 21 deletions
|
@ -2,7 +2,7 @@ use actix_web::{http::StatusCode, test};
|
|||
use meilisearch_lib::MeiliSearch;
|
||||
use serde_json::Value;
|
||||
|
||||
use meilisearch_http::{create_app, Opt};
|
||||
use meilisearch_http::{analytics, create_app, Opt};
|
||||
|
||||
pub struct Service {
|
||||
pub meilisearch: MeiliSearch,
|
||||
|
@ -11,7 +11,13 @@ pub struct Service {
|
|||
|
||||
impl Service {
|
||||
pub async fn post(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
|
||||
let app = test::init_service(create_app!(&self.meilisearch, true, &self.options)).await;
|
||||
let app = test::init_service(create_app!(
|
||||
&self.meilisearch,
|
||||
true,
|
||||
&self.options,
|
||||
analytics::MockAnalytics::new(&self.options)
|
||||
))
|
||||
.await;
|
||||
|
||||
let req = test::TestRequest::post()
|
||||
.uri(url.as_ref())
|
||||
|
@ -31,7 +37,13 @@ impl Service {
|
|||
url: impl AsRef<str>,
|
||||
body: impl AsRef<str>,
|
||||
) -> (Value, StatusCode) {
|
||||
let app = test::init_service(create_app!(&self.meilisearch, true, &self.options)).await;
|
||||
let app = test::init_service(create_app!(
|
||||
&self.meilisearch,
|
||||
true,
|
||||
&self.options,
|
||||
analytics::MockAnalytics::new(&self.options)
|
||||
))
|
||||
.await;
|
||||
|
||||
let req = test::TestRequest::post()
|
||||
.uri(url.as_ref())
|
||||
|
@ -47,7 +59,13 @@ impl Service {
|
|||
}
|
||||
|
||||
pub async fn get(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
|
||||
let app = test::init_service(create_app!(&self.meilisearch, true, &self.options)).await;
|
||||
let app = test::init_service(create_app!(
|
||||
&self.meilisearch,
|
||||
true,
|
||||
&self.options,
|
||||
analytics::MockAnalytics::new(&self.options)
|
||||
))
|
||||
.await;
|
||||
|
||||
let req = test::TestRequest::get().uri(url.as_ref()).to_request();
|
||||
let res = test::call_service(&app, req).await;
|
||||
|
@ -59,7 +77,13 @@ impl Service {
|
|||
}
|
||||
|
||||
pub async fn put(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
|
||||
let app = test::init_service(create_app!(&self.meilisearch, true, &self.options)).await;
|
||||
let app = test::init_service(create_app!(
|
||||
&self.meilisearch,
|
||||
true,
|
||||
&self.options,
|
||||
analytics::MockAnalytics::new(&self.options)
|
||||
))
|
||||
.await;
|
||||
|
||||
let req = test::TestRequest::put()
|
||||
.uri(url.as_ref())
|
||||
|
@ -74,7 +98,13 @@ impl Service {
|
|||
}
|
||||
|
||||
pub async fn delete(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
|
||||
let app = test::init_service(create_app!(&self.meilisearch, true, &self.options)).await;
|
||||
let app = test::init_service(create_app!(
|
||||
&self.meilisearch,
|
||||
true,
|
||||
&self.options,
|
||||
analytics::MockAnalytics::new(&self.options)
|
||||
))
|
||||
.await;
|
||||
|
||||
let req = test::TestRequest::delete().uri(url.as_ref()).to_request();
|
||||
let res = test::call_service(&app, req).await;
|
||||
|
|
|
@ -4,7 +4,7 @@ mod common;
|
|||
|
||||
use crate::common::Server;
|
||||
use actix_web::test;
|
||||
use meilisearch_http::create_app;
|
||||
use meilisearch_http::{analytics, create_app};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
#[actix_rt::test]
|
||||
|
@ -40,7 +40,8 @@ async fn error_json_bad_content_type() {
|
|||
let app = test::init_service(create_app!(
|
||||
&server.service.meilisearch,
|
||||
true,
|
||||
&server.service.options
|
||||
&server.service.options,
|
||||
analytics::MockAnalytics::new(&server.service.options)
|
||||
))
|
||||
.await;
|
||||
for route in routes {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::common::{GetAllDocumentsOptions, Server};
|
||||
use actix_web::test;
|
||||
use chrono::DateTime;
|
||||
use meilisearch_http::create_app;
|
||||
use meilisearch_http::{analytics, create_app};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
/// This is the basic usage of our API and every other tests uses the content-type application/json
|
||||
|
@ -19,7 +19,8 @@ async fn add_documents_test_json_content_types() {
|
|||
let app = test::init_service(create_app!(
|
||||
&server.service.meilisearch,
|
||||
true,
|
||||
&server.service.options
|
||||
&server.service.options,
|
||||
analytics::MockAnalytics::new(&server.service.options)
|
||||
))
|
||||
.await;
|
||||
// post
|
||||
|
@ -63,7 +64,8 @@ async fn error_add_documents_test_bad_content_types() {
|
|||
let app = test::init_service(create_app!(
|
||||
&server.service.meilisearch,
|
||||
true,
|
||||
&server.service.options
|
||||
&server.service.options,
|
||||
analytics::MockAnalytics::new(&server.service.options)
|
||||
))
|
||||
.await;
|
||||
// post
|
||||
|
@ -129,7 +131,8 @@ async fn error_add_documents_test_no_content_type() {
|
|||
let app = test::init_service(create_app!(
|
||||
&server.service.meilisearch,
|
||||
true,
|
||||
&server.service.options
|
||||
&server.service.options,
|
||||
analytics::MockAnalytics::new(&server.service.options)
|
||||
))
|
||||
.await;
|
||||
// post
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue