Skip to content

Commit

Permalink
Add email test
Browse files Browse the repository at this point in the history
  • Loading branch information
augustuswm committed Nov 16, 2024
1 parent 83815f9 commit a5b05e8
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions v-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,3 +761,54 @@ impl From<LinkRequestModel> for LinkRequest {
}
}
}

#[cfg(test)]
mod tests {
use std::collections::BTreeSet;

use chrono::Utc;
use newtype_uuid::TypedUuid;

use crate::{ApiUser, ApiUserContactEmail, ApiUserInfo, ApiUserProvider};

#[test]
fn test_user_owns_email() {
let api_user_id = TypedUuid::new_v4();
let user = ApiUserInfo {
user: ApiUser::<()> {
id: api_user_id,
permissions: Vec::new().into(),
groups: BTreeSet::default(),
created_at: Utc::now(),
updated_at: Utc::now(),
deleted_at: None,
},
email: Some(ApiUserContactEmail {
id: TypedUuid::new_v4(),
user_id: api_user_id,
email: "not-user@company".to_string(),
created_at: Utc::now(),
updated_at: Utc::now(),
deleted_at: None,
}),
providers: vec![ApiUserProvider {
id: TypedUuid::new_v4(),
user_id: api_user_id,
provider: "local".to_string(),
provider_id: "123".to_string(),
emails: vec!["user@company".to_string()],
display_names: vec![],
created_at: Utc::now(),
updated_at: Utc::now(),
deleted_at: None,
}],
};

// Users own email addresses defined by their providers
assert!(user.owns_email("user@company"));
assert!(!user.owns_email("user@company-two"));

// But they do not own emails defined by their email contact
assert!(!user.owns_email("not-user@company"));
}
}

0 comments on commit a5b05e8

Please sign in to comment.