use super::derivation::{DerivationRef, SecondLifeOperation};
use super::reference::PassportRef;
use crate::transfer::TransferReason;
#[test]
fn all_lists_every_variant() {
for operation in SecondLifeOperation::ALL {
match operation {
SecondLifeOperation::PreparationForReuse
| SecondLifeOperation::PreparationForRepurposing
| SecondLifeOperation::Repurposing
| SecondLifeOperation::Remanufacturing => {}
}
}
assert_eq!(
SecondLifeOperation::ALL.len(),
4,
"a variant was added to the match above but not to ALL"
);
}
#[test]
fn wire_vocabulary_agrees_with_transfer_reason() {
let pairs = [
(
SecondLifeOperation::PreparationForReuse,
TransferReason::PreparationForReuse,
),
(
SecondLifeOperation::PreparationForRepurposing,
TransferReason::PreparationForRepurposing,
),
(
SecondLifeOperation::Repurposing,
TransferReason::Repurposing,
),
(
SecondLifeOperation::Remanufacturing,
TransferReason::Remanufacturing,
),
];
assert_eq!(
pairs.len(),
SecondLifeOperation::ALL.len(),
"every operation needs a TransferReason counterpart in this table"
);
for (operation, reason) in &pairs {
assert_eq!(
operation.wire_str(),
reason.wire_str(),
"{operation:?} and its TransferReason counterpart must agree on the wire"
);
}
}
#[test]
fn serde_form_matches_wire_str() {
for operation in SecondLifeOperation::ALL {
let json = serde_json::to_string(operation).expect("operation serialises");
assert_eq!(
json,
format!("\"{}\"", operation.wire_str()),
"serde and wire_str disagree for {operation:?}"
);
}
}
#[test]
fn derivation_ref_round_trips() {
let edge = DerivationRef {
reference: PassportRef {
uri: "https://example.test/dpp/abc".into(),
public_jws_hash: "a".repeat(64),
},
operation: SecondLifeOperation::PreparationForRepurposing,
};
let json = serde_json::to_value(&edge).expect("edge serialises");
assert_eq!(
json["operation"], "preparationForRepurposing",
"the operation must survive as its wire form"
);
assert_eq!(
json["reference"]["publicJwsHash"],
"a".repeat(64),
"the wrapped reference keeps its own camelCase shape"
);
let back: DerivationRef = serde_json::from_value(json).expect("edge deserialises");
assert_eq!(back, edge);
}