use super::*;
use crate::catalog::{CatalogError, Granularity, ProductGroupCatalog, RetentionBasis};
#[test]
fn loads_all_embedded_manifests() {
let catalog = InstrumentCatalog::new();
assert_eq!(catalog.len(), catalog::EMBEDDED_COUNT);
}
#[test]
fn a_claim_to_have_a_text_is_backed_by_a_celex() {
for instrument in InstrumentCatalog::new().all() {
assert_eq!(
instrument.celex.is_some(),
instrument.status.has_citable_text(),
"instrument '{}' is {:?} but celex is {:?}",
instrument.id,
instrument.status,
instrument.celex
);
}
}
#[test]
fn acts_adopted_under_a_framework_carry_a_parent() {
for instrument in InstrumentCatalog::new().all() {
let expects_parent = matches!(
instrument.kind,
InstrumentKind::Delegated | InstrumentKind::Implementing
);
assert_eq!(
instrument.parent.is_some(),
expects_parent,
"instrument '{}' kind {:?} parent {:?}",
instrument.id,
instrument.kind,
instrument.parent
);
}
}
#[test]
fn an_act_may_reach_a_product_group_that_has_no_manifest() {
let instruments = InstrumentCatalog::new();
let product_groups = ProductGroupCatalog::new();
let unmodelled: Vec<&str> = instruments
.product_group_keys()
.into_iter()
.filter(|key| product_groups.get(key).is_none())
.collect();
assert!(
unmodelled.contains(&"lmt"),
"expected light means of transport to be reached without a manifest, got {unmodelled:?}"
);
assert!(
instruments
.bindings_for("lmt")
.iter()
.all(|(_, b)| !b.allows_determination()),
"a product group we do not model must not be determinable"
);
}
#[test]
fn determinability_and_passport_duty_are_independent() {
let catalog = InstrumentCatalog::new();
assert!(
!catalog.determinable_for("electronics").is_empty(),
"electronics ecodesign obligations bind today"
);
assert!(
!catalog.passport_required_for("electronics"),
"no passport obligation exists for electronics"
);
assert!(!catalog.determinable_for("unsold-goods").is_empty());
assert!(!catalog.passport_required_for("unsold-goods"));
assert!(!catalog.determinable_for("battery").is_empty());
assert!(catalog.passport_required_for("battery"));
let due = catalog.passport_due_for("battery").expect("a fixed date");
assert_eq!(due.date, "2027-02-18");
assert_eq!(due.basis, DateBasis::Sourced);
assert!(catalog.determinable_for("toy").is_empty());
assert!(catalog.passport_required_for("toy"));
}
#[test]
fn a_displaced_passport_is_never_reported_as_required() {
let catalog = InstrumentCatalog::new();
let instrument = catalog
.get("ecodesign-energy-labelling-mobile")
.expect("embedded");
assert!(matches!(
instrument.passport_for("electronics"),
Some(PassportObligation::DisplacedBy { .. })
));
assert!(!instrument.requires_passport_for("electronics"));
assert!(
instrument
.binding("electronics")
.expect("bound")
.allows_determination(),
"the ecodesign obligations themselves are live and must stay determinable"
);
}
#[test]
fn retention_folds_to_the_maximum_and_assumption_is_contagious() {
let catalog = InstrumentCatalog::new();
assert_eq!(
catalog.retention_for("battery"),
Some((10, RetentionBasis::Assumed))
);
assert_eq!(
catalog.retention_for("toy"),
Some((10, RetentionBasis::Sourced))
);
assert_eq!(
catalog.retention_for("textile"),
Some((10, RetentionBasis::Assumed))
);
assert_eq!(catalog.retention_for("packaging"), None);
}
#[test]
fn granularity_is_unset_because_no_act_has_fixed_one() {
let catalog = InstrumentCatalog::new();
for key in catalog.product_group_keys() {
assert_eq!(
catalog.granularity_for(key),
None,
"product group '{key}' should have no act-fixed granularity yet"
);
}
}
#[test]
fn most_granular_wins_when_two_acts_disagree() {
assert_eq!(
Granularity::Model.most_granular(Granularity::Item),
Granularity::Item
);
assert_eq!(
Granularity::Item.most_granular(Granularity::Batch),
Granularity::Item
);
}
#[test]
fn an_instrument_id_cannot_be_registered_twice() {
let mut catalog = InstrumentCatalog::new();
let duplicate = catalog.get("espr").expect("embedded").clone();
assert_eq!(
catalog.register(duplicate),
Err(CatalogError::AlreadyExists("espr".to_owned()))
);
}
#[test]
fn every_passport_date_comes_from_an_act_that_requires_a_passport() {
let instruments = InstrumentCatalog::new();
for instrument in instruments.all() {
for binding in &instrument.product_groups {
let obligation = binding.passport.as_ref().unwrap_or(&instrument.passport);
if let Some(date) = obligation.applies_from() {
assert!(
obligation.is_required(),
"'{}' under '{}' carries the date {} on an obligation that is not Required",
binding.product_group,
instrument.id,
date.date
);
assert!(
instrument.status.has_citable_text(),
"'{}' fixes a date with no citable text",
instrument.id
);
}
}
}
for key in ["electronics", "unsold-goods"] {
assert!(!instruments.determinable_for(key).is_empty(), "{key} binds");
assert!(
!instruments.passport_required_for(key),
"{key} has no passport obligation under any recorded act"
);
assert!(instruments.passport_due_for(key).is_none(), "{key}");
}
}