last review edits + fmt

This commit is contained in:
mpostma
2021-03-15 18:11:10 +01:00
parent c29b86849b
commit dd324807f9
46 changed files with 764 additions and 589 deletions

View File

@ -1,15 +1,14 @@
use actix_web::{http::StatusCode, test};
use serde_json::Value;
use meilisearch_http::data::Data;
use meilisearch_http::create_app;
use meilisearch_http::data::Data;
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(create_app!(&self.0, true)).await;
let mut app = test::init_service(create_app!(&self.0, true)).await;
let req = test::TestRequest::post()
.uri(url.as_ref())
@ -24,9 +23,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(create_app!(&self.0, true)).await;
pub async fn post_str(
&self,
url: impl AsRef<str>,
body: impl AsRef<str>,
) -> (Value, StatusCode) {
let mut app = test::init_service(create_app!(&self.0, true)).await;
let req = test::TestRequest::post()
.uri(url.as_ref())
@ -42,8 +44,7 @@ impl Service {
}
pub async fn get(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
let mut app =
test::init_service(create_app!(&self.0, true)).await;
let mut app = 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;
@ -55,8 +56,7 @@ impl Service {
}
pub async fn put(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
let mut app =
test::init_service(create_app!(&self.0, true)).await;
let mut app = test::init_service(create_app!(&self.0, true)).await;
let req = test::TestRequest::put()
.uri(url.as_ref())
@ -71,8 +71,7 @@ impl Service {
}
pub async fn delete(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
let mut app =
test::init_service(create_app!(&self.0, true)).await;
let mut app = 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;