2021-07-19 16:15:20 +08:00
|
|
|
use crate::helper::*;
|
2021-12-08 17:33:22 +08:00
|
|
|
use flowy_test::{event_builder::UserModuleEventBuilder, FlowySDKTest};
|
2022-07-19 14:40:56 +08:00
|
|
|
use flowy_user::entities::{UpdateUserProfilePayloadPB, UserProfilePB};
|
2022-01-28 10:56:55 +08:00
|
|
|
use flowy_user::{errors::ErrorCode, event_map::UserEvent::*};
|
2022-04-11 15:27:03 +08:00
|
|
|
use nanoid::nanoid;
|
|
|
|
|
2022-03-19 16:23:34 +08:00
|
|
|
// use serial_test::*;
|
2021-07-19 16:15:20 +08:00
|
|
|
|
2021-10-18 18:40:15 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn user_profile_get_failed() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let sdk = FlowySDKTest::default();
|
|
|
|
let result = UserModuleEventBuilder::new(sdk)
|
|
|
|
.event(GetUserProfile)
|
|
|
|
.assert_error()
|
|
|
|
.async_send()
|
|
|
|
.await;
|
|
|
|
assert!(result.user_profile().is_none())
|
2021-09-01 17:57:06 +08:00
|
|
|
}
|
|
|
|
|
2021-09-28 15:29:29 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn user_profile_get() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let test = FlowySDKTest::default();
|
|
|
|
let user_profile = test.init_user().await;
|
|
|
|
let user = UserModuleEventBuilder::new(test.clone())
|
|
|
|
.event(GetUserProfile)
|
|
|
|
.sync_send()
|
|
|
|
.parse::<UserProfilePB>();
|
|
|
|
assert_eq!(user_profile, user);
|
2021-09-01 17:57:06 +08:00
|
|
|
}
|
|
|
|
|
2021-09-28 15:29:29 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn user_update_with_name() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let sdk = FlowySDKTest::default();
|
|
|
|
let user = sdk.init_user().await;
|
|
|
|
let new_name = "hello_world".to_owned();
|
2023-04-04 08:41:16 +08:00
|
|
|
let request = UpdateUserProfilePayloadPB::new(user.id).name(&new_name);
|
2023-02-13 09:29:49 +08:00
|
|
|
let _ = UserModuleEventBuilder::new(sdk.clone())
|
|
|
|
.event(UpdateUserProfile)
|
|
|
|
.payload(request)
|
|
|
|
.sync_send();
|
2021-08-31 23:01:46 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
let user_profile = UserModuleEventBuilder::new(sdk.clone())
|
|
|
|
.event(GetUserProfile)
|
|
|
|
.assert_error()
|
|
|
|
.sync_send()
|
|
|
|
.parse::<UserProfilePB>();
|
2021-07-19 16:15:20 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
assert_eq!(user_profile.name, new_name,);
|
2021-07-19 16:15:20 +08:00
|
|
|
}
|
|
|
|
|
2021-09-28 15:29:29 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn user_update_with_email() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let sdk = FlowySDKTest::default();
|
|
|
|
let user = sdk.init_user().await;
|
|
|
|
let new_email = format!("{}@gmail.com", nanoid!(6));
|
2023-04-04 08:41:16 +08:00
|
|
|
let request = UpdateUserProfilePayloadPB::new(user.id).email(&new_email);
|
2023-02-13 09:29:49 +08:00
|
|
|
let _ = UserModuleEventBuilder::new(sdk.clone())
|
|
|
|
.event(UpdateUserProfile)
|
|
|
|
.payload(request)
|
|
|
|
.sync_send();
|
|
|
|
let user_profile = UserModuleEventBuilder::new(sdk.clone())
|
|
|
|
.event(GetUserProfile)
|
|
|
|
.assert_error()
|
|
|
|
.sync_send()
|
|
|
|
.parse::<UserProfilePB>();
|
2021-07-19 16:15:20 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
assert_eq!(user_profile.email, new_email,);
|
2021-07-19 16:15:20 +08:00
|
|
|
}
|
|
|
|
|
2021-09-28 15:29:29 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn user_update_with_password() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let sdk = FlowySDKTest::default();
|
|
|
|
let user = sdk.init_user().await;
|
|
|
|
let new_password = "H123world!".to_owned();
|
2023-04-04 08:41:16 +08:00
|
|
|
let request = UpdateUserProfilePayloadPB::new(user.id).password(&new_password);
|
2021-07-19 16:15:20 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
let _ = UserModuleEventBuilder::new(sdk.clone())
|
|
|
|
.event(UpdateUserProfile)
|
|
|
|
.payload(request)
|
|
|
|
.sync_send()
|
|
|
|
.assert_success();
|
2021-07-19 16:15:20 +08:00
|
|
|
}
|
|
|
|
|
2021-09-28 15:29:29 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn user_update_with_invalid_email() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let test = FlowySDKTest::default();
|
|
|
|
let user = test.init_user().await;
|
|
|
|
for email in invalid_email_test_case() {
|
2023-04-04 08:41:16 +08:00
|
|
|
let request = UpdateUserProfilePayloadPB::new(user.id).email(&email);
|
2023-02-13 09:29:49 +08:00
|
|
|
assert_eq!(
|
|
|
|
UserModuleEventBuilder::new(test.clone())
|
|
|
|
.event(UpdateUserProfile)
|
|
|
|
.payload(request)
|
|
|
|
.sync_send()
|
|
|
|
.error()
|
|
|
|
.code,
|
|
|
|
ErrorCode::EmailFormatInvalid.value()
|
|
|
|
);
|
|
|
|
}
|
2021-07-19 16:15:20 +08:00
|
|
|
}
|
|
|
|
|
2021-09-28 15:29:29 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn user_update_with_invalid_password() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let test = FlowySDKTest::default();
|
|
|
|
let user = test.init_user().await;
|
|
|
|
for password in invalid_password_test_case() {
|
2023-04-04 08:41:16 +08:00
|
|
|
let request = UpdateUserProfilePayloadPB::new(user.id).password(&password);
|
2021-07-19 16:15:20 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
UserModuleEventBuilder::new(test.clone())
|
|
|
|
.event(UpdateUserProfile)
|
|
|
|
.payload(request)
|
|
|
|
.sync_send()
|
|
|
|
.assert_error();
|
|
|
|
}
|
2021-07-19 16:15:20 +08:00
|
|
|
}
|
|
|
|
|
2021-09-28 15:29:29 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn user_update_with_invalid_name() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let test = FlowySDKTest::default();
|
|
|
|
let user = test.init_user().await;
|
2023-04-04 08:41:16 +08:00
|
|
|
let request = UpdateUserProfilePayloadPB::new(user.id).name("");
|
2023-02-13 09:29:49 +08:00
|
|
|
UserModuleEventBuilder::new(test.clone())
|
|
|
|
.event(UpdateUserProfile)
|
|
|
|
.payload(request)
|
|
|
|
.sync_send()
|
|
|
|
.assert_error();
|
2021-07-19 16:15:20 +08:00
|
|
|
}
|