fix: anon user error (#3772)

* fix: anon user error

* ci: fix tests
This commit is contained in:
Nathan.fooo
2023-10-24 23:13:51 +08:00
committed by GitHub
parent 71f80be8f7
commit cceee80799
39 changed files with 227 additions and 230 deletions

View File

@ -14,7 +14,7 @@ async fn af_cloud_sign_up_test() {
}
#[tokio::test]
async fn af_cloud_update_user_metadata_of_open_ai_key() {
async fn af_cloud_update_user_metadata() {
if get_af_cloud_config().is_some() {
let test = EventIntegrationTest::new();
let user = test.af_cloud_sign_up().await;
@ -25,12 +25,17 @@ async fn af_cloud_update_user_metadata_of_open_ai_key() {
test
.update_user_profile(UpdateUserProfilePayloadPB {
id: user.id,
openai_key: Some("new openai_key".to_string()),
openai_key: Some("new openai key".to_string()),
stability_ai_key: Some("new stability ai 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());
assert_eq!(new_profile.openai_key, "new openai key".to_string());
assert_eq!(
new_profile.stability_ai_key,
"new stability ai key".to_string()
);
}
}

View File

@ -1,7 +1,7 @@
use nanoid::nanoid;
use event_integration::{event_builder::EventBuilder, EventIntegrationTest};
use flowy_user::entities::{UpdateUserProfilePayloadPB, UserProfilePB};
use flowy_user::entities::{AuthTypePB, UpdateUserProfilePayloadPB, UserProfilePB};
use flowy_user::{errors::ErrorCode, event_map::UserEvent::*};
use crate::user::local_test::helper::*;
@ -20,20 +20,24 @@ async fn user_profile_get_failed() {
}
#[tokio::test]
async fn user_profile_get() {
async fn anon_user_profile_get() {
let test = EventIntegrationTest::new();
let user_profile = test.init_user().await;
let user_profile = test.init_anon_user().await;
let user = EventBuilder::new(test.clone())
.event(GetUserProfile)
.sync_send()
.parse::<UserProfilePB>();
assert_eq!(user_profile, user);
assert_eq!(user_profile.id, user.id);
assert_eq!(user_profile.openai_key, user.openai_key);
assert_eq!(user_profile.stability_ai_key, user.stability_ai_key);
assert_eq!(user_profile.workspace_id, user.workspace_id);
assert_eq!(user_profile.auth_type, AuthTypePB::Local);
}
#[tokio::test]
async fn user_update_with_name() {
let sdk = EventIntegrationTest::new();
let user = sdk.init_user().await;
let user = sdk.init_anon_user().await;
let new_name = "hello_world".to_owned();
let request = UpdateUserProfilePayloadPB::new(user.id).name(&new_name);
let _ = EventBuilder::new(sdk.clone())
@ -52,7 +56,7 @@ async fn user_update_with_name() {
#[tokio::test]
async fn user_update_with_ai_key() {
let sdk = EventIntegrationTest::new();
let user = sdk.init_user().await;
let user = sdk.init_anon_user().await;
let openai_key = "openai_key".to_owned();
let stability_ai_key = "stability_ai_key".to_owned();
let request = UpdateUserProfilePayloadPB::new(user.id)
@ -73,9 +77,9 @@ async fn user_update_with_ai_key() {
}
#[tokio::test]
async fn user_update_with_email() {
async fn anon_user_update_with_email() {
let sdk = EventIntegrationTest::new();
let user = sdk.init_user().await;
let user = sdk.init_anon_user().await;
let new_email = format!("{}@gmail.com", nanoid!(6));
let request = UpdateUserProfilePayloadPB::new(user.id).email(&new_email);
let _ = EventBuilder::new(sdk.clone())
@ -87,13 +91,14 @@ async fn user_update_with_email() {
.sync_send()
.parse::<UserProfilePB>();
assert_eq!(user_profile.email, new_email,);
// When the user is anonymous, the email is empty no matter what you set
assert!(user_profile.email.is_empty());
}
#[tokio::test]
async fn user_update_with_invalid_email() {
let test = EventIntegrationTest::new();
let user = test.init_user().await;
let user = test.init_anon_user().await;
for email in invalid_email_test_case() {
let request = UpdateUserProfilePayloadPB::new(user.id).email(&email);
assert_eq!(
@ -112,7 +117,7 @@ async fn user_update_with_invalid_email() {
#[tokio::test]
async fn user_update_with_invalid_password() {
let test = EventIntegrationTest::new();
let user = test.init_user().await;
let user = test.init_anon_user().await;
for password in invalid_password_test_case() {
let request = UpdateUserProfilePayloadPB::new(user.id).password(&password);
@ -129,7 +134,7 @@ async fn user_update_with_invalid_password() {
#[tokio::test]
async fn user_update_with_invalid_name() {
let test = EventIntegrationTest::new();
let user = test.init_user().await;
let user = test.init_anon_user().await;
let request = UpdateUserProfilePayloadPB::new(user.id).name("");
assert!(EventBuilder::new(test.clone())
.event(UpdateUserProfile)

View File

@ -194,17 +194,6 @@ async fn sign_up_as_guest_and_then_update_to_existing_cloud_user_test() {
}
}
#[tokio::test]
async fn check_not_exist_user_test() {
if let Some(test) = FlowySupabaseTest::new() {
let err = test
.check_user_with_uuid(&uuid::Uuid::new_v4().to_string())
.await
.unwrap_err();
assert_eq!(err.code, ErrorCode::RecordNotFound);
}
}
#[tokio::test]
async fn get_user_profile_test() {
if let Some(test) = FlowySupabaseTest::new() {