Skip to content

Commit 5d0906e

Browse files
committed
Convert a few remaining integers to StatusCode
1 parent f345573 commit 5d0906e

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/router.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ mod tests {
191191
};
192192
use crate::util::EndpointResult;
193193

194+
use conduit::StatusCode;
194195
use conduit_test::MockRequest;
195196
use diesel::result::Error as DieselError;
196197

@@ -205,25 +206,28 @@ mod tests {
205206
// Types for handling common error status codes
206207
assert_eq!(
207208
C(|_| Err(bad_request(""))).call(&mut req).unwrap().status(),
208-
400
209+
StatusCode::BAD_REQUEST
209210
);
210211
assert_eq!(
211212
C(|_| err(Unauthorized)).call(&mut req).unwrap().status(),
212-
403
213+
StatusCode::FORBIDDEN
213214
);
214215
assert_eq!(
215216
C(|_| Err(DieselError::NotFound.into()))
216217
.call(&mut req)
217218
.unwrap()
218219
.status(),
219-
404
220+
StatusCode::NOT_FOUND
221+
);
222+
assert_eq!(
223+
C(|_| err(NotFound)).call(&mut req).unwrap().status(),
224+
StatusCode::NOT_FOUND
220225
);
221-
assert_eq!(C(|_| err(NotFound)).call(&mut req).unwrap().status(), 404);
222226

223227
// cargo_err errors are returned as 200 so that cargo displays this nicely on the command line
224228
assert_eq!(
225229
C(|_| Err(cargo_err(""))).call(&mut req).unwrap().status(),
226-
200
230+
StatusCode::OK
227231
);
228232

229233
// Inner errors are captured for logging when wrapped by a user facing error
@@ -236,7 +240,7 @@ mod tests {
236240
})
237241
.call(&mut req)
238242
.unwrap();
239-
assert_eq!(response.status(), 400);
243+
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
240244
assert_eq!(
241245
crate::middleware::log_request::get_log_message(&req, "cause"),
242246
"middle error caused by invalid digit found in string"

src/tests/authentication.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn anonymous_user_unauthorized() {
2828
let request = anon.request_builder(Method::GET, URL);
2929

3030
let (status, body) = into_parts(call(&app, request));
31-
assert_eq!(status, 403);
31+
assert_eq!(status, StatusCode::FORBIDDEN);
3232
assert_eq!(body, MUST_LOGIN);
3333
}
3434

@@ -39,7 +39,7 @@ fn token_auth_cannot_find_token() {
3939
request.header(header::AUTHORIZATION, "fake-token");
4040

4141
let (status, body) = into_parts(call(&app, request));
42-
assert_eq!(status, 403);
42+
assert_eq!(status, StatusCode::FORBIDDEN);
4343
assert_eq!(body, MUST_LOGIN);
4444
}
4545

0 commit comments

Comments
 (0)