about summary refs log tree commit diff stats
path: root/crates/rocie-server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rocie-server/tests')
-rw-r--r--crates/rocie-server/tests/_testenv/init.rs21
-rw-r--r--crates/rocie-server/tests/defaults/mod.rs48
-rw-r--r--crates/rocie-server/tests/recipies/mod.rs178
-rw-r--r--crates/rocie-server/tests/tests.rs1
-rw-r--r--crates/rocie-server/tests/users/mod.rs13
5 files changed, 218 insertions, 43 deletions
diff --git a/crates/rocie-server/tests/_testenv/init.rs b/crates/rocie-server/tests/_testenv/init.rs
index 4a169fe..758ca4e 100644
--- a/crates/rocie-server/tests/_testenv/init.rs
+++ b/crates/rocie-server/tests/_testenv/init.rs
@@ -21,7 +21,7 @@ use std::{
 
 use rocie_client::{
     apis::{api_set_no_auth_user_api::provision, configuration::Configuration},
-    models::UserStub,
+    models::{ProvisionInfo, UserStub},
 };
 
 use crate::{
@@ -116,10 +116,15 @@ impl TestEnv {
 
         request!(
             env,
-            provision(UserStub {
-                description: Some("Test user, used during test runs".to_string()),
-                name: "rocie".to_string(),
-                password: "server".to_string()
+            provision(ProvisionInfo {
+                user: UserStub {
+                    description: Some("Test user, used during test runs".to_string()),
+                    name: "rocie".to_string(),
+                    password: "server".to_string()
+                },
+                // Don't use any default units.
+                // Otherwise we would need to update the tests every time we add new ones.
+                use_defaults: false,
             })
         );
 
@@ -150,7 +155,11 @@ impl TestEnv {
                 let mut stdout = BufReader::new(child.stdout.as_mut().expect("Was captured"));
 
                 let mut port = String::new();
-                assert_ne!(stdout.read_line(&mut port).expect("Works"), 0);
+                assert_ne!(
+                    stdout.read_line(&mut port).expect("Works"),
+                    0,
+                    "We should have been able to read the one line, the server printed"
+                );
 
                 port.trim_end()
                     .parse()
diff --git a/crates/rocie-server/tests/defaults/mod.rs b/crates/rocie-server/tests/defaults/mod.rs
new file mode 100644
index 0000000..6a334b0
--- /dev/null
+++ b/crates/rocie-server/tests/defaults/mod.rs
@@ -0,0 +1,48 @@
+use rocie_client::{
+    apis::{api_get_auth_unit_api::units, api_set_no_auth_user_api::provision},
+    models::{ProvisionInfo, UserStub},
+};
+
+use crate::testenv::{TestEnv, init::function_name, log::request};
+
+#[tokio::test]
+async fn test_defaults_disabled() {
+    let env = TestEnv::new_no_login(function_name!());
+
+    request!(
+        env,
+        provision(ProvisionInfo {
+            user: UserStub {
+                description: None,
+                name: "James Richard Haynes".to_string(),
+                password: "hunter14".to_string()
+            },
+            use_defaults: false,
+        })
+    );
+
+    let default_units = request!(env, units());
+
+    assert_eq!(default_units, vec![]);
+}
+
+#[tokio::test]
+async fn test_defaults_all() {
+    let env = TestEnv::new_no_login(function_name!());
+
+    request!(
+        env,
+        provision(ProvisionInfo {
+            user: UserStub {
+                description: None,
+                name: "James Richard Haynes".to_string(),
+                password: "hunter14".to_string()
+            },
+            use_defaults: true,
+        })
+    );
+
+    let default_units = request!(env, units());
+
+    assert!(!default_units.is_empty());
+}
diff --git a/crates/rocie-server/tests/recipies/mod.rs b/crates/rocie-server/tests/recipies/mod.rs
index e59c3f6..15680f1 100644
--- a/crates/rocie-server/tests/recipies/mod.rs
+++ b/crates/rocie-server/tests/recipies/mod.rs
@@ -1,13 +1,14 @@
 use rocie_client::{
     apis::{
-        api_get_auth_recipe_api::recipe_by_id, api_set_auth_product_api::register_product,
+        api_get_auth_recipe_api::{recipe_by_id, recipe_by_name},
+        api_set_auth_product_api::register_product,
         api_set_auth_recipe_api::add_recipe,
         api_set_auth_unit_property_api::register_unit_property,
     },
     models::{
         Content, ContentOneOf, CooklangRecipe, Ingredient, IngredientOneOf1NotRegisteredProduct,
-        Item, ItemOneOf, ItemOneOf1, Metadata, NameAndUrl, ProductStub, RecipeStub, Section, Step,
-        UnitPropertyStub,
+        Item, ItemOneOf, ItemOneOf1, ItemOneOf1Ingredient, ItemOneOf3, ItemOneOfText, Metadata,
+        NameAndUrl, ProductStub, RecipeStub, Section, Step, UnitPropertyStub,
     },
 };
 
@@ -74,7 +75,28 @@ title: Curry
 }
 
 #[tokio::test]
-async fn test_recipe_ingredients() {
+async fn test_recipe_whitespace() {
+    let env = TestEnv::new(function_name!()).await;
+
+    let name = "      Curry  ".to_owned();
+
+    request!(
+        env,
+        add_recipe(RecipeStub {
+            content: " nothing really ".to_owned(),
+            name: name.clone(),
+            parent: None,
+        })
+    );
+
+    let output = request!(env, recipe_by_name(&name));
+
+    assert_eq!(output.name, name);
+}
+
+#[tokio::test]
+#[expect(clippy::too_many_lines)]
+async fn test_recipe_contents() {
     let env = TestEnv::new(function_name!()).await;
 
     let up = request!(
@@ -104,6 +126,8 @@ author: James Connor
 title: Curry
 ---
 Add @rice{} and @water{200%ml} to a pot.
+
+Now add @curry-spice{200%g} let rest for ~{20%min}.
 "
             .to_owned(),
             name: "Curry".to_owned(),
@@ -130,41 +154,131 @@ Add @rice{} and @water{200%ml} to a pot.
                     quantity: None,
                 }
             }),
+            Ingredient::IngredientOneOf1(rocie_client::models::IngredientOneOf1 {
+                not_registered_product: IngredientOneOf1NotRegisteredProduct {
+                    name: "curry-spice".to_owned(),
+                    quantity: None,
+                }
+            }),
         ]
     );
 
     assert_eq!(
         output.content.sections,
         vec![Section {
-            content: vec![Content::ContentOneOf(ContentOneOf {
-                value: Step {
-                    items: vec![
-                        Item::ItemOneOf(ItemOneOf {
-                            r#type: rocie_client::models::item_one_of::Type::Text,
-                            value: "Add ".to_owned()
-                        }),
-                        Item::ItemOneOf1(ItemOneOf1 {
-                            r#type: rocie_client::models::item_one_of_1::Type::Ingredient,
-                            index: 0
-                        }),
-                        Item::ItemOneOf(ItemOneOf {
-                            r#type: rocie_client::models::item_one_of::Type::Text,
-                            value: " and ".to_owned()
-                        }),
-                        Item::ItemOneOf1(ItemOneOf1 {
-                            r#type: rocie_client::models::item_one_of_1::Type::Ingredient,
-                            index: 1
-                        }),
-                        Item::ItemOneOf(ItemOneOf {
-                            r#type: rocie_client::models::item_one_of::Type::Text,
-                            value: " to a pot.".to_owned()
-                        })
-                    ],
-                    number: 1
-                },
-                r#type: rocie_client::models::content_one_of::Type::Step
-            })],
+            content: vec![
+                Content::ContentOneOf(ContentOneOf {
+                    step: Step {
+                        items: vec![
+                            Item::ItemOneOf(ItemOneOf {
+                                text: ItemOneOfText {
+                                    value: "Add ".to_owned()
+                                }
+                            }),
+                            Item::ItemOneOf1(ItemOneOf1 {
+                                ingredient: ItemOneOf1Ingredient { index: 0 }
+                            }),
+                            Item::ItemOneOf(ItemOneOf {
+                                text: ItemOneOfText {
+                                    value: " and ".to_owned()
+                                }
+                            }),
+                            Item::ItemOneOf1(ItemOneOf1 {
+                                ingredient: ItemOneOf1Ingredient { index: 1 }
+                            }),
+                            Item::ItemOneOf(ItemOneOf {
+                                text: ItemOneOfText {
+                                    value: " to a pot.".to_owned()
+                                }
+                            })
+                        ],
+                        number: 1
+                    }
+                }),
+                Content::ContentOneOf(ContentOneOf {
+                    step: Step {
+                        items: vec![
+                            Item::ItemOneOf(ItemOneOf {
+                                text: ItemOneOfText {
+                                    value: "Now add ".to_owned()
+                                }
+                            }),
+                            Item::ItemOneOf1(ItemOneOf1 {
+                                ingredient: ItemOneOf1Ingredient { index: 2 }
+                            }),
+                            Item::ItemOneOf(ItemOneOf {
+                                text: ItemOneOfText {
+                                    value: " let rest for ".to_owned()
+                                }
+                            }),
+                            Item::ItemOneOf3(ItemOneOf3 {
+                                timer: ItemOneOf1Ingredient { index: 0 }
+                            }),
+                            Item::ItemOneOf(ItemOneOf {
+                                text: ItemOneOfText {
+                                    value: ".".to_owned()
+                                }
+                            })
+                        ],
+                        number: 2
+                    }
+                })
+            ],
             name: None
         }]
     );
 }
+
+#[tokio::test]
+async fn test_recipe_full_parse() {
+    let env = TestEnv::new(function_name!()).await;
+
+    // Recipe source: https://cook.md/https://bbcgoodfood.com/recipes/easy-pancakes
+    let recipe_id = request!(
+        env,
+        add_recipe(RecipeStub {
+            content: "
+---
+title: Easy pancakes
+description: Learn how to make the perfect pancakes every time with our foolproof easy crêpe recipe – elaborate flip optional
+image: https://images.immediate.co.uk/production/volatile/sites/30/2020/08/recipe-image-legacy-id-1273477_8-ad36e3b.jpg?resize=440,400
+nutrition:
+  calories: 61 calories
+  fat: 2 grams fat
+  saturated fat: 1 grams saturated fat
+  carbohydrates: 7 grams carbohydrates
+  sugar: 1 grams sugar
+  protein: 3 grams protein
+  sodium: 0.1 milligram of sodium
+tags: Cassie Best, Cook school, Crepe, Crêpes, easy pancakes, Flip, Flipping, Good for you, healthy pancakes, How to make pancakes, Make ahead, Pancake day, Pancake filling, Shrove Tuesday, Skills, thin pancakes
+source: https://bbcgoodfood.com/recipes/easy-pancakes
+author: Cassie Best
+prep time: 10 minutes
+course: Breakfast, Brunch, Main course
+time required: 30 minutes
+cook time: 20 minutes
+servings: Makes 12
+cuisine: British
+diet: Vegetarian
+---
+
+Put @plain flour{100%g}, @eggs{2}(large), @milk{300%ml}, @sunflower oil{1%tbsp} and a pinch of @salt{} into a #bowl{} or large jug, then whisk to a smooth batter. This should be similar in consistency to single cream.
+
+Set aside for ~{30%minutes} to rest if you have time, or start cooking straight away.
+
+Set a #medium frying pan{} or #crêpe pan{} over a medium heat and carefully wipe it with some oiled kitchen paper.
+
+When hot, cook your pancakes for ~{1%minute} on each side until golden, using around half a ladleful of batter per pancake. Keep them warm in a low oven as you make the rest.
+
+Serve with @?lemon wedges{} (optional) and @?caster sugar{} (optional), or your favourite filling. Once cold, you can layer the pancakes between baking parchment, then wrap in cling film and freeze for up to two months.
+"
+            .to_owned(),
+            name: "Easy pancakes".to_owned(),
+            parent: None,
+        })
+    );
+
+    let output = request!(env, recipe_by_id(recipe_id));
+
+    assert_eq!(output.name, "Easy pancakes".to_owned());
+}
diff --git a/crates/rocie-server/tests/tests.rs b/crates/rocie-server/tests/tests.rs
index e788712..6222017 100644
--- a/crates/rocie-server/tests/tests.rs
+++ b/crates/rocie-server/tests/tests.rs
@@ -9,3 +9,4 @@ mod recipe_parents;
 mod recipies;
 mod units;
 mod users;
+mod defaults;
diff --git a/crates/rocie-server/tests/users/mod.rs b/crates/rocie-server/tests/users/mod.rs
index d381e8f..c7ba6f8 100644
--- a/crates/rocie-server/tests/users/mod.rs
+++ b/crates/rocie-server/tests/users/mod.rs
@@ -4,7 +4,7 @@ use rocie_client::{
         api_set_auth_user_api::register_user,
         api_set_no_auth_user_api::{login, logout, provision},
     },
-    models::{LoginInfo, UserStub},
+    models::{LoginInfo, ProvisionInfo, UserStub},
 };
 
 use crate::testenv::{TestEnv, init::function_name, log::request};
@@ -15,10 +15,13 @@ async fn test_provisioning() {
 
     let user_id = request!(
         env,
-        provision(UserStub {
-            description: None,
-            name: "James Richard Haynes".to_string(),
-            password: "hunter14".to_string()
+        provision(ProvisionInfo {
+            user: UserStub {
+                description: None,
+                name: "James Richard Haynes".to_string(),
+                password: "hunter14".to_string()
+            },
+            use_defaults: false,
         })
     );