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

105 lines
2.8 KiB
Rust
Raw Normal View History

use crate::helper::*;
2021-08-30 14:44:17 +00:00
use flowy_user::{errors::ErrorCode, event::UserEvent::*, prelude::*};
use serial_test::*;
#[test]
#[serial]
fn user_update_with_name() {
2021-08-31 15:01:46 +00:00
let user_detail = TestBuilder::new().login().user_detail.unwrap();
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 _ = TestBuilder::new()
.event(UpdateUser)
.request(request)
2021-08-31 15:01:46 +00:00
.sync_send();
let user_detail = TestBuilder::new()
.event(GetUserProfile)
.assert_error()
.sync_send()
.parse::<UserDetail>();
assert_eq!(user_detail.name, new_name,);
}
#[test]
#[serial]
fn user_update_with_email() {
2021-08-31 15:01:46 +00:00
let user_detail = TestBuilder::new().login().user_detail.unwrap();
let new_email = "123@gmai.com".to_owned();
2021-08-31 15:01:46 +00:00
let request = UpdateUserRequest::new(&user_detail.id).email(&new_email);
2021-08-31 15:01:46 +00:00
let _ = TestBuilder::new()
.event(UpdateUser)
.request(request)
2021-08-31 15:01:46 +00:00
.sync_send();
let user_detail = TestBuilder::new()
.event(GetUserProfile)
.assert_error()
.sync_send()
.parse::<UserDetail>();
assert_eq!(user_detail.email, new_email,);
}
#[test]
#[serial]
fn user_update_with_password() {
2021-08-31 15:01:46 +00:00
let user_detail = TestBuilder::new().login().user_detail.unwrap();
let new_password = "H123world!".to_owned();
2021-08-31 15:01:46 +00:00
let request = UpdateUserRequest::new(&user_detail.id).password(&new_password);
2021-08-31 15:01:46 +00:00
let _ = TestBuilder::new()
.event(UpdateUser)
.request(request)
.sync_send()
.assert_success();
}
#[test]
#[serial]
fn user_update_with_invalid_email() {
2021-08-31 15:01:46 +00:00
let user_detail = TestBuilder::new().login().user_detail.unwrap();
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!(
2021-08-31 15:01:46 +00:00
TestBuilder::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() {
2021-08-31 15:01:46 +00:00
let user_detail = TestBuilder::new().login().user_detail.unwrap();
for password in invalid_password_test_case() {
2021-08-31 15:01:46 +00:00
let request = UpdateUserRequest::new(&user_detail.id).password(&password);
2021-08-31 15:01:46 +00:00
TestBuilder::new()
2021-08-24 05:10:53 +00:00
.event(UpdateUser)
.request(request)
.sync_send()
.assert_error();
}
}
#[test]
#[serial]
fn user_update_with_invalid_name() {
2021-08-31 15:01:46 +00:00
let user_detail = TestBuilder::new().login().user_detail.unwrap();
let request = UpdateUserRequest::new(&user_detail.id).name("");
2021-08-31 15:01:46 +00:00
TestBuilder::new()
2021-08-24 05:10:53 +00:00
.event(UpdateUser)
.request(request)
.sync_send()
.assert_error();
}