Add a RON API to search recipes by title + a bit of refactoring
This commit is contained in:
parent
a3f61e3711
commit
084f7ef445
26 changed files with 499 additions and 333 deletions
|
|
@ -2,7 +2,7 @@ use std::{error::Error, sync::Arc};
|
|||
|
||||
use axum::http;
|
||||
use axum_test::TestServer;
|
||||
use common::ron_api;
|
||||
use common::web_api;
|
||||
use cookie::Cookie;
|
||||
use scraper::{ElementRef, Html, Selector};
|
||||
use serde::Serialize;
|
||||
|
|
@ -221,7 +221,13 @@ async fn sign_in() -> Result<(), Box<dyn Error>> {
|
|||
// Assert.
|
||||
response.assert_status_see_other(); // Redirection after successful sign in.
|
||||
response.assert_text("");
|
||||
response.assert_header("location", "/?user_message=16&user_message_icon=0");
|
||||
response.assert_header(
|
||||
"location",
|
||||
format!(
|
||||
"/?user_message={}&user_message_icon=0",
|
||||
common::translation::Sentence::SignInSuccess as i64
|
||||
),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -260,7 +266,7 @@ async fn create_recipe_and_edit_it() -> Result<(), Box<dyn Error>> {
|
|||
.patch(&format!("/ron-api/recipe/{recipe_id}/title"))
|
||||
.add_cookie(cookie.clone())
|
||||
.add_header(http::header::CONTENT_TYPE, common::consts::MIME_TYPE_RON)
|
||||
.bytes(ron_api::to_string("AAA").unwrap().into())
|
||||
.bytes(web_api::to_string("AAA").unwrap().into())
|
||||
.await;
|
||||
response.assert_status_ok();
|
||||
|
||||
|
|
@ -268,7 +274,7 @@ async fn create_recipe_and_edit_it() -> Result<(), Box<dyn Error>> {
|
|||
.patch(&format!("/ron-api/recipe/{recipe_id}/description"))
|
||||
.add_cookie(cookie.clone())
|
||||
.add_header(http::header::CONTENT_TYPE, common::consts::MIME_TYPE_RON)
|
||||
.bytes(ron_api::to_string("BBB").unwrap().into())
|
||||
.bytes(web_api::to_string("BBB").unwrap().into())
|
||||
.await;
|
||||
response.assert_status_ok();
|
||||
|
||||
|
|
@ -276,7 +282,7 @@ async fn create_recipe_and_edit_it() -> Result<(), Box<dyn Error>> {
|
|||
.patch(&format!("/ron-api/recipe/{recipe_id}/servings"))
|
||||
.add_cookie(cookie.clone())
|
||||
.add_header(http::header::CONTENT_TYPE, common::consts::MIME_TYPE_RON)
|
||||
.bytes(ron_api::to_string(Some(42)).unwrap().into())
|
||||
.bytes(web_api::to_string(Some(42)).unwrap().into())
|
||||
.await;
|
||||
response.assert_status_ok();
|
||||
|
||||
|
|
@ -284,7 +290,7 @@ async fn create_recipe_and_edit_it() -> Result<(), Box<dyn Error>> {
|
|||
.patch(&format!("/ron-api/recipe/{recipe_id}/estimated_time"))
|
||||
.add_cookie(cookie.clone())
|
||||
.add_header(http::header::CONTENT_TYPE, common::consts::MIME_TYPE_RON)
|
||||
.bytes(ron_api::to_string(Some(420)).unwrap().into())
|
||||
.bytes(web_api::to_string(Some(420)).unwrap().into())
|
||||
.await;
|
||||
response.assert_status_ok();
|
||||
|
||||
|
|
@ -293,7 +299,7 @@ async fn create_recipe_and_edit_it() -> Result<(), Box<dyn Error>> {
|
|||
.add_cookie(cookie.clone())
|
||||
.add_header(http::header::CONTENT_TYPE, common::consts::MIME_TYPE_RON)
|
||||
.bytes(
|
||||
ron_api::to_string(ron_api::Difficulty::Hard)
|
||||
web_api::to_string(web_api::Difficulty::Hard)
|
||||
.unwrap()
|
||||
.into(),
|
||||
)
|
||||
|
|
@ -304,7 +310,7 @@ async fn create_recipe_and_edit_it() -> Result<(), Box<dyn Error>> {
|
|||
.patch(&format!("/ron-api/recipe/{recipe_id}/language"))
|
||||
.add_cookie(cookie.clone())
|
||||
.add_header(http::header::CONTENT_TYPE, common::consts::MIME_TYPE_RON)
|
||||
.bytes(ron_api::to_string("fr").unwrap().into())
|
||||
.bytes(web_api::to_string("fr").unwrap().into())
|
||||
.await;
|
||||
response.assert_status_ok();
|
||||
|
||||
|
|
@ -312,7 +318,7 @@ async fn create_recipe_and_edit_it() -> Result<(), Box<dyn Error>> {
|
|||
.patch(&format!("/ron-api/recipe/{recipe_id}/is_public"))
|
||||
.add_cookie(cookie.clone())
|
||||
.add_header(http::header::CONTENT_TYPE, common::consts::MIME_TYPE_RON)
|
||||
.bytes(ron_api::to_string(true).unwrap().into())
|
||||
.bytes(web_api::to_string(true).unwrap().into())
|
||||
.await;
|
||||
response.assert_status_ok();
|
||||
|
||||
|
|
@ -399,7 +405,7 @@ async fn recipe_tags() -> Result<(), Box<dyn Error>> {
|
|||
.add_cookie(cookie.clone())
|
||||
.add_header(http::header::CONTENT_TYPE, common::consts::MIME_TYPE_RON)
|
||||
.bytes(
|
||||
ron_api::to_string(vec!["ABC".to_string(), "xyz".to_string()])
|
||||
web_api::to_string(vec!["ABC".to_string(), "xyz".to_string()])
|
||||
.unwrap()
|
||||
.into(),
|
||||
)
|
||||
|
|
@ -424,7 +430,7 @@ async fn recipe_tags() -> Result<(), Box<dyn Error>> {
|
|||
.add_cookie(cookie.clone())
|
||||
.add_header(http::header::CONTENT_TYPE, common::consts::MIME_TYPE_RON)
|
||||
.bytes(
|
||||
ron_api::to_string(vec!["XYZ".to_string(), "qwe".to_string()])
|
||||
web_api::to_string(vec!["XYZ".to_string(), "qwe".to_string()])
|
||||
.unwrap()
|
||||
.into(),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue