Skip to content

Commit

Permalink
test(users): Rename auth tests to users and add more user tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TatriX committed Jun 13, 2019
1 parent 947029f commit 1560b14
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -4,7 +4,6 @@ language: rust
rust: nightly
cache: cargo


addons:
apt:
packages:
Expand Down
47 changes: 46 additions & 1 deletion tests/auth.rs → tests/users.rs
Expand Up @@ -28,6 +28,36 @@ fn test_register() {
}
}

#[test]
/// Registration with the same email must fail
fn test_register_with_duplicated_email() {
let client = test_client();
register(client, "clone", "clone@realworld.io", PASSWORD);

let response = &mut client
.post("/api/users")
.header(ContentType::JSON)
.body(json_string!({
"user": {
"username": "clone_1",
"email": "clone@realworld.io",
"password": PASSWORD,
},
}))
.dispatch();

assert_eq!(response.status(), Status::UnprocessableEntity);

let value = response_json_value(response);
let error = value
.get("errors")
.and_then(|errors| errors.get("email"))
.and_then(|errors| errors.get(0))
.and_then(|error| error.as_str());

assert_eq!(error, Some("has already been taken"))
}

#[test]
/// Login with wrong password must fail.
fn test_incorrect_login() {
Expand Down Expand Up @@ -75,7 +105,7 @@ fn test_login() {

#[test]
/// Check that `/user` endpoint returns expected data.
fn test_get_current_user() {
fn test_get_user() {
let client = test_client();
let token = login(&client);
let response = &mut client
Expand All @@ -86,6 +116,21 @@ fn test_get_current_user() {
check_user_response(response);
}

#[test]
/// Test user updating.
fn test_put_user() {
let client = test_client();
let token = login(&client);
let response = &mut client
.put("/api/user")
.header(token_header(token))
.header(ContentType::JSON)
.body(json_string!({"user": {"bio": "I'm doing Rust!"}}))
.dispatch();

check_user_response(response);
}

// Utility functions

/// Assert that body contains "user" response with expected fields.
Expand Down

0 comments on commit 1560b14

Please sign in to comment.