Skip to content

Commit e97e93b

Browse files
committed
test: assert crate email invite emails are sent
Adds assertions to verify the existing "you've been invited as an owner" notification emails are sent to invitees.
1 parent b397f42 commit e97e93b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/tests/owners.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ async fn new_crate_owner() {
136136
let user2 = app.db_new_user("Bar");
137137
token.add_named_owner("foo_owner", "BAR").await.good();
138138

139+
// Validate a "new co-owner invite" notification email was sent.
140+
assert!(app.is_email_sent("[email protected]", "Crate ownership invitation"));
139141
// accept invitation for user to be added as owner
140142
let krate: Crate = app.db(|conn| Crate::by_name("foo_owner").first(conn).unwrap());
141143
user2
@@ -165,6 +167,13 @@ async fn create_and_add_owner(
165167
) -> MockCookieUser {
166168
let user = app.db_new_user(username);
167169
token.add_named_owner(&krate.name, username).await.good();
170+
171+
// Validate an invite notification email was sent.
172+
assert!(app.is_email_sent(
173+
&format!("{username}@example.com"),
174+
"Crate ownership invitation"
175+
));
176+
168177
user.accept_ownership_invitation(&krate.name, krate.id)
169178
.await;
170179
user
@@ -262,6 +271,9 @@ async fn modify_multiple_owners() {
262271
let response = token
263272
.add_named_owners("owners_multiple", &["user2", "user3"])
264273
.await;
274+
275+
assert!(app.is_email_sent("[email protected]", "Crate ownership invitation"));
276+
assert!(app.is_email_sent("[email protected]", "Crate ownership invitation"));
265277
assert_eq!(response.status(), StatusCode::OK);
266278
assert_eq!(
267279
response.json(),
@@ -498,6 +510,7 @@ async fn test_accept_invitation() {
498510
.await
499511
.good();
500512

513+
assert!(app.is_email_sent("[email protected]", "Crate ownership invitation"));
501514
// New owner accepts the invitation
502515
invited_user
503516
.accept_ownership_invitation(&krate.name, krate.id)

src/tests/routes/crates/owners/add.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ async fn invite_already_invited_user() {
259259

260260
// Check one email was sent, this will be the ownership invite email
261261
assert_eq!(app.as_inner().emails.mails_in_memory().unwrap().len(), 1);
262+
assert!(app.is_email_sent("[email protected]", "Crate ownership invitation"));
262263

263264
// Then invite the user a second time, the message should point out the user is already invited
264265
let response = owner.add_named_owner("crate_name", "invited_user").await;
@@ -298,6 +299,7 @@ async fn invite_with_existing_expired_invite() {
298299

299300
// Check one email was sent, this will be the ownership invite email
300301
assert_eq!(app.as_inner().emails.mails_in_memory().unwrap().len(), 1);
302+
assert!(app.is_email_sent("[email protected]", "Crate ownership invitation"));
301303

302304
// Simulate the previous invite expiring
303305
expire_invitation(&app, krate.id);
@@ -315,6 +317,7 @@ async fn invite_with_existing_expired_invite() {
315317

316318
// Check that the email for the second invite was sent
317319
assert_eq!(app.as_inner().emails.mails_in_memory().unwrap().len(), 2);
320+
assert!(app.is_email_sent("[email protected]", "Crate ownership invitation"));
318321
}
319322

320323
#[tokio::test(flavor = "multi_thread")]

0 commit comments

Comments
 (0)