-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d9c5d8
commit a3857ac
Showing
7 changed files
with
113 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,27 +125,60 @@ mod test { | |
#[tokio::test] | ||
async fn wrong_password() { | ||
let state = AppState::default(); | ||
let app = app_router(state.clone()).with_state(state); | ||
let mut app = app_router(state.clone()).with_state(state).into_service(); | ||
|
||
let response = app | ||
.oneshot( | ||
Request::builder() | ||
.method(http::Method::POST) | ||
.uri(SIGN_IN) | ||
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref()) | ||
.body(Body::from( | ||
json!({ | ||
"email": "[email protected]", | ||
"password": "wrong_password", | ||
"device": { | ||
"name": "android 1111", | ||
"os": "Android" | ||
} | ||
}) | ||
.to_string(), | ||
)) | ||
.unwrap(), | ||
) | ||
let request = Request::builder() | ||
.method(http::Method::POST) | ||
.uri(SIGN_UP) | ||
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref()) | ||
.body(Body::from( | ||
json!({ | ||
"email": "[email protected]", | ||
"password": "1234", | ||
"device": { | ||
"name": "android 1111", | ||
"os": "Android" | ||
} | ||
}) | ||
.to_string(), | ||
)) | ||
.unwrap(); | ||
let response = ServiceExt::<Request<Body>>::ready(&mut app) | ||
.await | ||
.unwrap() | ||
.call(request) | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!(response.status(), StatusCode::CREATED); | ||
|
||
let body = response.into_body().collect().await.unwrap().to_bytes(); | ||
let body: Value = serde_json::from_slice(&body).unwrap(); | ||
|
||
assert!(body["data"].is_object()); | ||
assert!(body["data"]["access_token"].is_string()); | ||
assert!(body["data"]["refresh_token"].is_string()); | ||
|
||
let request = Request::builder() | ||
.method(http::Method::POST) | ||
.uri(SIGN_IN) | ||
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref()) | ||
.body(Body::from( | ||
json!({ | ||
"email": "[email protected]", | ||
"password": "wrong_password", | ||
"device": { | ||
"name": "android 1111", | ||
"os": "Android" | ||
} | ||
}) | ||
.to_string(), | ||
)) | ||
.unwrap(); | ||
let response = ServiceExt::<Request<Body>>::ready(&mut app) | ||
.await | ||
.unwrap() | ||
.call(request) | ||
.await | ||
.unwrap(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ mod test { | |
}; | ||
use http_body_util::BodyExt; | ||
use serde_json::{json, Value}; | ||
use tower::ServiceExt; | ||
use tower::{Service, ServiceExt}; | ||
|
||
use crate::{ | ||
enums::errors::external::{AuthError, ExternalError}, | ||
|
@@ -56,27 +56,60 @@ mod test { | |
#[tokio::test] | ||
async fn user_already_exists() { | ||
let state = AppState::default(); | ||
let app = app_router(state.clone()).with_state(state); | ||
let mut app = app_router(state.clone()).with_state(state).into_service(); | ||
|
||
let request = Request::builder() | ||
.method(http::Method::POST) | ||
.uri(SIGN_UP) | ||
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref()) | ||
.body(Body::from( | ||
json!({ | ||
"email": "[email protected]", | ||
"password": "1234", | ||
"device": { | ||
"name": "android 1111", | ||
"os": "Android" | ||
} | ||
}) | ||
.to_string(), | ||
)) | ||
.unwrap(); | ||
let response = ServiceExt::<Request<Body>>::ready(&mut app) | ||
.await | ||
.unwrap() | ||
.call(request) | ||
.await | ||
.unwrap(); | ||
|
||
let response = app | ||
.oneshot( | ||
Request::builder() | ||
.method(http::Method::POST) | ||
.uri(SIGN_UP) | ||
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref()) | ||
.body(Body::from( | ||
json!({ | ||
"email": "[email protected]", | ||
"password": "1234", | ||
"device": { | ||
"name": "android 1111", | ||
"os": "Android" | ||
} | ||
}) | ||
.to_string(), | ||
)) | ||
.unwrap(), | ||
) | ||
assert_eq!(response.status(), StatusCode::CREATED); | ||
|
||
let body = response.into_body().collect().await.unwrap().to_bytes(); | ||
let body: Value = serde_json::from_slice(&body).unwrap(); | ||
|
||
assert!(body["data"].is_object()); | ||
assert!(body["data"]["access_token"].is_string()); | ||
assert!(body["data"]["refresh_token"].is_string()); | ||
|
||
let request = Request::builder() | ||
.method(http::Method::POST) | ||
.uri(SIGN_UP) | ||
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref()) | ||
.body(Body::from( | ||
json!({ | ||
"email": "[email protected]", | ||
"password": "1234", | ||
"device": { | ||
"name": "android 1111", | ||
"os": "Android" | ||
} | ||
}) | ||
.to_string(), | ||
)) | ||
.unwrap(); | ||
let response = ServiceExt::<Request<Body>>::ready(&mut app) | ||
.await | ||
.unwrap() | ||
.call(request) | ||
.await | ||
.unwrap(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
mod auth; | ||
mod session; | ||
mod session; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod close_session; | ||
mod create_session; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +0,0 @@ | ||
#[cfg(test)] | ||
mod test { | ||
use crate::config::ENV; | ||
#[test] | ||
fn test() { | ||
println!("{:?}", ENV.database_url); | ||
} | ||
} | ||