Skip to content

Commit 7ab93b6

Browse files
authored
Merge pull request #7493 from Turbo87/ok-bool
Reduce `OkBool` usage in tests
2 parents 4e1c640 + 4c079e6 commit 7ab93b6

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/tests/routes/me/email_notifications.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::builders::CrateBuilder;
2+
use crate::new_user;
23
use crate::util::{RequestHelper, TestApp};
3-
use crate::{new_user, OkBool};
44
use crates_io::schema::crate_owners;
55
use diesel::prelude::*;
6+
use http::StatusCode;
67

78
#[derive(Serialize)]
89
struct EmailNotificationsUpdate {
@@ -11,9 +12,10 @@ struct EmailNotificationsUpdate {
1112
}
1213

1314
impl crate::util::MockCookieUser {
14-
fn update_email_notifications(&self, updates: Vec<EmailNotificationsUpdate>) -> OkBool {
15-
self.put("/api/v1/me/email_notifications", json!(updates).to_string())
16-
.good()
15+
fn update_email_notifications(&self, updates: Vec<EmailNotificationsUpdate>) {
16+
let response = self.put::<()>("/api/v1/me/email_notifications", json!(updates).to_string());
17+
assert_eq!(response.status(), StatusCode::OK);
18+
assert_eq!(response.into_json(), json!({ "ok": true }));
1719
}
1820
}
1921

src/tests/routes/users/update.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use crate::util::{RequestHelper, Response, TestApp};
2-
use crate::OkBool;
32
use http::StatusCode;
43

54
pub trait MockEmailHelper: RequestHelper {
65
// TODO: I don't like the name of this method or `update_email` on the `MockCookieUser` impl;
76
// this is starting to look like a builder might help?
87
// I want to explore alternative abstractions in any case.
9-
fn update_email_more_control(&self, user_id: i32, email: Option<&str>) -> Response<OkBool> {
8+
fn update_email_more_control(&self, user_id: i32, email: Option<&str>) -> Response<()> {
109
// When updating your email in crates.io, the request goes to the user route with PUT.
1110
// Ember sends all the user attributes. We check to make sure the ID in the URL matches
1211
// the ID of the currently logged in user, then we ignore everything but the email address.
@@ -27,9 +26,11 @@ impl MockEmailHelper for crate::util::MockCookieUser {}
2726
impl MockEmailHelper for crate::util::MockAnonymousUser {}
2827

2928
impl crate::util::MockCookieUser {
30-
pub fn update_email(&self, email: &str) -> OkBool {
29+
pub fn update_email(&self, email: &str) {
3130
let model = self.as_model();
32-
self.update_email_more_control(model.id, Some(email)).good()
31+
let response = self.update_email_more_control(model.id, Some(email));
32+
assert_eq!(response.status(), StatusCode::OK);
33+
assert_eq!(response.into_json(), json!({ "ok": true }));
3334
}
3435
}
3536

src/tests/user.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
use crate::{
22
new_user,
33
util::{MockCookieUser, RequestHelper},
4-
OkBool, TestApp,
4+
TestApp,
55
};
66
use crates_io::models::{Email, NewUser, User};
77
use diesel::prelude::*;
8+
use http::StatusCode;
89
use secrecy::ExposeSecret;
910

1011
impl crate::util::MockCookieUser {
11-
fn confirm_email(&self, email_token: &str) -> OkBool {
12+
fn confirm_email(&self, email_token: &str) {
1213
let url = format!("/api/v1/confirm/{email_token}");
13-
self.put(&url, &[] as &[u8]).good()
14+
let response = self.put::<()>(&url, &[] as &[u8]);
15+
assert_eq!(response.status(), StatusCode::OK);
16+
assert_eq!(response.into_json(), json!({ "ok": true }));
1417
}
1518
}
1619

0 commit comments

Comments
 (0)