Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/jwt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ mod test {
let req = TestRequest::GET("/auth");
let res = t.oneshot(req).await;
let AuthResponse { token } = res.json()
.expect("`/auth` response doesn't contain a token")
.expect("`/auth` response is not `AuthResponse`");
.expect("`/auth` response doesn't contain a token");

let req = TestRequest::GET("/private")
.header("Authorization", format!("Bearer {token}"));
Expand Down
6 changes: 3 additions & 3 deletions ohkami/src/fang/builtin/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ impl<Payload: for<'de> Deserialize<'de>> JWT<Payload> {
.header("Authorization", format!("Bearer {jwt_1}"));
let res = t.oneshot(req).await;
assert_eq!(res.status(), Status::OK);
assert_eq!(res.json::<Profile>().unwrap().unwrap(), Profile {
assert_eq!(res.json::<Profile>().unwrap(), Profile {
id: 1,
first_name: String::from("ohkami"),
familly_name: String::from("framework"),
Expand Down Expand Up @@ -690,7 +690,7 @@ impl<Payload: for<'de> Deserialize<'de>> JWT<Payload> {
.header("Authorization", format!("Bearer {jwt_2}"));
let res = t.oneshot(req).await;
assert_eq!(res.status(), Status::OK);
assert_eq!(res.json::<Profile>().unwrap().unwrap(), Profile {
assert_eq!(res.json::<Profile>().unwrap(), Profile {
id: 2,
first_name: String::from("Leonhard"),
familly_name: String::from("Euler"),
Expand Down Expand Up @@ -718,7 +718,7 @@ impl<Payload: for<'de> Deserialize<'de>> JWT<Payload> {
.header("Authorization", format!("Bearer {jwt_1}"));
let res = t.oneshot(req).await;
assert_eq!(res.status(), Status::OK);
assert_eq!(res.json::<Profile>().unwrap().unwrap(), Profile {
assert_eq!(res.json::<Profile>().unwrap(), Profile {
id: 1,
first_name: String::from("ohkami"),
familly_name: String::from("framework"),
Expand Down
14 changes: 6 additions & 8 deletions ohkami/src/testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,12 @@ impl TestResponse {
bytes.escape_ascii()
)))
}
pub fn json<'d, T: serde::Deserialize<'d>>(&'d self) -> Option<Result<T, serde_json::Error>> {
pub fn json<'d, T: serde::Deserialize<'d>>(&'d self) -> Option<T> {
self.content("application/json")
.map(|bytes| serde_json::from_slice(bytes)
// .expect(&f!(
// "Failed to deserialize json payload as {}: {}",
// std::any::type_name::<T>(),
// bytes.escape_ascii()
// ))
)
.map(|bytes| serde_json::from_slice(bytes).expect(&f!(
"Failed to deserialize json payload as {}: {}",
std::any::type_name::<T>(),
bytes.escape_ascii()
)))
}
}
12 changes: 6 additions & 6 deletions samples/realworld/src/_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub async fn senario() {

let UserResponse {
user: User { email, jwt, name, bio, image }
} = res.json().unwrap().unwrap();
} = res.json().unwrap();

assert_eq!(email, "jake@jake.jake");
assert_eq!(name, "Jacob");
Expand All @@ -119,7 +119,7 @@ pub async fn senario() {

let UserResponse {
user: User { email, jwt, name, bio, image }
} = res.json().unwrap().unwrap();
} = res.json().unwrap();

assert_eq!(email, "jake@jake.jake");
assert_eq!(name, "Jacob");
Expand All @@ -145,7 +145,7 @@ pub async fn senario() {

let UserResponse {
user: User { email, jwt, name, bio, image }
} = res.json().unwrap().unwrap();
} = res.json().unwrap();

assert_eq!(email, "jake@jake.jake");
assert_eq!(name, "Jacob");
Expand All @@ -160,7 +160,7 @@ pub async fn senario() {
let res = t.oneshot(req).await;

assert_eq!(res.status(), Status::OK);
assert_eq!(res.json::<ListOfTagsResponse>().unwrap().unwrap(), ListOfTagsResponse {
assert_eq!(res.json::<ListOfTagsResponse>().unwrap(), ListOfTagsResponse {
tags: Vec::new()
});

Expand All @@ -181,7 +181,7 @@ pub async fn senario() {

assert_eq!(res.status(), Status::Created);

let SingleArticleResponse { article } = res.json().unwrap().unwrap();
let SingleArticleResponse { article } = res.json().unwrap();

assert_eq!(article.title, "How to train your dragon");
assert_eq!(article.slug, "How-to-train-your-dragon");
Expand All @@ -204,7 +204,7 @@ pub async fn senario() {
let res = t.oneshot(req).await;

assert_eq!(res.status(), Status::OK);
assert_eq!(res.json::<ListOfTagsResponse>().unwrap().unwrap(), ListOfTagsResponse {
assert_eq!(res.json::<ListOfTagsResponse>().unwrap(), ListOfTagsResponse {
tags: vec![Tag::new("reactjs"), Tag::new("angularjs"), Tag::new("dragons")]
});

Expand Down