about summary refs log tree commit diff stats
path: root/crates/rocie-server/tests/recipe_parents/register.rs
blob: f525ae9395ccdc6f3dad71eb78f9ff496f5fcc3d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// rocie - An enterprise grocery management system
//
// Copyright (C) 2026 Benedikt Peetz <benedikt.peetz@b-peetz.de>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of Rocie.
//
// You should have received a copy of the License along with this program.
// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.

use rocie_client::{
    apis::{
        api_get_auth_recipe_api::recipe_by_id, api_set_auth_recipe_api::add_recipe,
        api_set_auth_recipe_parent_api::register_recipe_parent,
    },
    models::{RecipeParentStub, RecipeStub},
};

use crate::testenv::{TestEnv, init::function_name, log::request};

#[tokio::test]
async fn test_recipe_parent_register_roundtrip() {
    let env = TestEnv::new(function_name!()).await;

    let parent_dairy = request!(
        env,
        register_recipe_parent(RecipeParentStub {
            description: Some("Dairy replacment recipes".to_owned()),
            name: "Dairy replacements".to_owned(),
            parent: None,
        })
    );
    let parent_dairy_milk = request!(
        env,
        register_recipe_parent(RecipeParentStub {
            description: Some("Milk replacment recipes".to_owned()),
            name: "Milk replacements".to_owned(),
            parent: Some(parent_dairy),
        })
    );

    let recipe_soy_milk = request!(
        env,
        add_recipe(RecipeStub {
            name: "Soy drink".to_owned(),
            parent: Some(parent_dairy_milk),
            content: "Mix soy and drink".to_owned()
        })
    );
    let recipe_oat_milk = request!(
        env,
        add_recipe(RecipeStub {
            name: "Oat drink".to_owned(),
            parent: Some(parent_dairy_milk),
            content: "Mix oat and drink".to_owned()
        })
    );

    let recipe_vegan_cheese = request!(
        env,
        add_recipe(RecipeStub {
            name: "Vegan cheese".to_owned(),
            parent: Some(parent_dairy),
            content: "Make cheese. Remove cheese".to_owned()
        })
    );

    for recipe in [recipe_soy_milk, recipe_oat_milk] {
        let recipe = request!(env, recipe_by_id(recipe));

        assert_eq!(recipe.parent, Some(parent_dairy_milk));
    }

    {
        let recipe = request!(env, recipe_by_id(recipe_vegan_cheese));

        assert_eq!(recipe.parent, Some(parent_dairy));
    }
}