summaryrefslogtreecommitdiffstats
path: root/src/routes/login.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/login.rs')
-rw-r--r--src/routes/login.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/routes/login.rs b/src/routes/login.rs
index 12442e8..a3c52f8 100644
--- a/src/routes/login.rs
+++ b/src/routes/login.rs
@@ -8,6 +8,7 @@ use axum_extra::{
};
use jsonwebtoken::{EncodingKey, Header};
use serde::Deserialize;
+use serde_json::json;
use crate::{
model::{LoginSchema, TokenClaims, User},
@@ -81,8 +82,10 @@ mod tests {
const JWT_SECRET: &str = "test-jwt-secret-token";
const JWT_MAX_AGE: time::Duration = time::Duration::HOUR;
+ type TestResult<T = (), E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
+
#[sqlx::test(fixtures(path = "../../fixtures", scripts("users")))]
- async fn test_login_unauthorized(pool: PgPool) -> Result<(), Error> {
+ async fn test_login_unauthorized(pool: PgPool) -> TestResult {
let state = Arc::new(AppState {
pool,
jwt_secret: JWT_SECRET.to_string(),
@@ -99,9 +102,9 @@ mod tests {
.uri("/api/login")
.method("POST")
.header(header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
- .body(Body::from(serde_json::to_vec(&user).unwrap()))?;
+ .body(Body::from(serde_json::to_vec(&user)?))?;
- let response = router.oneshot(request).await.unwrap();
+ let response = router.oneshot(request).await?;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
@@ -109,7 +112,7 @@ mod tests {
}
#[sqlx::test(fixtures(path = "../../fixtures", scripts("users")))]
- async fn test_login_ok(pool: PgPool) -> Result<(), Error> {
+ async fn test_login_ok(pool: PgPool) -> TestResult {
let state = Arc::new(AppState {
pool,
jwt_secret: JWT_SECRET.to_string(),
@@ -122,16 +125,13 @@ mod tests {
password: "solongandthanksforallthefish".to_string(),
};
- let response = router
- .oneshot(
- Request::builder()
- .uri("/api/login")
- .method("POST")
- .header(header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
- .body(Body::from(serde_json::to_vec(&user).unwrap()))?,
- )
- .await
- .unwrap();
+ let request = Request::builder()
+ .uri("/api/login")
+ .method("POST")
+ .header(header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
+ .body(Body::from(serde_json::to_vec(&user)?))?;
+
+ let response = router.oneshot(request).await?;
assert_eq!(StatusCode::OK, response.status());