Skip to content

Commit d863ea4

Browse files
Turbo87domodwyer
andauthored
test: generate per-user email (#9322)
When generating a test user, derive that user's email address from the username. This makes asserting the correct recipient emails are used when inspecting emails in tests. Co-authored-by: Dom Dwyer <[email protected]>
1 parent 47e9348 commit d863ea4

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

src/tests/krate/publish/basics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async fn new_krate() {
3434
.select(versions_published_by::email)
3535
.first(conn)
3636
.unwrap();
37-
assert_eq!(email, "something@example.com");
37+
assert_eq!(email, "foo@example.com");
3838
});
3939
}
4040

src/tests/routes/me/snapshots/all__routes__me__get__me-2.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
source: src/tests/routes/me/get.rs
3-
expression: response.into_json()
3+
expression: response.json()
44
---
55
{
66
"owned_crates": [],
77
"user": {
88
"avatar": null,
9-
"email": "something@example.com",
9+
"email": "foo@example.com",
1010
"email_verification_sent": true,
1111
"email_verified": true,
1212
"id": 1,

src/tests/routes/me/snapshots/all__routes__me__get__me-3.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: src/tests/routes/me/get.rs
3-
expression: response.into_json()
3+
expression: response.json()
44
---
55
{
66
"owned_crates": [
@@ -12,7 +12,7 @@ expression: response.into_json()
1212
],
1313
"user": {
1414
"avatar": null,
15-
"email": "something@example.com",
15+
"email": "foo@example.com",
1616
"email_verification_sent": true,
1717
"email_verified": true,
1818
"id": 1,

src/tests/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ async fn test_email_get_and_put() {
139139
let (_app, _anon, user) = TestApp::init().with_user();
140140

141141
let json = user.show_me().await;
142-
assert_eq!(json.user.email.unwrap(), "something@example.com");
142+
assert_eq!(json.user.email.unwrap(), "foo@example.com");
143143

144144
user.update_email("[email protected]").await;
145145

src/tests/util/test_app.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ impl TestApp {
113113
f(&mut self.0.test_database.connect())
114114
}
115115

116-
/// Create a new user with a verified email address in the database and return a mock user
117-
/// session
116+
/// Create a new user with a verified email address in the database
117+
/// (`<username>@example.com``) and return a mock user session.
118118
///
119119
/// This method updates the database directly
120120
pub fn db_new_user(&self, username: &str) -> MockCookieUser {
121121
use crates_io::schema::emails;
122122
use diesel::prelude::*;
123123

124124
let user = self.db(|conn| {
125-
let email = "something@example.com";
125+
let email = format!("{username}@example.com");
126126

127127
let user = crate::new_user(username)
128128
.create_or_update(None, &self.0.app.emails, conn)

0 commit comments

Comments
 (0)