//! `mint::served`: the receipt of a row a writer that keeps no receipts //! serves (the Worker's object) — its author is the stamp's, a live row is a //! create and a deleted one a plain retract; only a row the object holds //! erased (its tombstone says why, 23 Nov 2026) is a retract naming that erase. use std::collections::BTreeMap; use cotton_store::canonical; use cotton_store::mint::{served, Actor, JobName, ServedRow}; use cotton_store::protocol::types::OpKind; use serde_json::json; fn actor() -> Actor { Actor::job(JobName::named("object-sync").expect("a job name")) } #[test] fn a_live_row_is_a_create_of_the_stamps_author() { let fields = BTreeMap::from([("title".to_string(), json!("Water the plants"))]); let op = served("op-1".into(), "cotton_todos", "todo-1", "0001700000000000:0003:object", &actor(), ServedRow::Live(fields), None) .expect("a receipt"); assert_eq!((op.kind, op.device_id.as_str(), op.actor.as_str()), (OpKind::Upsert, "object", "job:object-sync")); let receipt = canonical::decode(op.receipt.as_bytes()).expect("canonical bytes"); assert_eq!((receipt.kind, receipt.author.as_str()), (canonical::Kind::Create, "object")); assert_eq!(receipt.fields["title"], json!("Water the plants")); } #[test] fn a_deleted_row_is_a_retract_that_erases_nothing() { let op = served("op-2".into(), "cotton_todos", "todo-1", "0001700000000001:0000:object", &actor(), ServedRow::Retracted, None) .expect("a receipt"); let receipt = canonical::decode(op.receipt.as_bytes()).expect("canonical bytes"); assert_eq!((op.kind, receipt.kind, receipt.erase, receipt.fields.len()), (OpKind::Delete, canonical::Kind::Retract, None, 0)); } #[test] fn a_stamp_that_names_no_author_is_refused() { assert!(served("op-3".into(), "cotton_todos", "todo-1", "0001700000000001:0000:", &actor(), ServedRow::Retracted, None).is_err()); } #[test] fn a_row_that_says_more_than_the_receipt_it_replaces_names_it() { let fields = BTreeMap::from([("title".to_string(), json!("Water the plants")), ("notes".to_string(), json!("the ferns"))]); let op = served("op-4".into(), "cotton_todos", "todo-1", "0001700000000000:0003:object", &actor(), ServedRow::Live(fields), Some("op-1")) .expect("a receipt"); let receipt = canonical::decode(op.receipt.as_bytes()).expect("canonical bytes"); assert_eq!(receipt.restamps.as_deref(), Some("op-1")); }