AppFlowy/rust-lib/flowy-user/tests/event/user_profile_test.rs

112 lines
3.0 KiB
Rust
Raw Normal View History

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