tests: add more test cases for auth API

This commit is contained in:
Peter Cai 2020-02-21 09:13:35 +08:00
parent 2893bbd595
commit 689b67ca74
No known key found for this signature in database
GPG Key ID: 71F5FB4E4F3FD54F
1 changed files with 87 additions and 0 deletions

View File

@ -109,4 +109,91 @@ fn should_log_in_fail() {
}"#)
.dispatch();
assert_eq!(resp.status(), Status::InternalServerError);
}
#[test]
fn should_change_pw_successfully() {
CLIENT.post("/auth")
.header(ContentType::JSON)
.body(r#"{
"email": "test4@example.com",
"password": "testpw",
"pw_cost": "100",
"pw_nonce": "whatever",
"version": "001"
}"#)
.dispatch()
.body_string()
.unwrap();
let resp = CLIENT
.post("/auth/change_pw")
.header(ContentType::JSON)
.body(r#"{
"email": "test4@example.com",
"password": "testpw1",
"current_password": "testpw"
}"#)
.dispatch();
assert_eq!(resp.status(), Status::NoContent);
}
#[test]
fn should_change_pw_fail() {
CLIENT.post("/auth")
.header(ContentType::JSON)
.body(r#"{
"email": "test5@example.com",
"password": "testpw",
"pw_cost": "100",
"pw_nonce": "whatever",
"version": "001"
}"#)
.dispatch()
.body_string()
.unwrap();
let resp = CLIENT
.post("/auth/change_pw")
.header(ContentType::JSON)
.body(r#"{
"email": "test5@example.com",
"password": "testpw1",
"current_password": "testpw2"
}"#)
.dispatch();
assert_eq!(resp.status(), Status::InternalServerError);
}
#[test]
fn should_change_pw_successfully_and_log_in_successfully() {
CLIENT.post("/auth")
.header(ContentType::JSON)
.body(r#"{
"email": "test6@example.com",
"password": "testpw",
"pw_cost": "100",
"pw_nonce": "whatever",
"version": "001"
}"#)
.dispatch()
.body_string()
.unwrap();
let resp = CLIENT
.post("/auth/change_pw")
.header(ContentType::JSON)
.body(r#"{
"email": "test6@example.com",
"password": "testpw1",
"current_password": "testpw"
}"#)
.dispatch();
assert_eq!(resp.status(), Status::NoContent);
let resp = CLIENT
.post("/auth/sign_in")
.header(ContentType::JSON)
.body(r#"{
"email": "test6@example.com",
"password": "testpw1"
}"#)
.dispatch();
assert_eq!(resp.status(), Status::Ok);
}