Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/monetize

crates/monetize-server/tests/estate_kinds_per_product.rs

//! **A sold estate's boxes are its PRODUCT's** (2026-10-17; v2.0 P3): the lay gives each
//! machine the seed and the medium of the kind its product's lifecycle names for its role
//! (`medium_kind`), never a kind the core makes up from the product's name. It named them
//! "gunnar" for every product once, so a Holger estate's seed landed in `seed.gunnar.toml`.

use monetize_server::estate_order::{give_release_media_as, give_seeds_as, media_missing, plan_for_as, EstateOrderConfig, EstateSizes};
use monetize_server::testing::lifecycles::{gunnar as test_gunnar, holger as test_holger};

/// The Gunnar rules' plan for `c` (the native `plan_for` went in v2.0 P2 12.4).
fn plan_for(c: &EstateOrderConfig, company: &str, sizes: &EstateSizes, twin: &str) -> monetize_cloud::lay::EstatePlan {
    plan_for_as(c, company, sizes, twin, &test_gunnar())
}

#[test]
fn a_holger_estate_is_seeded_and_laid_as_holger() {
    // The shop's media check reads the product's lifecycle: the Holger-shaped TEST one (A28 H6).
    monetize_server::testing::lifecycles::install();
    let c = EstateOrderConfig { product: "holger".into(), pairing: "shop-pairing".into(), ..EstateOrderConfig::default() };
    let material = vec![("seed.front.toml".to_string(), "GF".to_string()), ("seed.holger-front.toml".to_string(), "F".to_string()), ("seed.holger.toml".to_string(), "H".to_string()), ("seed.gunnar.toml".to_string(), "G".to_string())];
    let mut plan = plan_for(&c, "acme", &EstateSizes::default(), "");
    give_seeds_as(&mut plan, &material, &test_holger());
    let by_role = |p: &monetize_cloud::lay::EstatePlan, r: &str| p.machines.iter().find(|m| m.role == r).map(|m| m.user_data.0.clone()).unwrap_or_default();
    assert_eq!((by_role(&plan, "front"), by_role(&plan, "main"), by_role(&plan, "twin")), ("F".into(), "H".into(), "H".into()));

    let mut gunnar = plan_for(&c, "acme", &EstateSizes::default(), "");
    give_seeds_as(&mut gunnar, &material, &test_gunnar());
    assert_eq!(by_role(&gunnar, "main"), "G", "gunnar's lay reads seed.gunnar.toml, as before");

    let media = [("front".to_string(), "front-uuid".to_string()), ("holger-front".to_string(), "holger-front-uuid".to_string()), ("holger".to_string(), "holger-uuid".to_string()), ("gunnar".to_string(), "gunnar-uuid".to_string())].into();
    give_release_media_as(&mut plan, &media, &Default::default(), &test_holger());
    let medium = |r: &str| plan.machines.iter().find(|m| m.role == r).map(|m| m.medium.clone()).unwrap_or_default();
    assert_eq!((medium("front"), medium("main"), medium("twin")), ("holger-front-uuid".into(), "holger-uuid".into(), "holger-uuid".into()));

    // The shop's media check asks for the product's medium.
    let why = media_missing(&EstateOrderConfig { media: [("holger-front".to_string(), "f".to_string()), ("gunnar".to_string(), "g".to_string())].into(), ..c.clone() }).expect("no holger medium");
    assert!(why.contains("holger") && !why.contains("holger-front"), "{why}");
    let why = media_missing(&EstateOrderConfig { media: [("front".to_string(), "f".to_string()), ("holger".to_string(), "h".to_string())].into(), ..c.clone() }).expect("Gunnar's front is no Holger front");
    assert!(why.contains("holger-front"), "{why}");
    assert!(media_missing(&EstateOrderConfig { media: [("holger-front".to_string(), "f".to_string()), ("holger".to_string(), "h".to_string())].into(), ..c }).is_none());
}