Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

1.4 KB
Raw Blame
use super::*;

fn user(email: &str) -> MacroUserIdStr<'static> {
    MacroUserIdStr::try_from_email(email).unwrap()
}

#[test]
fn explicit_connections_are_a_separate_message_shape() {
    let connections = vec![ContactConnection::new(
        user("[email protected]"),
        user("[email protected]"),
    )];
    let serialized = serde_json::to_value(ContactConnections::new(connections.clone())).unwrap();

    assert!(serialized.get("users").is_none());
    assert_eq!(
        serde_json::from_value::<ContactConnections>(serialized)
            .unwrap()
            .connections,
        connections
    );
}

#[test]
fn consumer_deserializes_existing_nodes_message() {
    let message: ContactsMessage = serde_json::from_str(
        r#"{"users":["macro|[email protected]","macro|[email protected]"]}"#,
    )
    .unwrap();

    assert!(matches!(message, ContactsMessage::Nodes(_)));
}

#[test]
fn consumer_rejects_message_with_both_shapes() {
    let message = serde_json::from_str::<ContactsMessage>(
        r#"{"users":["macro|[email protected]"],"connections":[]}"#,
    );

    assert!(message.is_err());
}

#[test]
fn consumer_deserializes_explicit_connections_message() {
    let message: ContactsMessage = serde_json::from_str(
        r#"{"connections":[{"first":"macro|[email protected]","second":"macro|[email protected]"}]}"#,
    )
    .unwrap();

    assert!(matches!(message, ContactsMessage::Connections(_)));
}