mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 20:07:09 +02:00
fix tests
This commit is contained in:
parent
0cd8869349
commit
a56e8c1a0c
4 changed files with 17 additions and 9 deletions
|
@ -2,14 +2,14 @@ use actix_web::{http::StatusCode, test};
|
|||
use serde_json::Value;
|
||||
|
||||
use meilisearch_http::data::Data;
|
||||
use meilisearch_http::helpers::NormalizePath;
|
||||
use meilisearch_http::create_app;
|
||||
|
||||
pub struct Service(pub Data);
|
||||
|
||||
impl Service {
|
||||
pub async fn post(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
|
||||
let mut app =
|
||||
test::init_service(meilisearch_http::create_app(&self.0, true).wrap(NormalizePath)).await;
|
||||
test::init_service(create_app!(&self.0, true)).await;
|
||||
|
||||
let req = test::TestRequest::post()
|
||||
.uri(url.as_ref())
|
||||
|
@ -26,12 +26,12 @@ impl Service {
|
|||
/// Send a test post request from a text body, with a `content-type:application/json` header.
|
||||
pub async fn post_str(&self, url: impl AsRef<str>, body: impl AsRef<str>) -> (Value, StatusCode) {
|
||||
let mut app =
|
||||
test::init_service(meilisearch_http::create_app(&self.0, true).wrap(NormalizePath)).await;
|
||||
test::init_service(create_app!(&self.0, true)).await;
|
||||
|
||||
let req = test::TestRequest::post()
|
||||
.uri(url.as_ref())
|
||||
.set_payload(body.as_ref().to_string())
|
||||
.header("content-type", "application/json")
|
||||
.insert_header(("content-type", "application/json"))
|
||||
.to_request();
|
||||
let res = test::call_service(&mut app, req).await;
|
||||
let status_code = res.status();
|
||||
|
@ -43,7 +43,7 @@ impl Service {
|
|||
|
||||
pub async fn get(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
|
||||
let mut app =
|
||||
test::init_service(meilisearch_http::create_app(&self.0, true).wrap(NormalizePath)).await;
|
||||
test::init_service(create_app!(&self.0, true)).await;
|
||||
|
||||
let req = test::TestRequest::get().uri(url.as_ref()).to_request();
|
||||
let res = test::call_service(&mut app, req).await;
|
||||
|
@ -56,7 +56,7 @@ impl Service {
|
|||
|
||||
pub async fn put(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
|
||||
let mut app =
|
||||
test::init_service(meilisearch_http::create_app(&self.0, true).wrap(NormalizePath)).await;
|
||||
test::init_service(create_app!(&self.0, true)).await;
|
||||
|
||||
let req = test::TestRequest::put()
|
||||
.uri(url.as_ref())
|
||||
|
@ -72,7 +72,7 @@ impl Service {
|
|||
|
||||
pub async fn delete(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
|
||||
let mut app =
|
||||
test::init_service(meilisearch_http::create_app(&self.0, true).wrap(NormalizePath)).await;
|
||||
test::init_service(create_app!(&self.0, true)).await;
|
||||
|
||||
let req = test::TestRequest::delete().uri(url.as_ref()).to_request();
|
||||
let res = test::call_service(&mut app, req).await;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue