nblm_core/models/requests/
share.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, Default)]
4#[serde(rename_all = "camelCase")]
5pub struct ShareRequest {
6 pub account_and_roles: Vec<AccountRole>,
7}
8
9#[derive(Debug, Clone, Serialize, Deserialize, Default)]
10#[serde(rename_all = "camelCase")]
11pub struct AccountRole {
12 pub email: String,
13 pub role: ProjectRole,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize, Default)]
17#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
18pub enum ProjectRole {
19 ProjectRoleOwner,
20 ProjectRoleWriter,
21 #[default]
22 ProjectRoleReader,
23 ProjectRoleNotShared,
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 fn project_role_serializes_correctly() {
32 let owner = ProjectRole::ProjectRoleOwner;
33 let json = serde_json::to_string(&owner).unwrap();
34 assert_eq!(json, r#""PROJECT_ROLE_OWNER""#);
35
36 let writer = ProjectRole::ProjectRoleWriter;
37 let json = serde_json::to_string(&writer).unwrap();
38 assert_eq!(json, r#""PROJECT_ROLE_WRITER""#);
39
40 let reader = ProjectRole::ProjectRoleReader;
41 let json = serde_json::to_string(&reader).unwrap();
42 assert_eq!(json, r#""PROJECT_ROLE_READER""#);
43 }
44
45 #[test]
46 fn project_role_deserializes_correctly() {
47 let json = r#""PROJECT_ROLE_OWNER""#;
48 let role: ProjectRole = serde_json::from_str(json).unwrap();
49 assert!(matches!(role, ProjectRole::ProjectRoleOwner));
50
51 let json = r#""PROJECT_ROLE_READER""#;
52 let role: ProjectRole = serde_json::from_str(json).unwrap();
53 assert!(matches!(role, ProjectRole::ProjectRoleReader));
54 }
55
56 #[test]
57 fn share_request_serializes_correctly() {
58 let request = ShareRequest {
59 account_and_roles: vec![
60 AccountRole {
61 email: "user1@example.com".to_string(),
62 role: ProjectRole::ProjectRoleOwner,
63 },
64 AccountRole {
65 email: "user2@example.com".to_string(),
66 role: ProjectRole::ProjectRoleReader,
67 },
68 ],
69 };
70 let json = serde_json::to_string(&request).unwrap();
71 assert!(json.contains("accountAndRoles"));
72 assert!(json.contains("user1@example.com"));
73 assert!(json.contains("PROJECT_ROLE_OWNER"));
74 assert!(json.contains("user2@example.com"));
75 assert!(json.contains("PROJECT_ROLE_READER"));
76 }
77
78 #[test]
79 fn account_role_default_is_reader() {
80 let default_role = ProjectRole::default();
81 assert!(matches!(default_role, ProjectRole::ProjectRoleReader));
82 }
83}