2021-09-01 09:57:06 +00:00
|
|
|
use crate::helper::*;
|
2021-09-28 07:29:29 +00:00
|
|
|
use flowy_test::{builder::UserTest, FlowyTest};
|
2021-09-01 09:57:06 +00:00
|
|
|
use flowy_user::{errors::ErrorCode, event::UserEvent::*, prelude::*};
|
|
|
|
use serial_test::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[serial]
|
|
|
|
fn sign_up_with_invalid_email() {
|
|
|
|
for email in invalid_email_test_case() {
|
2021-09-28 07:29:29 +00:00
|
|
|
let test = FlowyTest::setup();
|
2021-09-01 09:57:06 +00:00
|
|
|
let request = SignUpRequest {
|
|
|
|
email: email.to_string(),
|
|
|
|
name: valid_name(),
|
2021-09-03 08:43:03 +00:00
|
|
|
password: login_password(),
|
2021-09-01 09:57:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(
|
2021-09-28 07:29:29 +00:00
|
|
|
UserTest::new(test.sdk)
|
|
|
|
.event(SignUp)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.error()
|
|
|
|
.code,
|
2021-09-01 09:57:06 +00:00
|
|
|
ErrorCode::EmailFormatInvalid
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[test]
|
|
|
|
#[serial]
|
|
|
|
fn sign_up_with_invalid_password() {
|
|
|
|
for password in invalid_password_test_case() {
|
2021-09-28 07:29:29 +00:00
|
|
|
let test = FlowyTest::setup();
|
2021-09-01 09:57:06 +00:00
|
|
|
let request = SignUpRequest {
|
|
|
|
email: random_email(),
|
|
|
|
name: valid_name(),
|
|
|
|
password,
|
|
|
|
};
|
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
UserTest::new(test.sdk)
|
|
|
|
.event(SignUp)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.assert_error();
|
2021-09-01 09:57:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
#[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;
|
2021-09-01 09:57:06 +00:00
|
|
|
|
|
|
|
let request = SignInRequest {
|
2021-09-28 07:29:29 +00:00
|
|
|
email: sign_up_context.user_profile.email.clone(),
|
|
|
|
password: sign_up_context.password.clone(),
|
2021-09-01 09:57:06 +00:00
|
|
|
};
|
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
let response = UserTest::new(test.sdk())
|
2021-09-01 09:57:06 +00:00
|
|
|
.event(SignIn)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
2021-09-04 08:53:58 +00:00
|
|
|
.parse::<UserProfile>();
|
2021-09-01 09:57:06 +00:00
|
|
|
dbg!(&response);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[serial]
|
|
|
|
fn sign_in_with_invalid_email() {
|
|
|
|
for email in invalid_email_test_case() {
|
2021-09-28 07:29:29 +00:00
|
|
|
let test = FlowyTest::setup();
|
2021-09-01 09:57:06 +00:00
|
|
|
let request = SignInRequest {
|
|
|
|
email: email.to_string(),
|
2021-09-03 08:43:03 +00:00
|
|
|
password: login_password(),
|
2021-09-01 09:57:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(
|
2021-09-28 07:29:29 +00:00
|
|
|
UserTest::new(test.sdk)
|
|
|
|
.event(SignIn)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.error()
|
|
|
|
.code,
|
2021-09-01 09:57:06 +00:00
|
|
|
ErrorCode::EmailFormatInvalid
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[serial]
|
|
|
|
fn sign_in_with_invalid_password() {
|
|
|
|
for password in invalid_password_test_case() {
|
2021-09-28 07:29:29 +00:00
|
|
|
let test = FlowyTest::setup();
|
|
|
|
|
2021-09-01 09:57:06 +00:00
|
|
|
let request = SignInRequest {
|
|
|
|
email: random_email(),
|
|
|
|
password,
|
|
|
|
};
|
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
UserTest::new(test.sdk)
|
|
|
|
.event(SignIn)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.assert_error();
|
2021-09-01 09:57:06 +00:00
|
|
|
}
|
|
|
|
}
|