-
Notifications
You must be signed in to change notification settings - Fork 12
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
7d6ab21
commit 34df229
Showing
11 changed files
with
84 additions
and
11 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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
mod token_create; |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use std::str::FromStr; | ||
|
||
use async_graphql::{Request, Variables}; | ||
use serde_json::json; | ||
use townhall::user::{ | ||
model::{Email, Password, Username}, | ||
service::CreateUserDto, | ||
}; | ||
|
||
use crate::TestUtil; | ||
|
||
#[tokio::test] | ||
async fn authenticates_successfully() { | ||
let test_util = TestUtil::new_cleared().await; | ||
let (context, schema) = test_util.parts(); | ||
let mutation: &str = " | ||
mutation TokenCreate($email: String!, $password: String!) { | ||
tokenCreate(email: $email, password: $password) { | ||
token { | ||
accessToken | ||
} | ||
error { | ||
code | ||
message | ||
} | ||
} | ||
} | ||
"; | ||
let password = String::from("TestingPassword1234"); | ||
let user = context | ||
.services | ||
.user | ||
.register(CreateUserDto { | ||
name: "John".into(), | ||
surname: "Appleseed".into(), | ||
username: Username::from_str("jappleseed").unwrap(), | ||
email: Email::from_str("j.appleseed@mail.com").unwrap(), | ||
password: password.clone(), | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
let result = schema | ||
.execute( | ||
Request::new(mutation).variables(Variables::from_json(json!({ | ||
"email": "j.appleseed@mail.com", | ||
"password": password.clone(), | ||
}))), | ||
) | ||
.await; | ||
|
||
println!("{:#?}", result); | ||
|
||
let set_cookie = result.http_headers.get("Set-Cookie"); | ||
|
||
assert!(set_cookie.is_some()); | ||
|
||
let data = result.data.into_json().unwrap(); | ||
let access_token = &data["tokenCreate"]["token"]["accessToken"]; | ||
|
||
assert!(!access_token.to_string().is_empty()); | ||
assert_eq!(set_cookie.unwrap().to_str().unwrap(), access_token.to_string()); | ||
} |
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,3 @@ | ||
mod auth; | ||
mod post; | ||
mod user; |
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