-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abe26cb
commit cc95f7e
Showing
13 changed files
with
431 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use super::setup; | ||
use anyhow::Result; | ||
use reqwest::StatusCode; | ||
|
||
#[tokio::test] | ||
async fn can_get_me() -> Result<()> { | ||
let mut harness = setup::harness().await?; | ||
|
||
harness.authenticate("thomas").await?; | ||
|
||
let response = harness.get("/api/v1/auth/me").send().await?; | ||
|
||
assert_eq!(StatusCode::OK, response.status()); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use super::{requests, responses, setup}; | ||
use anyhow::Result; | ||
use reqwest::StatusCode; | ||
|
||
#[tokio::test] | ||
async fn cannot_get_unknown_recipe() -> Result<()> { | ||
let harness = setup::with_auth().await?; | ||
|
||
let random_id = uuid::Uuid::new_v4(); | ||
|
||
let response = harness | ||
.get(&format!("/api/v1/recipes/{random_id}")) | ||
.send() | ||
.await?; | ||
|
||
assert_eq!(StatusCode::NOT_FOUND, response.status()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn can_create_and_get_recipe() -> Result<()> { | ||
let harness = setup::with_auth().await?; | ||
|
||
let response = harness | ||
.post("/api/v1/recipes") | ||
.json(&requests::CreateRecipe { | ||
title: "Chicken Parm".into(), | ||
ingredients: "\ | ||
- One chicken\n\ | ||
- Parmesan cheese\ | ||
" | ||
.into(), | ||
instructions: "\ | ||
- Broil the chicken\n\ | ||
- Add the parmesan\ | ||
" | ||
.into(), | ||
notes: Some("Best served hot!".into()), | ||
}) | ||
.send() | ||
.await?; | ||
|
||
assert_eq!(StatusCode::OK, response.status()); | ||
let id = response.json::<responses::Id>().await?.data; | ||
|
||
// try to get recipe | ||
let response = harness.get(&format!("/api/v1/recipes/{id}")).send().await?; | ||
assert_eq!(StatusCode::OK, response.status()); | ||
|
||
let result = response.json::<responses::GetRecipe>().await?.data; | ||
|
||
assert_eq!("Chicken Parm", result.title); | ||
assert_eq!( | ||
vec![responses::Ingredients { | ||
title: None, | ||
ingredients: vec!["One chicken".into(), "Parmesan cheese".into()] | ||
}], | ||
result.ingredient_blocks | ||
); | ||
assert_eq!( | ||
vec![responses::Instructions { | ||
title: None, | ||
instructions: vec!["Broil the chicken".into(), "Add the parmesan".into()] | ||
}], | ||
result.instruction_blocks | ||
); | ||
assert_eq!(Some("Best served hot!".into()), result.notes); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize)] | ||
pub struct CreateRecipe { | ||
pub title: String, | ||
pub ingredients: String, | ||
pub instructions: String, | ||
pub notes: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
pub struct Data<T> { | ||
pub data: T, | ||
} | ||
|
||
pub type Id = Data<uuid::Uuid>; | ||
|
||
pub type GetRecipe = Data<Recipe>; | ||
|
||
#[derive(Debug, Deserialize, PartialEq, Eq)] | ||
pub struct Recipe { | ||
pub id: String, | ||
pub hash: String, | ||
pub title: String, | ||
pub ingredient_blocks: Vec<Ingredients>, | ||
pub instruction_blocks: Vec<Instructions>, | ||
pub notes: Option<String>, | ||
} | ||
|
||
#[derive(Debug, Deserialize, PartialEq, Eq)] | ||
pub struct Instructions { | ||
pub title: Option<String>, | ||
pub instructions: Vec<String>, | ||
} | ||
|
||
#[derive(Debug, Deserialize, PartialEq, Eq)] | ||
pub struct Ingredients { | ||
pub title: Option<String>, | ||
pub ingredients: Vec<String>, | ||
} |
Oops, something went wrong.