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.

2.0 KB
Raw Blame
use super::{build_contact_connections, build_notification_recipients};
use macro_user_id::user_id::MacroUserIdStr;
use uuid::Uuid;

fn id(s: &str) -> MacroUserIdStr<'static> {
    MacroUserIdStr::try_from(s.to_string()).expect("valid macro user id")
}

#[test]
fn fans_out_to_owner_and_every_delegated_primary() {
    let owner = id("macro|[email protected]");
    let primaries = vec![
        "macro|[email protected]".to_string(),
        "macro|[email protected]".to_string(),
    ];

    let recipients = build_notification_recipients(&owner, primaries);

    assert_eq!(recipients.len(), 3);
    assert!(recipients.contains(&owner));
    assert!(recipients.contains(&id("macro|[email protected]")));
    assert!(recipients.contains(&id("macro|[email protected]")));
}

#[test]
fn owner_only_when_no_delegates() {
    let owner = id("macro|[email protected]");
    let recipients = build_notification_recipients(&owner, vec![]);
    assert_eq!(recipients.len(), 1);
    assert!(recipients.contains(&owner));
}

#[test]
fn skips_primaries_that_fail_to_parse() {
    let owner = id("macro|[email protected]");
    let primaries = vec![
        "not-a-macro-id".to_string(),
        "macro|[email protected]".to_string(),
    ];

    let recipients = build_notification_recipients(&owner, primaries);

    assert_eq!(recipients.len(), 2);
    assert!(recipients.contains(&owner));
    assert!(recipients.contains(&id("macro|[email protected]")));
}

#[test]
fn contact_connections_skip_addresses_that_fail_to_parse() {
    let owner = id("macro|[email protected]");
    let emails = [
        "'[email protected]'",
        "[email protected]",
        ",[email protected]",
        "[email protected]",
    ];

    let connections = build_contact_connections(&owner, Uuid::nil(), emails);

    let contacts: Vec<_> = connections.iter().map(|c| c.second.clone()).collect();
    assert_eq!(
        contacts,
        vec![id("macro|[email protected]"), id("macro|[email protected]")]
    );
    assert!(connections.iter().all(|c| c.first == owner));
}