Skip to content

Commit 58d9247

Browse files
committed
Add a verified email address to all test users
Then manually remove or edit the email record if we're specifically testing a user without a verified email address.
1 parent 83b6f6c commit 58d9247

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

src/tests/krate.rs

+8-23
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,10 @@ fn new_krate_with_readme() {
10791079
fn new_krate_without_any_email_warns() {
10801080
let (app, _, _, token) = TestApp::with_proxy().with_token();
10811081

1082+
app.db(|conn| {
1083+
delete(emails::table).execute(conn).unwrap();
1084+
});
1085+
10821086
let crate_to_publish = PublishBuilder::new("foo_no_email");
10831087

10841088
let json = token.publish(crate_to_publish).good();
@@ -1100,15 +1104,11 @@ fn new_krate_without_any_email_warns() {
11001104
// See https://github.com/rust-lang/crates-io-cargo-teams/issues/8
11011105
#[test]
11021106
fn new_krate_with_unverified_email_warns() {
1103-
let (app, _, user, token) = TestApp::with_proxy().with_token();
1104-
let user = user.as_model();
1107+
let (app, _, _, token) = TestApp::with_proxy().with_token();
11051108

11061109
app.db(|conn| {
1107-
insert_into(emails::table)
1108-
.values((
1109-
emails::user_id.eq(user.id),
1110-
emails::email.eq("[email protected]"),
1111-
))
1110+
update(emails::table)
1111+
.set((emails::verified.eq(false),))
11121112
.execute(conn)
11131113
.unwrap();
11141114
});
@@ -1132,22 +1132,7 @@ fn new_krate_with_unverified_email_warns() {
11321132

11331133
#[test]
11341134
fn new_krate_with_verified_email_doesnt_warn() {
1135-
let (app, _, user, token) = TestApp::with_proxy().with_token();
1136-
let user = user.as_model();
1137-
1138-
// TODO: Move this to TestApp setup for user so we don't have to do this for every test
1139-
// that publishes a crate; then edit the test for the user without a verified email to
1140-
// remove the verified email
1141-
app.db(|conn| {
1142-
insert_into(emails::table)
1143-
.values((
1144-
emails::user_id.eq(user.id),
1145-
emails::email.eq("[email protected]"),
1146-
emails::verified.eq(true),
1147-
))
1148-
.execute(conn)
1149-
.unwrap();
1150-
});
1135+
let (app, _, _, token) = TestApp::with_proxy().with_token();
11511136

11521137
let crate_to_publish = PublishBuilder::new("foo_verified_email");
11531138

src/tests/util.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,28 @@ impl TestApp {
7979
f(&conn)
8080
}
8181

82-
/// Create a new user in the database and return a mock user session
82+
/// Create a new user with a verified email address in the database and return a mock user
83+
/// session
8384
///
8485
/// This method updates the database directly
85-
pub fn db_new_user(&self, user: &str) -> MockCookieUser {
86-
let user = self.db(|conn| crate::new_user(user).create_or_update(conn).unwrap());
86+
pub fn db_new_user(&self, username: &str) -> MockCookieUser {
87+
use cargo_registry::schema::emails;
88+
use diesel::prelude::*;
89+
90+
let user = self.db(|conn| {
91+
let mut user = crate::new_user(username).create_or_update(conn).unwrap();
92+
let email = "[email protected]";
93+
user.email = Some(email.to_string());
94+
diesel::insert_into(emails::table)
95+
.values((
96+
emails::user_id.eq(user.id),
97+
emails::email.eq(email),
98+
emails::verified.eq(true),
99+
))
100+
.execute(conn)
101+
.unwrap();
102+
user
103+
});
87104
MockCookieUser {
88105
app: TestApp(Rc::clone(&self.0)),
89106
user,

0 commit comments

Comments
 (0)