Skip to content

Commit 5ef002d

Browse files
committed
update tests to match altered fields
1 parent 521beb7 commit 5ef002d

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

src/tests/all.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ fn new_user(login: &str) -> NewUser<'_> {
220220
NewUser {
221221
gh_id: NEXT_GH_ID.fetch_add(1, Ordering::SeqCst) as i32,
222222
gh_login: login,
223-
email: None,
224223
name: None,
225224
gh_avatar: None,
226225
gh_access_token: Cow::Borrowed("some random token"),

src/tests/krate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn index() {
8686
assert_eq!(json.meta.total, 0);
8787

8888
let krate = app.db(|conn| {
89-
let u = new_user("foo").create_or_update(conn).unwrap();
89+
let u = new_user("foo").create_or_update(None, conn).unwrap();
9090
CrateBuilder::new("fooindex", u.id).expect_build(conn)
9191
});
9292

src/tests/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn token_gives_access_to_me() {
267267
anon.get(url).assert_forbidden();
268268

269269
let json: UserShowPrivateResponse = token.get(url).good();
270-
assert_eq!(json.user.email, user.as_model().email);
270+
assert_eq!(json.user.name, user.as_model().name);
271271
}
272272

273273
#[test]

src/tests/user.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn me() {
110110
let user = app.db_new_user("foo");
111111
let json = user.show_me();
112112

113-
assert_eq!(json.user.email, user.as_model().email);
113+
assert_eq!(json.user.name, user.as_model().name);
114114
}
115115

116116
#[test]
@@ -141,21 +141,19 @@ fn show_latest_user_case_insensitively() {
141141
t!(NewUser::new(
142142
1,
143143
"foobar",
144-
145144
Some("I was first then deleted my github account"),
146145
None,
147146
"bar"
148147
)
149-
.create_or_update(conn));
148+
.create_or_update(None, conn));
150149
t!(NewUser::new(
151150
2,
152151
"FOOBAR",
153-
154152
Some("I was second, I took the foobar username on github"),
155153
None,
156154
"bar"
157155
)
158-
.create_or_update(conn));
156+
.create_or_update(None, conn));
159157
});
160158

161159
let json: UserShowPublicResponse = anon.get("api/v1/users/fOObAr").good();
@@ -324,7 +322,7 @@ fn updating_existing_user_doesnt_change_api_token() {
324322

325323
let user = app.db(|conn| {
326324
// Reuse gh_id but use new gh_login and gh_access_token
327-
t!(NewUser::new(gh_id, "bar", None, None, None, "bar_token").create_or_update(conn));
325+
t!(NewUser::new(gh_id, "bar", None, None, "bar_token").create_or_update(None, conn));
328326

329327
// Use the original API token to find the now updated user
330328
t!(User::find_by_api_token(conn, token))
@@ -353,7 +351,7 @@ fn github_without_email_does_not_overwrite_email() {
353351
// Don't use app.db_new_user because it adds a verified email.
354352
let user_without_github_email = app.db(|conn| {
355353
let u = new_user("arbitrary_username");
356-
let u = u.create_or_update(conn).unwrap();
354+
let u = u.create_or_update(None, conn).unwrap();
357355
MockCookieUser::new(&app, u)
358356
});
359357
let user_without_github_email_model = user_without_github_email.as_model();
@@ -373,7 +371,7 @@ fn github_without_email_does_not_overwrite_email() {
373371
// new_user uses a None email; the rest of the fields are arbitrary
374372
..new_user("arbitrary_username")
375373
};
376-
let u = u.create_or_update(conn).unwrap();
374+
let u = u.create_or_update(None, conn).unwrap();
377375
MockCookieUser::new(&app, u)
378376
});
379377

@@ -386,9 +384,16 @@ fn github_without_email_does_not_overwrite_email() {
386384
*/
387385
#[test]
388386
fn github_with_email_does_not_overwrite_email() {
387+
use cargo_registry::schema::emails;
388+
389389
let (app, _, user) = TestApp::init().with_user();
390390
let model = user.as_model();
391-
let original_email = &model.email;
391+
let original_email = app.db(|conn| {
392+
Email::belonging_to(model)
393+
.select(emails::email)
394+
.first::<String>(&*conn)
395+
.unwrap()
396+
});
392397

393398
let new_github_email = "[email protected]";
394399

@@ -397,16 +402,15 @@ fn github_with_email_does_not_overwrite_email() {
397402
let u = NewUser {
398403
// Use the same github ID to link to the existing account
399404
gh_id: model.gh_id,
400-
email: Some(new_github_email),
401405
// the rest of the fields are arbitrary
402406
..new_user("arbitrary_username")
403407
};
404-
let u = u.create_or_update(conn).unwrap();
408+
let u = u.create_or_update(Some(new_github_email), conn).unwrap();
405409
MockCookieUser::new(&app, u)
406410
});
407411

408412
let json = user_with_different_email_in_github.show_me();
409-
assert_eq!(json.user.email, *original_email);
413+
assert_eq!(json.user.email, Some(original_email));
410414
}
411415

412416
/* Given a crates.io user, check that the user's email can be
@@ -512,10 +516,9 @@ fn test_confirm_user_email() {
512516
// email directly into the database and we want to test the verification flow here.
513517
let user = app.db(|conn| {
514518
let u = NewUser {
515-
email: Some("[email protected]"),
516519
..new_user("arbitrary_username")
517520
};
518-
let u = u.create_or_update(conn).unwrap();
521+
let u = u.create_or_update(None, conn).unwrap();
519522
MockCookieUser::new(&app, u)
520523
});
521524
let user_model = user.as_model();
@@ -551,10 +554,9 @@ fn test_existing_user_email() {
551554
// email directly into the database and we want to test the verification flow here.
552555
let user = app.db(|conn| {
553556
let u = NewUser {
554-
email: Some("[email protected]"),
555557
..new_user("arbitrary_username")
556558
};
557-
let u = u.create_or_update(conn).unwrap();
559+
let u = u.create_or_update(None, conn).unwrap();
558560
update(Email::belonging_to(&u))
559561
// Users created before we added verification will have
560562
// `NULL` in the `token_generated_at` column.

src/tests/util.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ impl TestApp {
135135
use diesel::prelude::*;
136136

137137
let user = self.db(|conn| {
138-
let mut user = crate::new_user(username).create_or_update(conn).unwrap();
139-
let email = "[email protected]";
140-
user.email = Some(email.to_string());
138+
let email = "[email protected]";
139+
let user = crate::new_user(username)
140+
.create_or_update(Some(email), conn)
141+
.unwrap();
141142
diesel::insert_into(emails::table)
142143
.values((
143144
emails::user_id.eq(user.id),

0 commit comments

Comments
 (0)