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

105 lines
3.1 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::UserTestBuilder;
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]
fn user_status_get_failed() {
let tester = UserTestBuilder::new().event(GetUserProfile).assert_error().sync_send();
assert!(tester.get_user_detail().is_none())
2021-09-01 09:57:06 +00:00
}
#[test]
#[serial]
fn user_detail_get() {
let user_detail = UserTestBuilder::new().sign_up().user_detail;
2021-09-01 09:57:06 +00:00
let user_detail2 = UserTestBuilder::new().event(GetUserProfile).sync_send().parse::<UserDetail>();
2021-09-01 09:57:06 +00:00
assert_eq!(user_detail, user_detail2);
}
#[test]
#[serial]
fn user_update_with_name() {
let user_detail = UserTestBuilder::new().sign_up().user_detail;
let new_name = "hello_world".to_owned();
2021-08-31 15:01:46 +00:00
let request = UpdateUserRequest::new(&user_detail.id).name(&new_name);
let _ = UserTestBuilder::new().event(UpdateUser).request(request).sync_send();
2021-08-31 15:01:46 +00:00
let user_detail = UserTestBuilder::new()
2021-08-31 15:01:46 +00:00
.event(GetUserProfile)
.assert_error()
.sync_send()
.parse::<UserDetail>();
assert_eq!(user_detail.name, new_name,);
}
#[test]
#[serial]
fn user_update_with_email() {
let user_detail = UserTestBuilder::new().sign_up().user_detail;
2021-09-01 09:57:06 +00:00
let new_email = format!("{}@gmai.com", uuid());
2021-08-31 15:01:46 +00:00
let request = UpdateUserRequest::new(&user_detail.id).email(&new_email);
let _ = UserTestBuilder::new().event(UpdateUser).request(request).sync_send();
2021-08-31 15:01:46 +00:00
let user_detail = UserTestBuilder::new()
2021-08-31 15:01:46 +00:00
.event(GetUserProfile)
.assert_error()
.sync_send()
.parse::<UserDetail>();
assert_eq!(user_detail.email, new_email,);
}
#[test]
#[serial]
fn user_update_with_password() {
let user_detail = UserTestBuilder::new().sign_up().user_detail;
let new_password = "H123world!".to_owned();
2021-08-31 15:01:46 +00:00
let request = UpdateUserRequest::new(&user_detail.id).password(&new_password);
let _ = UserTestBuilder::new()
.event(UpdateUser)
.request(request)
.sync_send()
.assert_success();
}
#[test]
#[serial]
fn user_update_with_invalid_email() {
let user_detail = UserTestBuilder::new().sign_up().user_detail;
for email in invalid_email_test_case() {
2021-08-31 15:01:46 +00:00
let request = UpdateUserRequest::new(&user_detail.id).email(&email);
assert_eq!(
UserTestBuilder::new().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 user_detail = UserTestBuilder::new().sign_up().user_detail;
for password in invalid_password_test_case() {
2021-08-31 15:01:46 +00:00
let request = UpdateUserRequest::new(&user_detail.id).password(&password);
UserTestBuilder::new().event(UpdateUser).request(request).sync_send().assert_error();
}
}
#[test]
#[serial]
fn user_update_with_invalid_name() {
let user_detail = UserTestBuilder::new().sign_up().user_detail;
2021-08-31 15:01:46 +00:00
let request = UpdateUserRequest::new(&user_detail.id).name("");
UserTestBuilder::new().event(UpdateUser).request(request).sync_send().assert_error();
}