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.

3.2 KB
Raw Blame
use crate::email::ReadEmailParts;

use super::*;

#[test]
fn it_should_parse() {
    let valid_emails = [
        "macro|[email protected]",
        "macro|[email protected]",
        "macro|###hello###[email protected]",
    ];
    let res: Result<Vec<_>, _> = valid_emails
        .iter()
        .copied()
        .map(MacroUserId::parse_from_str)
        .collect();
    res.unwrap();
}

#[test]
fn it_should_fail() {
    let invalid_emails = [
        "macro|[email protected] ",
        "macro| [email protected]",
        "macro|[email protected]\n",
        "macro|\n[email protected]",
        "macro|[email protected]",
        "macro|sean@@macro.com",
        "schmacro|[email protected]",
    ];
    invalid_emails
        .iter()
        .copied()
        .map(MacroUserId::parse_from_str)
        .for_each(|res| {
            res.unwrap_err();
        });
}

#[test]
fn email_works() {
    let id = MacroUserId::parse_from_str("macro|###hello###[email protected]")
        .unwrap();

    dbg!(&id);

    assert_eq!(
        id.email_part().email_str(),
        "###hello###[email protected]"
    );
}

#[test]
fn domain_part_works() {
    let id = MacroUserId::parse_from_str("macro|###hello###[email protected]")
        .unwrap();

    dbg!(&id);

    assert_eq!(
        id.email_part().domain_part(),
        "something-strange.world.tour"
    );
}

#[test]
fn local_part_works() {
    let id = MacroUserId::parse_from_str("macro|###hello###[email protected]")
        .unwrap();

    dbg!(&id);

    assert_eq!(id.email_part().local_part(), "###hello###+weird");
}

#[test]
fn casing_matters_for_prefix() {
    let _id = MacroUserId::parse_from_str("macRo|###hello###[email protected]")
        .unwrap_err();
}

#[test]
fn incomplete_input_does_not_panic() {
    assert!(MacroUserId::parse_from_str("").is_err());
    assert!(MacroUserId::parse_from_str("macro").is_err());
    assert!(MacroUserId::parse_from_str("macro|").is_err());
}

#[test]
fn casing_ignored_for_email() {
    let id = MacroUserId::parse_from_str("macro|###hello###[email protected]")
        .unwrap();

    assert_eq!(id.email_part().local_part(), "###hello###+WEIRD");
}

#[test]
fn debug_output_is_simple_string() {
    let id = MacroUserId::parse_from_str("macro|[email protected]").unwrap();
    assert_eq!(format!("{:?}", id), "macro|[email protected]");

    let id_str = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
    assert_eq!(format!("{:?}", id_str), "macro|[email protected]");
}

#[test]
fn macro_com_users_are_staff() {
    let id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
    assert!(id.is_macro_staff());
}

#[test]
fn macro_com_plus_aliases_are_staff() {
    let id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
    assert!(id.is_macro_staff());
}

#[test]
fn non_macro_domains_are_not_staff() {
    let id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
    assert!(!id.is_macro_staff());
}

#[test]
fn it_should_fail_this() {
    MacroUserIdStr::parse_from_str("macro|a'or$1=$1or'x'='[email protected]").unwrap_err();
}