2021-09-10 10:21:35 +00:00
|
|
|
use crate::helper::{spawn_server, TestServer};
|
2021-09-01 08:37:46 +00:00
|
|
|
use flowy_user::entities::{SignInParams, SignUpParams, SignUpResponse, UpdateUserParams};
|
2021-08-23 14:10:36 +00:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn user_register() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let app = spawn_server().await;
|
2021-09-01 08:08:32 +00:00
|
|
|
let response = register_user(&app, "annie@appflowy.io", "HelloWorld123!").await;
|
2021-08-23 14:10:36 +00:00
|
|
|
log::info!("{:?}", response);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
2021-08-24 05:10:53 +00:00
|
|
|
#[should_panic]
|
|
|
|
async fn user_sign_in_with_invalid_password() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let app = spawn_server().await;
|
2021-08-23 14:10:36 +00:00
|
|
|
let email = "annie@appflowy.io";
|
|
|
|
let password = "123";
|
2021-08-24 05:10:53 +00:00
|
|
|
let _ = register_user(&app, email, password).await;
|
|
|
|
}
|
2021-08-23 14:10:36 +00:00
|
|
|
|
2021-08-24 05:10:53 +00:00
|
|
|
#[actix_rt::test]
|
|
|
|
#[should_panic]
|
|
|
|
async fn user_sign_in_with_invalid_email() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let app = spawn_server().await;
|
2021-08-24 05:10:53 +00:00
|
|
|
let email = "annie@gmail@";
|
2021-09-01 08:08:32 +00:00
|
|
|
let password = "HelloWorld123!";
|
2021-08-24 05:10:53 +00:00
|
|
|
let _ = register_user(&app, email, password).await;
|
|
|
|
}
|
2021-08-23 14:10:36 +00:00
|
|
|
|
2021-08-24 05:10:53 +00:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn user_sign_in() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let app = spawn_server().await;
|
2021-08-24 05:10:53 +00:00
|
|
|
let email = "annie@appflowy.io";
|
2021-09-01 08:08:32 +00:00
|
|
|
let password = "HelloWorld123!";
|
2021-08-24 05:10:53 +00:00
|
|
|
let _ = register_user(&app, email, password).await;
|
2021-09-01 08:08:32 +00:00
|
|
|
let params = SignInParams {
|
|
|
|
email: email.to_string(),
|
|
|
|
password: password.to_string(),
|
|
|
|
};
|
|
|
|
let _ = app.sign_in(params).await.unwrap();
|
2021-08-23 14:10:36 +00:00
|
|
|
}
|
2021-08-24 05:10:53 +00:00
|
|
|
|
2021-08-31 09:25:08 +00:00
|
|
|
#[actix_rt::test]
|
2021-09-01 08:08:32 +00:00
|
|
|
#[should_panic]
|
2021-08-31 09:25:08 +00:00
|
|
|
async fn user_sign_out() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let server = TestServer::new().await;
|
|
|
|
server.sign_out().await;
|
2021-08-31 09:56:38 +00:00
|
|
|
|
2021-09-01 08:08:32 +00:00
|
|
|
// user_detail will be empty because use was sign out.
|
2021-09-10 10:21:35 +00:00
|
|
|
server.get_user_profile().await;
|
2021-08-31 09:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn user_get_detail() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let server = TestServer::new().await;
|
|
|
|
log::info!("{:?}", server.get_user_profile().await);
|
2021-09-01 08:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn user_update_password() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let mut server = spawn_server().await;
|
2021-08-31 09:56:38 +00:00
|
|
|
let email = "annie@appflowy.io";
|
2021-09-01 08:08:32 +00:00
|
|
|
let password = "HelloWorld123!";
|
2021-09-10 10:21:35 +00:00
|
|
|
let sign_up_resp = register_user(&server, email, password).await;
|
2021-09-01 08:08:32 +00:00
|
|
|
|
2021-09-02 06:47:39 +00:00
|
|
|
let params = UpdateUserParams::new(&sign_up_resp.user_id).password("Hello123!");
|
2021-09-10 10:21:35 +00:00
|
|
|
server.user_token = Some(sign_up_resp.token);
|
|
|
|
|
|
|
|
server.update_user_profile(params).await.unwrap();
|
2021-09-01 08:08:32 +00:00
|
|
|
|
|
|
|
let sign_in_params = SignInParams {
|
|
|
|
email: email.to_string(),
|
|
|
|
password: password.to_string(),
|
2021-08-31 09:56:38 +00:00
|
|
|
};
|
2021-09-01 08:08:32 +00:00
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
match server.sign_in(sign_in_params).await {
|
2021-09-01 08:08:32 +00:00
|
|
|
Ok(_) => {},
|
|
|
|
Err(e) => {
|
|
|
|
assert_eq!(e.code, flowy_user::errors::ErrorCode::PasswordNotMatch);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn user_update_name() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let server = TestServer::new().await;
|
|
|
|
|
2021-09-01 08:08:32 +00:00
|
|
|
let name = "tom".to_string();
|
2021-09-10 10:21:35 +00:00
|
|
|
let params = UpdateUserParams::new(&server.user_id()).name(&name);
|
|
|
|
server.update_user_profile(params).await.unwrap();
|
2021-09-01 08:08:32 +00:00
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
let user = server.get_user_profile().await;
|
2021-09-01 08:08:32 +00:00
|
|
|
assert_eq!(user.name, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn user_update_email() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let server = TestServer::new().await;
|
2021-09-01 08:08:32 +00:00
|
|
|
let email = "123@gmail.com".to_string();
|
2021-09-10 10:21:35 +00:00
|
|
|
let params = UpdateUserParams::new(server.user_id()).email(&email);
|
|
|
|
server.update_user_profile(params).await.unwrap();
|
2021-09-01 08:08:32 +00:00
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
let user = server.get_user_profile().await;
|
2021-09-01 08:08:32 +00:00
|
|
|
assert_eq!(user.email, email);
|
|
|
|
}
|
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
async fn sign_up_user(server: &TestServer) -> SignUpResponse {
|
2021-09-01 08:08:32 +00:00
|
|
|
let email = "annie@appflowy.io";
|
|
|
|
let password = "HelloWorld123!";
|
2021-09-10 10:21:35 +00:00
|
|
|
let response = register_user(server, email, password).await;
|
2021-09-01 08:08:32 +00:00
|
|
|
response
|
2021-08-31 09:25:08 +00:00
|
|
|
}
|
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
async fn register_user(server: &TestServer, email: &str, password: &str) -> SignUpResponse {
|
2021-08-24 05:10:53 +00:00
|
|
|
let params = SignUpParams {
|
|
|
|
email: email.to_string(),
|
|
|
|
name: "annie".to_string(),
|
|
|
|
password: password.to_string(),
|
|
|
|
};
|
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
let response = server.register(params).await;
|
2021-08-24 05:10:53 +00:00
|
|
|
response
|
|
|
|
}
|