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/src/estate_order/tests/one_lay_root.rs

//! ★ **A33-5: an operator site and a sold estate differ in DATA alone** (owner 2026-10-26: ONE
//! lay implementation that every path calls). Who pays is the order's kind ([`OrderedBy`]) and
//! nothing else: whether an order lays a declared site's ROOT (its apex's own names, its DNS
//! taken over, its cap met before it is paid) is the order's data, read in one place, and the
//! operator's EUR 0.50 is a price its terms hold, never a branch at the quote or at the lay.

use super::*;

/// The order's start and its lay, and the operator-site order: the code alone (the tests are
/// their own files).
const ORDER_SRC: &str = include_str!("../../estate_order.rs");
const SITE_SRC: &str = include_str!("../site.rs");

/// ★ **Who pays never decides what is laid, or what it costs**: no site order is a payer kind,
/// the root is never read off the payer, and neither the quote nor the lay's recheck branches
/// on the operator's buy (its price is the terms' data).
#[test]
fn who_pays_never_decides_what_is_laid_or_what_it_costs() {
    for (file, src) in [
        ("estate_order.rs", ORDER_SRC),
        ("estate_order/site.rs", SITE_SRC),
    ] {
        for kind in [
            "OrderedBy::Site",
            "matches!(by, OrderedBy::Site",
            "site_order: matches!(by",
        ] {
            assert!(
                !src.contains(kind),
                "{file} reads what is laid off who pays: `{kind}`"
            );
        }
        for branch in [
            "if run.operator_test {",
            "= if operator_test {",
            "operator_quote(",
            "at_operator_price)",
            "price::live_price(cfg, cloud, &plan)",
        ] {
            assert!(!src.contains(branch), "{file} branches on the operator's buy instead of pricing it from its terms: `{branch}`");
        }
    }
}

/// ★ **The operator's site order and the operator's own sold estate on that site go ONE way**:
/// the same start, the same EUR 0.50 through the site's own vendor, the same job and the same
/// lay. What differs is the root, data on the run: the site's own label laid under the apex's
/// own names, against a name under the apex.
#[test]
fn an_operator_site_and_a_sold_estate_are_laid_by_one_path_and_differ_in_the_root_alone() {
    let (state, pay, cloud, kit, dir, _clock) = site_rig("one-lay-root");
    *kit.ticket_key.lock().unwrap() = a_ticket_key();
    let root = site::start_site(
        &state,
        "gunnar-rs",
        "ops@example.invalid",
        &EstateSizes::default(),
    )
    .expect("the site order is taken");
    let sold = start_on(
        &state,
        Some("gunnar-rs"),
        "opa",
        "ops@example.invalid",
        "",
        "ignalina",
        &EstateSizes::default(),
    )
    .expect("the operator's own buy is taken");
    for run in [&root, &sold] {
        assert_eq!(
            (run.amount, run.operator_test, run.test),
            (FIFTY_CENTS, true, false),
            "the operator pays 0.50 for either: {run:?}"
        );
        assert_eq!(
            run.handle.as_ref().map(|h| h.vendor.as_str()),
            Some("holdpay"),
            "through the site's own vendor"
        );
        assert!(
            run.checkout_url.starts_with("https://pay.example/"),
            "at the vendor's page: {run:?}"
        );
        assert_eq!(
            (run.estate.as_str(), run.account.as_str()),
            ("gunnar-rs", "ignalina")
        );
    }
    assert_eq!(
        root.quote.sizes, sold.quote.sizes,
        "the same machines for the same order"
    );
    assert_eq!(root.quote.machines.len(), sold.quote.machines.len());
    // The one difference: the root, as data.
    assert!(
        root.site_order && !sold.site_order,
        "the root is the run's data"
    );
    for run in [&root, &sold] {
        pay.authorize(&run.handle.clone().unwrap().id);
        drive(&state, &run.company);
    }
    let (root, sold) = (
        state.estates.get("gunnarrs").unwrap(),
        state.estates.get("opa").unwrap(),
    );
    assert_eq!(
        phases(&root),
        phases(&sold),
        "the same job: {:#?} / {:#?}",
        root.history,
        sold.history
    );
    assert_eq!(
        phases(&sold),
        vec![
            "ordered",
            "held",
            "laying",
            "installing",
            "paired",
            "captured"
        ],
        "{:#?}",
        sold.history
    );
    assert_eq!(
        cloud.lays(),
        vec!["estate/gunnarrs".to_string(), "estate/opa".to_string()],
        "the same lay"
    );
    assert_eq!(pay.captures(), 2);
    let dns: Vec<String> = FileDns(dir.join("dns.json"))
        .listed()
        .unwrap()
        .into_iter()
        .map(|d| d.name)
        .collect();
    for name in [
        "gunnar.rs",
        "www.gunnar.rs",
        "git.gunnar.rs",
        "opa.gunnar.rs",
        "www.opa.gunnar.rs",
        "git.opa.gunnar.rs",
    ] {
        assert!(dns.contains(&name.to_string()), "{name} written: {dns:?}");
    }
}

/// ★ **The root is ONE data field of the ONE start**: [`start_order`] lays a declared operator
/// sites root for its admin, under the sites own label, and a name under the apex for the
/// same payer with the field empty. A root for anyone else, under another name or of a site
/// that is not the operator's own is refused by name before anything is held.
#[test]
fn a_root_is_one_field_of_the_one_start_and_only_the_declared_sites_own() {
    let (state, pay, ..) = site_rig("one-lay-root-field");
    let by = OrderedBy::Operator {
        back_to: String::new(),
        test_payer: String::new(),
    };
    for (estate, company, account) in [
        ("gunnar-rs", "gunnarrs", "nina"),
        ("gunnar-rs", "opa", "ignalina"),
        ("kunde-se", "kundese", "kunde"),
        ("nobody-rs", "nobodyrs", "ignalina"),
    ] {
        let r = start_order(
            &state,
            &LayAt::root_of(estate, ""),
            company,
            "ops@example.invalid",
            "",
            account,
            &EstateSizes::default(),
            &by,
        );
        assert!(
            matches!(r, Err(StartRefusal::NotSold(_))),
            "{estate}/{company}/{account}: {r:?}"
        );
    }
    assert!(
        pay.0.requests.lock().unwrap().is_empty(),
        "nothing held for a refused root"
    );
    let root = start_order(
        &state,
        &LayAt::root_of("gunnar-rs", ""),
        "gunnarrs",
        "ops@example.invalid",
        "",
        "ignalina",
        &EstateSizes::default(),
        &by,
    )
    .expect("the root");
    let sold = start_order(
        &state,
        &LayAt::on(Some("gunnar-rs")),
        "opa",
        "ops@example.invalid",
        "",
        "ignalina",
        &EstateSizes::default(),
        &by,
    )
    .expect("a name under it");
    assert!(root.site_order && !sold.site_order);
    assert_eq!(
        (root.amount, sold.amount),
        (FIFTY_CENTS, FIFTY_CENTS),
        "who pays sets the price, for either"
    );
    let base = state.estates.cfg.as_ref().unwrap();
    let host = |run: &EstateRun| terms_of(&state, base, run).unwrap().host_of(&run.company);
    assert_eq!(
        (host(&root).as_str(), host(&sold).as_str()),
        ("gunnar.rs", "opa.gunnar.rs"),
        "the root is the apex itself"
    );
}