mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: integrate postgres storage (#2604)
* chore: env config * chore: get user workspace * feat: enable postgres storage * chore: add new env * chore: add set env ffi * chore: pass env before backend init * chore: update * fix: ci tests * chore: commit the generate env file * chore: remove unused import
This commit is contained in:
123
frontend/rust-lib/flowy-test/tests/user/local_test/auth_test.rs
Normal file
123
frontend/rust-lib/flowy-test/tests/user/local_test/auth_test.rs
Normal file
@ -0,0 +1,123 @@
|
||||
use flowy_test::user_event::*;
|
||||
use flowy_test::{event_builder::EventBuilder, FlowyCoreTest};
|
||||
use flowy_user::entities::{AuthTypePB, SignInPayloadPB, SignUpPayloadPB, UserProfilePB};
|
||||
use flowy_user::errors::ErrorCode;
|
||||
use flowy_user::event_map::UserEvent::*;
|
||||
|
||||
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 request = SignUpPayloadPB {
|
||||
email: email.to_string(),
|
||||
name: valid_name(),
|
||||
password: login_password(),
|
||||
auth_type: AuthTypePB::Local,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
EventBuilder::new(sdk)
|
||||
.event(SignUp)
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
.unwrap()
|
||||
.code,
|
||||
ErrorCode::EmailFormatInvalid.value()
|
||||
);
|
||||
}
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn sign_up_with_long_password() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let request = SignUpPayloadPB {
|
||||
email: random_email(),
|
||||
name: valid_name(),
|
||||
password: "1234".repeat(100).as_str().to_string(),
|
||||
auth_type: AuthTypePB::Local,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
EventBuilder::new(sdk)
|
||||
.event(SignUp)
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
.unwrap()
|
||||
.code,
|
||||
ErrorCode::PasswordTooLong.value()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sign_in_success() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let _ = EventBuilder::new(test.clone()).event(SignOut).sync_send();
|
||||
let sign_up_context = test.sign_up().await;
|
||||
|
||||
let request = SignInPayloadPB {
|
||||
email: sign_up_context.user_profile.email.clone(),
|
||||
password: sign_up_context.password.clone(),
|
||||
name: "".to_string(),
|
||||
auth_type: AuthTypePB::Local,
|
||||
};
|
||||
|
||||
let response = EventBuilder::new(test.clone())
|
||||
.event(SignIn)
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<UserProfilePB>();
|
||||
dbg!(&response);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sign_in_with_invalid_email() {
|
||||
for email in invalid_email_test_case() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let request = SignInPayloadPB {
|
||||
email: email.to_string(),
|
||||
password: login_password(),
|
||||
name: "".to_string(),
|
||||
auth_type: AuthTypePB::Local,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
EventBuilder::new(sdk)
|
||||
.event(SignIn)
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
.unwrap()
|
||||
.code,
|
||||
ErrorCode::EmailFormatInvalid.value()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sign_in_with_invalid_password() {
|
||||
for password in invalid_password_test_case() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
|
||||
let request = SignInPayloadPB {
|
||||
email: random_email(),
|
||||
password,
|
||||
name: "".to_string(),
|
||||
auth_type: AuthTypePB::Local,
|
||||
};
|
||||
|
||||
assert!(EventBuilder::new(sdk)
|
||||
.event(SignIn)
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
.is_some())
|
||||
}
|
||||
}
|
37
frontend/rust-lib/flowy-test/tests/user/local_test/helper.rs
Normal file
37
frontend/rust-lib/flowy-test/tests/user/local_test/helper.rs
Normal file
@ -0,0 +1,37 @@
|
||||
pub(crate) fn invalid_email_test_case() -> Vec<String> {
|
||||
// https://gist.github.com/cjaoude/fd9910626629b53c4d25
|
||||
vec![
|
||||
"annie@",
|
||||
"annie@gmail@",
|
||||
"#@%^%#$@#$@#.com",
|
||||
"@example.com",
|
||||
"Joe Smith <email@example.com>",
|
||||
"email.example.com",
|
||||
"email@example@example.com",
|
||||
"email@-example.com",
|
||||
"email@example..com",
|
||||
"あいうえお@example.com",
|
||||
/* The following email is valid according to the validate_email function return
|
||||
* ".email@example.com",
|
||||
* "email.@example.com",
|
||||
* "email..email@example.com",
|
||||
* "email@example",
|
||||
* "email@example.web",
|
||||
* "email@111.222.333.44444",
|
||||
* "Abc..123@example.com", */
|
||||
]
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub(crate) fn invalid_password_test_case() -> Vec<String> {
|
||||
vec!["123456", "1234".repeat(100).as_str()]
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub(crate) fn valid_name() -> String {
|
||||
"AppFlowy".to_string()
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
mod auth_test;
|
||||
mod helper;
|
||||
mod user_profile_test;
|
@ -0,0 +1,115 @@
|
||||
use crate::user::local_test::helper::*;
|
||||
use flowy_test::{event_builder::EventBuilder, FlowyCoreTest};
|
||||
use flowy_user::entities::{UpdateUserProfilePayloadPB, UserProfilePB};
|
||||
use flowy_user::{errors::ErrorCode, event_map::UserEvent::*};
|
||||
use nanoid::nanoid;
|
||||
|
||||
// use serial_test::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_profile_get_failed() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let result = EventBuilder::new(sdk)
|
||||
.event(GetUserProfile)
|
||||
.async_send()
|
||||
.await
|
||||
.error();
|
||||
assert!(result.is_some())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_profile_get() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let user_profile = test.init_user().await;
|
||||
let user = EventBuilder::new(test.clone())
|
||||
.event(GetUserProfile)
|
||||
.sync_send()
|
||||
.parse::<UserProfilePB>();
|
||||
assert_eq!(user_profile, user);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_update_with_name() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let user = sdk.init_user().await;
|
||||
let new_name = "hello_world".to_owned();
|
||||
let request = UpdateUserProfilePayloadPB::new(user.id).name(&new_name);
|
||||
let _ = EventBuilder::new(sdk.clone())
|
||||
.event(UpdateUserProfile)
|
||||
.payload(request)
|
||||
.sync_send();
|
||||
|
||||
let user_profile = EventBuilder::new(sdk.clone())
|
||||
.event(GetUserProfile)
|
||||
.sync_send()
|
||||
.parse::<UserProfilePB>();
|
||||
|
||||
assert_eq!(user_profile.name, new_name,);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_update_with_email() {
|
||||
let sdk = FlowyCoreTest::new();
|
||||
let user = sdk.init_user().await;
|
||||
let new_email = format!("{}@gmail.com", nanoid!(6));
|
||||
let request = UpdateUserProfilePayloadPB::new(user.id).email(&new_email);
|
||||
let _ = EventBuilder::new(sdk.clone())
|
||||
.event(UpdateUserProfile)
|
||||
.payload(request)
|
||||
.sync_send();
|
||||
let user_profile = EventBuilder::new(sdk.clone())
|
||||
.event(GetUserProfile)
|
||||
.sync_send()
|
||||
.parse::<UserProfilePB>();
|
||||
|
||||
assert_eq!(user_profile.email, new_email,);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_update_with_invalid_email() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let user = test.init_user().await;
|
||||
for email in invalid_email_test_case() {
|
||||
let request = UpdateUserProfilePayloadPB::new(user.id).email(&email);
|
||||
assert_eq!(
|
||||
EventBuilder::new(test.clone())
|
||||
.event(UpdateUserProfile)
|
||||
.payload(request)
|
||||
.sync_send()
|
||||
.error()
|
||||
.unwrap()
|
||||
.code,
|
||||
ErrorCode::EmailFormatInvalid.value()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_update_with_invalid_password() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let user = test.init_user().await;
|
||||
for password in invalid_password_test_case() {
|
||||
let request = UpdateUserProfilePayloadPB::new(user.id).password(&password);
|
||||
|
||||
assert!(EventBuilder::new(test.clone())
|
||||
.event(UpdateUserProfile)
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
.is_some());
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_update_with_invalid_name() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let user = test.init_user().await;
|
||||
let request = UpdateUserProfilePayloadPB::new(user.id).name("");
|
||||
assert!(EventBuilder::new(test.clone())
|
||||
.event(UpdateUserProfile)
|
||||
.payload(request)
|
||||
.sync_send()
|
||||
.error()
|
||||
.is_some())
|
||||
}
|
2
frontend/rust-lib/flowy-test/tests/user/mod.rs
Normal file
2
frontend/rust-lib/flowy-test/tests/user/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
mod local_test;
|
||||
mod supabase_test;
|
@ -0,0 +1,28 @@
|
||||
use crate::user::supabase_test::helper::get_supabase_config;
|
||||
|
||||
use flowy_test::{event_builder::EventBuilder, FlowyCoreTest};
|
||||
use flowy_user::entities::{AuthTypePB, ThirdPartyAuthPB, UserProfilePB};
|
||||
|
||||
use flowy_user::event_map::UserEvent::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[tokio::test]
|
||||
async fn sign_up_test() {
|
||||
if get_supabase_config().is_some() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let mut map = HashMap::new();
|
||||
map.insert("uuid".to_string(), uuid::Uuid::new_v4().to_string());
|
||||
let payload = ThirdPartyAuthPB {
|
||||
map,
|
||||
auth_type: AuthTypePB::Supabase,
|
||||
};
|
||||
|
||||
let response = EventBuilder::new(test.clone())
|
||||
.event(ThirdPartyAuth)
|
||||
.payload(payload)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<UserProfilePB>();
|
||||
dbg!(&response);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
use dotenv::dotenv;
|
||||
use flowy_server::supabase::SupabaseConfiguration;
|
||||
|
||||
/// In order to run this test, you need to create a .env file in the root directory of this project
|
||||
/// and add the following environment variables:
|
||||
/// - SUPABASE_URL
|
||||
/// - SUPABASE_ANON_KEY
|
||||
/// - SUPABASE_KEY
|
||||
/// - SUPABASE_JWT_SECRET
|
||||
///
|
||||
/// the .env file should look like this:
|
||||
/// SUPABASE_URL=https://<your-supabase-url>.supabase.co
|
||||
/// SUPABASE_ANON_KEY=<your-supabase-anon-key>
|
||||
/// SUPABASE_KEY=<your-supabase-key>
|
||||
/// SUPABASE_JWT_SECRET=<your-supabase-jwt-secret>
|
||||
///
|
||||
pub fn get_supabase_config() -> Option<SupabaseConfiguration> {
|
||||
dotenv().ok()?;
|
||||
SupabaseConfiguration::from_env().ok()
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
mod auth_test;
|
||||
mod helper;
|
||||
mod workspace_test;
|
@ -0,0 +1,38 @@
|
||||
use crate::user::supabase_test::helper::get_supabase_config;
|
||||
use flowy_folder2::entities::WorkspaceSettingPB;
|
||||
use flowy_folder2::event_map::FolderEvent::ReadCurrentWorkspace;
|
||||
|
||||
use flowy_test::{event_builder::EventBuilder, FlowyCoreTest};
|
||||
use flowy_user::entities::{AuthTypePB, ThirdPartyAuthPB, UserProfilePB};
|
||||
|
||||
use flowy_user::event_map::UserEvent::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[tokio::test]
|
||||
async fn initial_workspace_test() {
|
||||
if get_supabase_config().is_some() {
|
||||
let test = FlowyCoreTest::new();
|
||||
let mut map = HashMap::new();
|
||||
map.insert("uuid".to_string(), uuid::Uuid::new_v4().to_string());
|
||||
let payload = ThirdPartyAuthPB {
|
||||
map,
|
||||
auth_type: AuthTypePB::Supabase,
|
||||
};
|
||||
|
||||
let _ = EventBuilder::new(test.clone())
|
||||
.event(ThirdPartyAuth)
|
||||
.payload(payload)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<UserProfilePB>();
|
||||
|
||||
let workspace_settings = EventBuilder::new(test.clone())
|
||||
.event(ReadCurrentWorkspace)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<WorkspaceSettingPB>();
|
||||
|
||||
assert!(workspace_settings.latest_view.is_some());
|
||||
dbg!(&workspace_settings);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user