2021-07-19 08:15:20 +00:00
|
|
|
use crate::helper::*;
|
2021-09-01 09:57:06 +00:00
|
|
|
use flowy_infra::uuid;
|
2021-09-28 07:29:29 +00:00
|
|
|
use flowy_test::{builder::UserTest, FlowyTest};
|
2021-08-30 14:44:17 +00:00
|
|
|
use flowy_user::{errors::ErrorCode, event::UserEvent::*, prelude::*};
|
2021-07-19 08:15:20 +00:00
|
|
|
use serial_test::*;
|
|
|
|
|
2021-09-01 09:57:06 +00:00
|
|
|
#[test]
|
|
|
|
#[serial]
|
2021-09-04 07:12:53 +00:00
|
|
|
fn user_profile_get_failed() {
|
2021-09-28 07:29:29 +00:00
|
|
|
let test = FlowyTest::setup();
|
|
|
|
let result = UserTest::new(test.sdk).event(GetUserProfile).assert_error().sync_send();
|
2021-09-04 08:53:58 +00:00
|
|
|
assert!(result.user_profile().is_none())
|
2021-09-01 09:57:06 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
#[tokio::test]
|
2021-09-01 09:57:06 +00:00
|
|
|
#[serial]
|
2021-09-28 07:29:29 +00:00
|
|
|
async fn user_profile_get() {
|
|
|
|
let test = FlowyTest::setup();
|
|
|
|
let user_profile = test.init_user().await;
|
|
|
|
let user = UserTest::new(test.sdk.clone())
|
2021-09-04 08:12:48 +00:00
|
|
|
.event(GetUserProfile)
|
|
|
|
.sync_send()
|
2021-09-04 08:53:58 +00:00
|
|
|
.parse::<UserProfile>();
|
2021-09-28 07:29:29 +00:00
|
|
|
assert_eq!(user_profile, user);
|
2021-09-01 09:57:06 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
#[tokio::test]
|
2021-07-19 08:15:20 +00:00
|
|
|
#[serial]
|
2021-09-28 07:29:29 +00:00
|
|
|
async fn user_update_with_name() {
|
|
|
|
let test = FlowyTest::setup();
|
|
|
|
let user = test.init_user().await;
|
2021-07-19 08:15:20 +00:00
|
|
|
let new_name = "hello_world".to_owned();
|
2021-09-28 07:29:29 +00:00
|
|
|
let request = UpdateUserRequest::new(&user.id).name(&new_name);
|
|
|
|
let _ = UserTest::new(test.sdk()).event(UpdateUser).request(request).sync_send();
|
2021-08-31 15:01:46 +00:00
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
let user_profile = UserTest::new(test.sdk())
|
2021-08-31 15:01:46 +00:00
|
|
|
.event(GetUserProfile)
|
|
|
|
.assert_error()
|
2021-07-19 08:15:20 +00:00
|
|
|
.sync_send()
|
2021-09-04 08:53:58 +00:00
|
|
|
.parse::<UserProfile>();
|
2021-07-19 08:15:20 +00:00
|
|
|
|
2021-09-04 08:53:58 +00:00
|
|
|
assert_eq!(user_profile.name, new_name,);
|
2021-07-19 08:15:20 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
#[tokio::test]
|
2021-07-19 08:15:20 +00:00
|
|
|
#[serial]
|
2021-09-28 07:29:29 +00:00
|
|
|
async fn user_update_with_email() {
|
|
|
|
let test = FlowyTest::setup();
|
|
|
|
let user = test.init_user().await;
|
2021-09-01 09:57:06 +00:00
|
|
|
let new_email = format!("{}@gmai.com", uuid());
|
2021-09-28 07:29:29 +00:00
|
|
|
let request = UpdateUserRequest::new(&user.id).email(&new_email);
|
|
|
|
let _ = UserTest::new(test.sdk()).event(UpdateUser).request(request).sync_send();
|
|
|
|
let user_profile = UserTest::new(test.sdk())
|
2021-08-31 15:01:46 +00:00
|
|
|
.event(GetUserProfile)
|
|
|
|
.assert_error()
|
2021-07-19 08:15:20 +00:00
|
|
|
.sync_send()
|
2021-09-04 08:53:58 +00:00
|
|
|
.parse::<UserProfile>();
|
2021-07-19 08:15:20 +00:00
|
|
|
|
2021-09-04 08:53:58 +00:00
|
|
|
assert_eq!(user_profile.email, new_email,);
|
2021-07-19 08:15:20 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
#[tokio::test]
|
2021-07-19 08:15:20 +00:00
|
|
|
#[serial]
|
2021-09-28 07:29:29 +00:00
|
|
|
async fn user_update_with_password() {
|
|
|
|
let test = FlowyTest::setup();
|
|
|
|
let user = test.init_user().await;
|
2021-07-19 08:15:20 +00:00
|
|
|
let new_password = "H123world!".to_owned();
|
2021-09-28 07:29:29 +00:00
|
|
|
let request = UpdateUserRequest::new(&user.id).password(&new_password);
|
2021-07-19 08:15:20 +00:00
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
let _ = UserTest::new(test.sdk())
|
2021-07-19 08:15:20 +00:00
|
|
|
.event(UpdateUser)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.assert_success();
|
|
|
|
}
|
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
#[tokio::test]
|
2021-07-19 08:15:20 +00:00
|
|
|
#[serial]
|
2021-09-28 07:29:29 +00:00
|
|
|
async fn user_update_with_invalid_email() {
|
|
|
|
let test = FlowyTest::setup();
|
|
|
|
let user = test.init_user().await;
|
2021-07-19 08:15:20 +00:00
|
|
|
for email in invalid_email_test_case() {
|
2021-09-28 07:29:29 +00:00
|
|
|
let request = UpdateUserRequest::new(&user.id).email(&email);
|
2021-07-19 08:15:20 +00:00
|
|
|
assert_eq!(
|
2021-09-28 07:29:29 +00:00
|
|
|
UserTest::new(test.sdk())
|
|
|
|
.event(UpdateUser)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.error()
|
|
|
|
.code,
|
2021-08-30 14:44:17 +00:00
|
|
|
ErrorCode::EmailFormatInvalid
|
2021-07-19 08:15:20 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
#[tokio::test]
|
2021-07-19 08:15:20 +00:00
|
|
|
#[serial]
|
2021-09-28 07:29:29 +00:00
|
|
|
async fn user_update_with_invalid_password() {
|
|
|
|
let test = FlowyTest::setup();
|
|
|
|
let user = test.init_user().await;
|
2021-07-19 08:15:20 +00:00
|
|
|
for password in invalid_password_test_case() {
|
2021-09-28 07:29:29 +00:00
|
|
|
let request = UpdateUserRequest::new(&user.id).password(&password);
|
2021-07-19 08:15:20 +00:00
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
UserTest::new(test.sdk())
|
2021-09-04 07:12:53 +00:00
|
|
|
.event(UpdateUser)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.assert_error();
|
2021-07-19 08:15:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
#[tokio::test]
|
2021-07-19 08:15:20 +00:00
|
|
|
#[serial]
|
2021-09-28 07:29:29 +00:00
|
|
|
async fn user_update_with_invalid_name() {
|
|
|
|
let test = FlowyTest::setup();
|
|
|
|
let user = test.init_user().await;
|
|
|
|
let request = UpdateUserRequest::new(&user.id).name("");
|
|
|
|
UserTest::new(test.sdk())
|
2021-09-04 07:12:53 +00:00
|
|
|
.event(UpdateUser)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.assert_error();
|
2021-07-19 08:15:20 +00:00
|
|
|
}
|