2021-08-24 05:10:53 +00:00
|
|
|
use crate::helper::{spawn_app, TestApp};
|
2021-08-31 09:25:08 +00:00
|
|
|
use flowy_user::entities::{SignInParams, SignOutParams, SignUpParams, SignUpResponse};
|
2021-08-23 14:10:36 +00:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn user_register() {
|
|
|
|
let app = spawn_app().await;
|
2021-08-24 05:10:53 +00:00
|
|
|
let response = register_user(&app, "annie@appflowy.io", "HelloWork123!").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-08-23 14:10:36 +00:00
|
|
|
let app = spawn_app().await;
|
|
|
|
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() {
|
|
|
|
let app = spawn_app().await;
|
|
|
|
let email = "annie@gmail@";
|
|
|
|
let password = "HelloWork123!";
|
|
|
|
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() {
|
|
|
|
let app = spawn_app().await;
|
|
|
|
let email = "annie@appflowy.io";
|
|
|
|
let password = "HelloWork123!";
|
|
|
|
let _ = register_user(&app, email, password).await;
|
2021-08-23 14:10:36 +00:00
|
|
|
let response = app
|
|
|
|
.sign_in(SignInParams {
|
|
|
|
email: email.to_string(),
|
|
|
|
password: password.to_string(),
|
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
|
|
|
log::info!("{:?}", response);
|
|
|
|
}
|
2021-08-24 05:10:53 +00:00
|
|
|
|
2021-08-31 09:25:08 +00:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn user_sign_out() {
|
|
|
|
let app = spawn_app().await;
|
|
|
|
let email = "annie@appflowy.io";
|
|
|
|
let password = "HelloWork123!";
|
|
|
|
let _ = register_user(&app, email, password).await;
|
|
|
|
let sign_in_resp = app
|
|
|
|
.sign_in(SignInParams {
|
|
|
|
email: email.to_string(),
|
|
|
|
password: password.to_string(),
|
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
|
|
|
let sign_out_params = SignOutParams {
|
|
|
|
token: sign_in_resp.token,
|
|
|
|
};
|
|
|
|
|
|
|
|
app.sign_out(sign_out_params).await;
|
|
|
|
}
|
|
|
|
|
2021-08-24 05:10:53 +00:00
|
|
|
async fn register_user(app: &TestApp, email: &str, password: &str) -> SignUpResponse {
|
|
|
|
let params = SignUpParams {
|
|
|
|
email: email.to_string(),
|
|
|
|
name: "annie".to_string(),
|
|
|
|
password: password.to_string(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let response = app.register_user(params).await;
|
|
|
|
response
|
|
|
|
}
|