Added
All checks were successful
Rust Build / Check (pull_request) Successful in 1m1s
Rust Build / Test Suite (pull_request) Successful in 1m28s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Successful in 1m2s
Rust Build / build (pull_request) Successful in 1m54s
All checks were successful
Rust Build / Check (pull_request) Successful in 1m1s
Rust Build / Test Suite (pull_request) Successful in 1m28s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Successful in 1m2s
Rust Build / build (pull_request) Successful in 1m54s
This commit is contained in:
21
src/main.rs
21
src/main.rs
@@ -64,10 +64,16 @@ mod tests {
|
|||||||
http::{Request, StatusCode},
|
http::{Request, StatusCode},
|
||||||
};
|
};
|
||||||
use http_body_util::BodyExt;
|
use http_body_util::BodyExt;
|
||||||
// use reqwest;
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tower::ServiceExt; // for `call`, `oneshot`, and `ready`
|
use tower::ServiceExt; // for `call`, `oneshot`, and `ready`
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: icarus_auth::models::common::User,
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_hello_world() {
|
async fn test_hello_world() {
|
||||||
let app = init::app().await;
|
let app = init::app().await;
|
||||||
@@ -106,8 +112,8 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let payload = json!({
|
let payload = json!({
|
||||||
"username": usr.username,
|
"username": &usr.username,
|
||||||
"password": usr.password,
|
"password": &usr.password,
|
||||||
});
|
});
|
||||||
|
|
||||||
let response = app
|
let response = app
|
||||||
@@ -124,6 +130,15 @@ mod tests {
|
|||||||
match response {
|
match response {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
assert_eq!(resp.status(), StatusCode::CREATED, "Message: {:?}", resp);
|
assert_eq!(resp.status(), StatusCode::CREATED, "Message: {:?}", resp);
|
||||||
|
let body = axum::body::to_bytes(resp.into_body(), usize::MAX)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let parsed_body: Response = serde_json::from_slice(&body).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
usr.username, parsed_body.data.username,
|
||||||
|
"Usernames do not match"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
assert!(false, "Error: {:?}", err.to_string());
|
assert!(false, "Error: {:?}", err.to_string());
|
||||||
|
Reference in New Issue
Block a user