Register endpoint #16
21
src/main.rs
21
src/main.rs
@@ -64,10 +64,16 @@ mod tests {
|
||||
http::{Request, StatusCode},
|
||||
};
|
||||
use http_body_util::BodyExt;
|
||||
// use reqwest;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
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]
|
||||
async fn test_hello_world() {
|
||||
let app = init::app().await;
|
||||
@@ -106,8 +112,8 @@ mod tests {
|
||||
};
|
||||
|
||||
let payload = json!({
|
||||
"username": usr.username,
|
||||
"password": usr.password,
|
||||
"username": &usr.username,
|
||||
"password": &usr.password,
|
||||
});
|
||||
|
||||
let response = app
|
||||
@@ -124,6 +130,15 @@ mod tests {
|
||||
match response {
|
||||
Ok(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) => {
|
||||
assert!(false, "Error: {:?}", err.to_string());
|
||||
|
Reference in New Issue
Block a user