use super::*; // RULE: the link names the app's scheme, the person and the call's kind, and reads back. #[test] fn a_link_is_built_and_read() { let url = build(&["6f1c2b1e-0000-4000-8000-000000000001"], true, false); assert_eq!(url, "cottoncalling://call?person=6f1c2b1e-0000-4000-8000-000000000001&video=1"); assert_eq!(parse(&url), Some(CallLink { people: vec!["6f1c2b1e-0000-4000-8000-000000000001".into()], video: true, dev: false })); let dev = build(&["p 1/x"], false, true); assert_eq!(dev, "cottoncallingdev://call?person=p%201%2Fx&video=0"); assert_eq!(parse(&dev).unwrap().people, ["p 1/x"]); } // RULE: audio is the default; unknown parameters are ignored. #[test] fn audio_by_default() { assert_eq!(parse("cottoncalling://call?person=p-1"), Some(CallLink { people: vec!["p-1".into()], video: false, dev: false })); assert_eq!(parse("CottonCalling://call/?utm=x&person=p-1&video=0").unwrap().people, ["p-1"]); } // RULE: anything else is not a call link: another scheme or host, no person, a video that is not 0 or 1, a repeated field, bad escapes. #[test] fn not_a_call_link() { for url in [ "https://call?person=p-1", "cottoncalling://chat?person=p-1", "cottoncalling://call?video=1", "cottoncalling://call?person=&video=1", "cottoncalling://call?person=p-1&video=yes", "cottoncalling://call?person=%zz", "cottoncalling:call?person=p-1", ] { assert_eq!(parse(url), None, "{url}"); } } // RULE: a group link repeats person: each once, in order; more than eight is not a call link. #[test] fn a_group_link() { let url = build(&["p-1", "p-2", "p-3"], true, false); assert_eq!(url, "cottoncalling://call?person=p-1&person=p-2&person=p-3&video=1"); assert_eq!(parse(&url).unwrap().people, ["p-1", "p-2", "p-3"]); assert_eq!(parse("cottoncalling://call?person=p-1&person=p-1").unwrap().people, ["p-1"]); let nine: String = (1..=9).map(|n| format!("person=p-{n}&")).collect(); assert_eq!(parse(&format!("cottoncalling://call?{nine}video=0")), None); assert_eq!(parse("cottoncalling://call?person=p-1&video=1&video=0"), None); }