add frontend folder

This commit is contained in:
appflowy
2021-11-20 09:32:46 +08:00
parent f93f012bc8
commit 8f1d62f115
1697 changed files with 754 additions and 104 deletions

View File

@ -0,0 +1,108 @@
use crate::helper::*;
use flowy_test::{builder::UserTest, FlowyTest};
use flowy_user::{errors::ErrorCode, event::UserEvent::*, prelude::*};
#[tokio::test]
async fn sign_up_with_invalid_email() {
for email in invalid_email_test_case() {
let test = FlowyTest::setup();
let request = SignUpRequest {
email: email.to_string(),
name: valid_name(),
password: login_password(),
};
assert_eq!(
UserTest::new(test.sdk)
.event(SignUp)
.request(request)
.async_send()
.await
.error()
.code,
ErrorCode::EmailFormatInvalid.value()
);
}
}
#[tokio::test]
async fn sign_up_with_invalid_password() {
for password in invalid_password_test_case() {
let test = FlowyTest::setup();
let request = SignUpRequest {
email: random_email(),
name: valid_name(),
password,
};
UserTest::new(test.sdk)
.event(SignUp)
.request(request)
.async_send()
.await
.assert_error();
}
}
#[tokio::test]
async fn sign_in_success() {
let test = FlowyTest::setup();
let _ = UserTest::new(test.sdk()).event(SignOut).sync_send();
let sign_up_context = test.sign_up().await;
let request = SignInRequest {
email: sign_up_context.user_profile.email.clone(),
password: sign_up_context.password.clone(),
name: "".to_string(),
};
let response = UserTest::new(test.sdk())
.event(SignIn)
.request(request)
.async_send()
.await
.parse::<UserProfile>();
dbg!(&response);
}
#[tokio::test]
async fn sign_in_with_invalid_email() {
for email in invalid_email_test_case() {
let test = FlowyTest::setup();
let request = SignInRequest {
email: email.to_string(),
password: login_password(),
name: "".to_string(),
};
assert_eq!(
UserTest::new(test.sdk)
.event(SignIn)
.request(request)
.async_send()
.await
.error()
.code,
ErrorCode::EmailFormatInvalid.value()
);
}
}
#[tokio::test]
async fn sign_in_with_invalid_password() {
for password in invalid_password_test_case() {
let test = FlowyTest::setup();
let request = SignInRequest {
email: random_email(),
password,
name: "".to_string(),
};
UserTest::new(test.sdk)
.event(SignIn)
.request(request)
.async_send()
.await
.assert_error();
}
}

View File

@ -0,0 +1,40 @@
pub use flowy_test::{
builder::*,
prelude::{login_password, random_email},
};
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() }

View File

@ -0,0 +1,3 @@
mod auth_test;
mod helper;
mod user_profile_test;

View File

@ -0,0 +1,126 @@
use crate::helper::*;
use flowy_test::{builder::UserTest, FlowyTest};
use flowy_user::{errors::ErrorCode, event::UserEvent::*, prelude::*};
use lib_infra::uuid;
use serial_test::*;
#[tokio::test]
async fn user_profile_get_failed() {
let test = FlowyTest::setup();
let result = UserTest::new(test.sdk)
.event(GetUserProfile)
.assert_error()
.async_send()
.await;
assert!(result.user_profile().is_none())
}
#[tokio::test]
#[serial]
async fn user_profile_get() {
let test = FlowyTest::setup();
let user_profile = test.init_user().await;
let user = UserTest::new(test.sdk.clone())
.event(GetUserProfile)
.sync_send()
.parse::<UserProfile>();
assert_eq!(user_profile, user);
}
#[tokio::test]
#[serial]
async fn user_update_with_name() {
let test = FlowyTest::setup();
let user = test.init_user().await;
let new_name = "hello_world".to_owned();
let request = UpdateUserRequest::new(&user.id).name(&new_name);
let _ = UserTest::new(test.sdk()).event(UpdateUser).request(request).sync_send();
let user_profile = UserTest::new(test.sdk())
.event(GetUserProfile)
.assert_error()
.sync_send()
.parse::<UserProfile>();
assert_eq!(user_profile.name, new_name,);
}
#[tokio::test]
#[serial]
async fn user_update_with_email() {
let test = FlowyTest::setup();
let user = test.init_user().await;
let new_email = format!("{}@gmail.com", uuid());
let request = UpdateUserRequest::new(&user.id).email(&new_email);
let _ = UserTest::new(test.sdk()).event(UpdateUser).request(request).sync_send();
let user_profile = UserTest::new(test.sdk())
.event(GetUserProfile)
.assert_error()
.sync_send()
.parse::<UserProfile>();
assert_eq!(user_profile.email, new_email,);
}
#[tokio::test]
#[serial]
async fn user_update_with_password() {
let test = FlowyTest::setup();
let user = test.init_user().await;
let new_password = "H123world!".to_owned();
let request = UpdateUserRequest::new(&user.id).password(&new_password);
let _ = UserTest::new(test.sdk())
.event(UpdateUser)
.request(request)
.sync_send()
.assert_success();
}
#[tokio::test]
#[serial]
async fn user_update_with_invalid_email() {
let test = FlowyTest::setup();
let user = test.init_user().await;
for email in invalid_email_test_case() {
let request = UpdateUserRequest::new(&user.id).email(&email);
assert_eq!(
UserTest::new(test.sdk())
.event(UpdateUser)
.request(request)
.sync_send()
.error()
.code,
ErrorCode::EmailFormatInvalid.value()
);
}
}
#[tokio::test]
#[serial]
async fn user_update_with_invalid_password() {
let test = FlowyTest::setup();
let user = test.init_user().await;
for password in invalid_password_test_case() {
let request = UpdateUserRequest::new(&user.id).password(&password);
UserTest::new(test.sdk())
.event(UpdateUser)
.request(request)
.sync_send()
.assert_error();
}
}
#[tokio::test]
#[serial]
async fn user_update_with_invalid_name() {
let test = FlowyTest::setup();
let user = test.init_user().await;
let request = UpdateUserRequest::new(&user.id).name("");
UserTest::new(test.sdk())
.event(UpdateUser)
.request(request)
.sync_send()
.assert_error();
}