1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
10#[serde(tag = "kind", rename_all = "lowercase")]
11pub enum Scope {
12 #[default]
13 Personal,
14 Team {
15 team_id: String,
16 },
17 Community {
18 pack_id: Option<String>,
19 },
20}
21
22#[cfg(test)]
23mod tests {
24 use super::*;
25
26 #[test]
27 fn default_is_personal() {
28 assert_eq!(Scope::default(), Scope::Personal);
29 }
30
31 #[test]
32 fn yaml_roundtrip_personal() {
33 let s = Scope::Personal;
34 let y = serde_yaml::to_string(&s).unwrap();
35 assert_eq!(y.trim(), "kind: personal");
36 let back: Scope = serde_yaml::from_str(&y).unwrap();
37 assert_eq!(back, s);
38 }
39
40 #[test]
41 fn yaml_roundtrip_team() {
42 let s = Scope::Team {
43 team_id: "ops".into(),
44 };
45 let y = serde_yaml::to_string(&s).unwrap();
46 let back: Scope = serde_yaml::from_str(&y).unwrap();
47 assert_eq!(back, s);
48 }
49
50 #[test]
51 fn yaml_roundtrip_community_with_pack() {
52 let s = Scope::Community {
53 pack_id: Some("security-best-practices".into()),
54 };
55 let y = serde_yaml::to_string(&s).unwrap();
56 let back: Scope = serde_yaml::from_str(&y).unwrap();
57 assert_eq!(back, s);
58 }
59
60 #[test]
61 fn yaml_roundtrip_community_no_pack() {
62 let s = Scope::Community { pack_id: None };
63 let y = serde_yaml::to_string(&s).unwrap();
64 let back: Scope = serde_yaml::from_str(&y).unwrap();
65 assert_eq!(back, s);
66 }
67}