mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: save user metadata (#3754)
* feat: save user metadata * chore: update client api * refactor: separate test methods * chore: save updated at * chore: clippy * chore: fix test
This commit is contained in:
@ -1,13 +1,36 @@
|
||||
use event_integration::FlowyCoreTest;
|
||||
use event_integration::EventIntegrationTest;
|
||||
use flowy_user::entities::UpdateUserProfilePayloadPB;
|
||||
|
||||
use crate::util::{generate_test_email, get_af_cloud_config};
|
||||
|
||||
#[tokio::test]
|
||||
async fn af_cloud_sign_up_test() {
|
||||
if get_af_cloud_config().is_some() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let test = EventIntegrationTest::new();
|
||||
let email = generate_test_email();
|
||||
let user = test.af_cloud_sign_in_with_email(&email).await.unwrap();
|
||||
assert_eq!(user.email, email);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn af_cloud_update_user_metadata_of_open_ai_key() {
|
||||
if get_af_cloud_config().is_some() {
|
||||
let test = EventIntegrationTest::new();
|
||||
let user = test.af_cloud_sign_up().await;
|
||||
|
||||
let old_profile = test.get_user_profile().await.unwrap();
|
||||
assert_eq!(old_profile.openai_key, "".to_string());
|
||||
|
||||
test
|
||||
.update_user_profile(UpdateUserProfilePayloadPB {
|
||||
id: user.id,
|
||||
openai_key: Some("new openai_key".to_string()),
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
|
||||
let new_profile = test.get_user_profile().await.unwrap();
|
||||
assert_eq!(new_profile.openai_key, "new openai_key".to_string());
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use event_integration::user_event::*;
|
||||
use event_integration::{event_builder::EventBuilder, FlowyCoreTest};
|
||||
use event_integration::test_user::{login_password, unique_email};
|
||||
use event_integration::{event_builder::EventBuilder, EventIntegrationTest};
|
||||
use flowy_user::entities::{AuthTypePB, SignInPayloadPB, SignUpPayloadPB};
|
||||
use flowy_user::errors::ErrorCode;
|
||||
use flowy_user::event_map::UserEvent::*;
|
||||
@ -9,7 +9,7 @@ use crate::user::local_test::helper::*;
|
||||
#[tokio::test]
|
||||
async fn sign_up_with_invalid_email() {
|
||||
for email in invalid_email_test_case() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let sdk = EventIntegrationTest::new();
|
||||
let request = SignUpPayloadPB {
|
||||
email: email.to_string(),
|
||||
name: valid_name(),
|
||||
@ -33,9 +33,9 @@ async fn sign_up_with_invalid_email() {
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn sign_up_with_long_password() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let sdk = EventIntegrationTest::new();
|
||||
let request = SignUpPayloadPB {
|
||||
email: random_email(),
|
||||
email: unique_email(),
|
||||
name: valid_name(),
|
||||
password: "1234".repeat(100).as_str().to_string(),
|
||||
auth_type: AuthTypePB::Local,
|
||||
@ -58,7 +58,7 @@ async fn sign_up_with_long_password() {
|
||||
#[tokio::test]
|
||||
async fn sign_in_with_invalid_email() {
|
||||
for email in invalid_email_test_case() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let sdk = EventIntegrationTest::new();
|
||||
let request = SignInPayloadPB {
|
||||
email: email.to_string(),
|
||||
password: login_password(),
|
||||
@ -84,10 +84,10 @@ async fn sign_in_with_invalid_email() {
|
||||
#[tokio::test]
|
||||
async fn sign_in_with_invalid_password() {
|
||||
for password in invalid_password_test_case() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let sdk = EventIntegrationTest::new();
|
||||
|
||||
let request = SignInPayloadPB {
|
||||
email: random_email(),
|
||||
email: unique_email(),
|
||||
password,
|
||||
name: "".to_string(),
|
||||
auth_type: AuthTypePB::Local,
|
||||
|
@ -1,13 +1,13 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use event_integration::event_builder::EventBuilder;
|
||||
use event_integration::FlowyCoreTest;
|
||||
use event_integration::EventIntegrationTest;
|
||||
use flowy_user::entities::{ReminderPB, RepeatedReminderPB};
|
||||
use flowy_user::event_map::UserEvent::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_update_with_name() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let sdk = EventIntegrationTest::new();
|
||||
let _ = sdk.sign_up_as_guest().await;
|
||||
let mut meta = HashMap::new();
|
||||
meta.insert("object_id".to_string(), "".to_string());
|
||||
|
@ -1,14 +1,16 @@
|
||||
use crate::user::local_test::helper::*;
|
||||
use event_integration::{event_builder::EventBuilder, FlowyCoreTest};
|
||||
use nanoid::nanoid;
|
||||
|
||||
use event_integration::{event_builder::EventBuilder, EventIntegrationTest};
|
||||
use flowy_user::entities::{UpdateUserProfilePayloadPB, UserProfilePB};
|
||||
use flowy_user::{errors::ErrorCode, event_map::UserEvent::*};
|
||||
use nanoid::nanoid;
|
||||
|
||||
use crate::user::local_test::helper::*;
|
||||
|
||||
// use serial_test::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_profile_get_failed() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let sdk = EventIntegrationTest::new();
|
||||
let result = EventBuilder::new(sdk)
|
||||
.event(GetUserProfile)
|
||||
.async_send()
|
||||
@ -19,7 +21,7 @@ async fn user_profile_get_failed() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_profile_get() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let test = EventIntegrationTest::new();
|
||||
let user_profile = test.init_user().await;
|
||||
let user = EventBuilder::new(test.clone())
|
||||
.event(GetUserProfile)
|
||||
@ -30,7 +32,7 @@ async fn user_profile_get() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_update_with_name() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let sdk = EventIntegrationTest::new();
|
||||
let user = sdk.init_user().await;
|
||||
let new_name = "hello_world".to_owned();
|
||||
let request = UpdateUserProfilePayloadPB::new(user.id).name(&new_name);
|
||||
@ -49,7 +51,7 @@ async fn user_update_with_name() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_update_with_ai_key() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let sdk = EventIntegrationTest::new();
|
||||
let user = sdk.init_user().await;
|
||||
let openai_key = "openai_key".to_owned();
|
||||
let stability_ai_key = "stability_ai_key".to_owned();
|
||||
@ -72,7 +74,7 @@ async fn user_update_with_ai_key() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_update_with_email() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let sdk = EventIntegrationTest::new();
|
||||
let user = sdk.init_user().await;
|
||||
let new_email = format!("{}@gmail.com", nanoid!(6));
|
||||
let request = UpdateUserProfilePayloadPB::new(user.id).email(&new_email);
|
||||
@ -90,7 +92,7 @@ async fn user_update_with_email() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_update_with_invalid_email() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let test = EventIntegrationTest::new();
|
||||
let user = test.init_user().await;
|
||||
for email in invalid_email_test_case() {
|
||||
let request = UpdateUserProfilePayloadPB::new(user.id).email(&email);
|
||||
@ -109,7 +111,7 @@ async fn user_update_with_invalid_email() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_update_with_invalid_password() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let test = EventIntegrationTest::new();
|
||||
let user = test.init_user().await;
|
||||
for password in invalid_password_test_case() {
|
||||
let request = UpdateUserProfilePayloadPB::new(user.id).password(&password);
|
||||
@ -126,7 +128,7 @@ async fn user_update_with_invalid_password() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_update_with_invalid_name() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let test = EventIntegrationTest::new();
|
||||
let user = test.init_user().await;
|
||||
let request = UpdateUserProfilePayloadPB::new(user.id).name("");
|
||||
assert!(EventBuilder::new(test.clone())
|
||||
|
@ -1,4 +1,4 @@
|
||||
use event_integration::FlowyCoreTest;
|
||||
use event_integration::EventIntegrationTest;
|
||||
use flowy_core::DEFAULT_NAME;
|
||||
use flowy_folder2::entities::ViewLayoutPB;
|
||||
|
||||
@ -11,7 +11,7 @@ async fn migrate_historical_empty_document_test() {
|
||||
"historical_empty_document",
|
||||
)
|
||||
.unwrap();
|
||||
let test = FlowyCoreTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string());
|
||||
let test = EventIntegrationTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string());
|
||||
|
||||
let views = test.get_all_workspace_views().await;
|
||||
assert_eq!(views.len(), 3);
|
||||
|
@ -1,4 +1,4 @@
|
||||
use event_integration::FlowyCoreTest;
|
||||
use event_integration::EventIntegrationTest;
|
||||
use flowy_core::DEFAULT_NAME;
|
||||
use flowy_folder2::entities::ViewLayoutPB;
|
||||
|
||||
@ -11,7 +11,7 @@ async fn migrate_020_historical_empty_document_test() {
|
||||
"020_historical_user_data",
|
||||
)
|
||||
.unwrap();
|
||||
let test = FlowyCoreTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string());
|
||||
let test = EventIntegrationTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string());
|
||||
|
||||
let mut views = test.get_all_workspace_views().await;
|
||||
assert_eq!(views.len(), 1);
|
||||
|
@ -10,7 +10,7 @@ use serde_json::json;
|
||||
|
||||
use event_integration::document::document_event::DocumentEventTest;
|
||||
use event_integration::event_builder::EventBuilder;
|
||||
use event_integration::FlowyCoreTest;
|
||||
use event_integration::EventIntegrationTest;
|
||||
use flowy_core::DEFAULT_NAME;
|
||||
use flowy_encrypt::decrypt_text;
|
||||
use flowy_server::supabase::define::{USER_EMAIL, USER_UUID};
|
||||
@ -23,7 +23,7 @@ use crate::util::*;
|
||||
#[tokio::test]
|
||||
async fn third_party_sign_up_test() {
|
||||
if get_supabase_config().is_some() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let test = EventIntegrationTest::new();
|
||||
let mut map = HashMap::new();
|
||||
map.insert(USER_UUID.to_string(), uuid::Uuid::new_v4().to_string());
|
||||
map.insert(
|
||||
@ -48,7 +48,7 @@ async fn third_party_sign_up_test() {
|
||||
#[tokio::test]
|
||||
async fn third_party_sign_up_with_encrypt_test() {
|
||||
if get_supabase_config().is_some() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let test = EventIntegrationTest::new();
|
||||
test.supabase_party_sign_up().await;
|
||||
let user_profile = test.get_user_profile().await.unwrap();
|
||||
assert!(user_profile.encryption_sign.is_empty());
|
||||
@ -65,7 +65,7 @@ async fn third_party_sign_up_with_encrypt_test() {
|
||||
#[tokio::test]
|
||||
async fn third_party_sign_up_with_duplicated_uuid() {
|
||||
if get_supabase_config().is_some() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let test = EventIntegrationTest::new();
|
||||
let email = format!("{}@appflowy.io", nanoid!(6));
|
||||
let mut map = HashMap::new();
|
||||
map.insert(USER_UUID.to_string(), uuid::Uuid::new_v4().to_string());
|
||||
@ -98,7 +98,7 @@ async fn third_party_sign_up_with_duplicated_uuid() {
|
||||
#[tokio::test]
|
||||
async fn third_party_sign_up_with_duplicated_email() {
|
||||
if get_supabase_config().is_some() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let test = EventIntegrationTest::new();
|
||||
let email = format!("{}@appflowy.io", nanoid!(6));
|
||||
test
|
||||
.supabase_sign_up_with_uuid(&uuid::Uuid::new_v4().to_string(), Some(email.clone()))
|
||||
@ -116,7 +116,7 @@ async fn third_party_sign_up_with_duplicated_email() {
|
||||
#[tokio::test]
|
||||
async fn sign_up_as_guest_and_then_update_to_new_cloud_user_test() {
|
||||
if get_supabase_config().is_some() {
|
||||
let test = FlowyCoreTest::new_with_guest_user().await;
|
||||
let test = EventIntegrationTest::new_with_guest_user().await;
|
||||
let old_views = test
|
||||
.folder_manager
|
||||
.get_current_workspace_views()
|
||||
@ -148,7 +148,7 @@ async fn sign_up_as_guest_and_then_update_to_new_cloud_user_test() {
|
||||
#[tokio::test]
|
||||
async fn sign_up_as_guest_and_then_update_to_existing_cloud_user_test() {
|
||||
if get_supabase_config().is_some() {
|
||||
let test = FlowyCoreTest::new_with_guest_user().await;
|
||||
let test = EventIntegrationTest::new_with_guest_user().await;
|
||||
let uuid = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
let email = format!("{}@appflowy.io", nanoid!(6));
|
||||
@ -260,7 +260,7 @@ async fn update_user_profile_with_existing_email_test() {
|
||||
#[tokio::test]
|
||||
async fn migrate_anon_document_on_cloud_signup() {
|
||||
if get_supabase_config().is_some() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let test = EventIntegrationTest::new();
|
||||
let user_profile = test.sign_up_as_guest().await.user_profile;
|
||||
|
||||
let view = test
|
||||
@ -305,7 +305,8 @@ async fn migrate_anon_data_on_cloud_signup() {
|
||||
"workspace_sync",
|
||||
)
|
||||
.unwrap();
|
||||
let test = FlowyCoreTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string());
|
||||
let test =
|
||||
EventIntegrationTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string());
|
||||
let user_profile = test.supabase_party_sign_up().await;
|
||||
|
||||
// Get the folder data from remote
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use event_integration::{event_builder::EventBuilder, FlowyCoreTest};
|
||||
use event_integration::{event_builder::EventBuilder, EventIntegrationTest};
|
||||
use flowy_folder2::entities::WorkspaceSettingPB;
|
||||
use flowy_folder2::event_map::FolderEvent::GetCurrentWorkspace;
|
||||
use flowy_server::supabase::define::{USER_EMAIL, USER_UUID};
|
||||
@ -12,7 +12,7 @@ use crate::util::*;
|
||||
#[tokio::test]
|
||||
async fn initial_workspace_test() {
|
||||
if get_supabase_config().is_some() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let test = EventIntegrationTest::new();
|
||||
let mut map = HashMap::new();
|
||||
map.insert(USER_UUID.to_string(), uuid::Uuid::new_v4().to_string());
|
||||
map.insert(
|
||||
|
Reference in New Issue
Block a user