//! `verify_invariants()` over a graph where one `merge` declaration matches //! two members of the context it names and another matches none. use mizan_core as mizan; use mizan_core::graph_check::verify_invariants; use mizan_core::prelude::*; use mizan_core::RequestHandle; use serde::{Deserialize, Serialize}; #[derive(Mizan, Serialize, Deserialize, Debug, Clone)] pub struct Profile { pub user_id: i64, pub name: String, } #[derive(Mizan, Serialize, Deserialize, Debug, Clone)] pub struct Status { pub ok: bool, } #[mizan::context("user")] pub struct UserCtx; #[mizan::client(context = UserCtx)] pub async fn user_profile(_req: &RequestHandle<'_>, user_id: i64) -> Profile { Profile { user_id, name: format!("user-{user_id}"), } } /// Same output shape as `user_profile`. #[mizan::client(context = UserCtx)] pub async fn user_card(_req: &RequestHandle<'_>, user_id: i64) -> Profile { Profile { user_id, name: format!("card-{user_id}"), } } #[mizan::client(merge = UserCtx)] pub async fn rename_user(_req: &RequestHandle<'_>, user_id: i64, name: String) -> Profile { Profile { user_id, name } } /// No member of `user` returns this shape. #[mizan::client(merge = UserCtx)] pub async fn mark_seen(_req: &RequestHandle<'_>, user_id: i64) -> Status { Status { ok: user_id > 0 } } #[test] #[should_panic(expected = "Merge resolution needs exactly one match")] fn a_merge_matching_several_members_is_ambiguous() { verify_invariants(); } #[test] #[should_panic(expected = "user_card")] fn an_ambiguous_merge_names_every_candidate_member() { verify_invariants(); } #[test] #[should_panic(expected = "no member of that context has output type")] fn a_merge_matching_no_member_has_no_slot() { verify_invariants(); }