2021-09-01 09:57:06 +00:00
|
|
|
use crate::helper::*;
|
2021-12-08 09:33:22 +00:00
|
|
|
use flowy_test::{event_builder::UserModuleEventBuilder, FlowySDKTest};
|
2022-01-28 02:56:55 +00:00
|
|
|
use flowy_user::{errors::ErrorCode, event_map::UserEvent::*};
|
2022-02-24 13:49:18 +00:00
|
|
|
use flowy_user_data_model::entities::{SignInPayload, SignUpPayload, UserProfile};
|
2021-09-01 09:57:06 +00:00
|
|
|
|
2021-10-18 10:40:15 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn sign_up_with_invalid_email() {
|
2021-09-01 09:57:06 +00:00
|
|
|
for email in invalid_email_test_case() {
|
2022-01-07 09:37:11 +00:00
|
|
|
let sdk = FlowySDKTest::default();
|
2022-02-24 13:49:18 +00:00
|
|
|
let request = SignUpPayload {
|
2021-09-01 09:57:06 +00:00
|
|
|
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-12-08 09:33:22 +00:00
|
|
|
UserModuleEventBuilder::new(sdk)
|
2021-09-28 07:29:29 +00:00
|
|
|
.event(SignUp)
|
2022-02-24 13:49:18 +00:00
|
|
|
.payload(request)
|
2021-10-18 10:40:15 +00:00
|
|
|
.async_send()
|
|
|
|
.await
|
2021-09-28 07:29:29 +00:00
|
|
|
.error()
|
|
|
|
.code,
|
2021-11-07 13:45:18 +00:00
|
|
|
ErrorCode::EmailFormatInvalid.value()
|
2021-09-01 09:57:06 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 10:40:15 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn sign_up_with_invalid_password() {
|
2021-09-01 09:57:06 +00:00
|
|
|
for password in invalid_password_test_case() {
|
2022-01-07 09:37:11 +00:00
|
|
|
let sdk = FlowySDKTest::default();
|
2022-02-24 13:49:18 +00:00
|
|
|
let request = SignUpPayload {
|
2021-09-01 09:57:06 +00:00
|
|
|
email: random_email(),
|
|
|
|
name: valid_name(),
|
|
|
|
password,
|
|
|
|
};
|
|
|
|
|
2021-12-08 09:33:22 +00:00
|
|
|
UserModuleEventBuilder::new(sdk)
|
2021-09-28 07:29:29 +00:00
|
|
|
.event(SignUp)
|
2022-02-24 13:49:18 +00:00
|
|
|
.payload(request)
|
2021-10-18 10:40:15 +00:00
|
|
|
.async_send()
|
|
|
|
.await
|
2021-09-28 07:29:29 +00:00
|
|
|
.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() {
|
2022-01-07 09:37:11 +00:00
|
|
|
let test = FlowySDKTest::default();
|
2021-12-08 09:33:22 +00:00
|
|
|
let _ = UserModuleEventBuilder::new(test.clone()).event(SignOut).sync_send();
|
2021-09-28 07:29:29 +00:00
|
|
|
let sign_up_context = test.sign_up().await;
|
2021-09-01 09:57:06 +00:00
|
|
|
|
2022-02-24 13:49:18 +00:00
|
|
|
let request = SignInPayload {
|
2021-09-28 07:29:29 +00:00
|
|
|
email: sign_up_context.user_profile.email.clone(),
|
|
|
|
password: sign_up_context.password.clone(),
|
2021-11-07 13:45:18 +00:00
|
|
|
name: "".to_string(),
|
2021-09-01 09:57:06 +00:00
|
|
|
};
|
|
|
|
|
2021-12-08 09:33:22 +00:00
|
|
|
let response = UserModuleEventBuilder::new(test.clone())
|
2021-09-01 09:57:06 +00:00
|
|
|
.event(SignIn)
|
2022-02-24 13:49:18 +00:00
|
|
|
.payload(request)
|
2021-10-18 10:40:15 +00:00
|
|
|
.async_send()
|
|
|
|
.await
|
2021-09-04 08:53:58 +00:00
|
|
|
.parse::<UserProfile>();
|
2021-09-01 09:57:06 +00:00
|
|
|
dbg!(&response);
|
|
|
|
}
|
|
|
|
|
2021-10-18 10:40:15 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn sign_in_with_invalid_email() {
|
2021-09-01 09:57:06 +00:00
|
|
|
for email in invalid_email_test_case() {
|
2022-01-07 09:37:11 +00:00
|
|
|
let sdk = FlowySDKTest::default();
|
2022-02-24 13:49:18 +00:00
|
|
|
let request = SignInPayload {
|
2021-09-01 09:57:06 +00:00
|
|
|
email: email.to_string(),
|
2021-09-03 08:43:03 +00:00
|
|
|
password: login_password(),
|
2021-11-07 13:45:18 +00:00
|
|
|
name: "".to_string(),
|
2021-09-01 09:57:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(
|
2021-12-08 09:33:22 +00:00
|
|
|
UserModuleEventBuilder::new(sdk)
|
2021-09-28 07:29:29 +00:00
|
|
|
.event(SignIn)
|
2022-02-24 13:49:18 +00:00
|
|
|
.payload(request)
|
2021-10-18 10:40:15 +00:00
|
|
|
.async_send()
|
|
|
|
.await
|
2021-09-28 07:29:29 +00:00
|
|
|
.error()
|
|
|
|
.code,
|
2021-11-07 13:45:18 +00:00
|
|
|
ErrorCode::EmailFormatInvalid.value()
|
2021-09-01 09:57:06 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 10:40:15 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn sign_in_with_invalid_password() {
|
2021-09-01 09:57:06 +00:00
|
|
|
for password in invalid_password_test_case() {
|
2022-01-07 09:37:11 +00:00
|
|
|
let sdk = FlowySDKTest::default();
|
2021-09-28 07:29:29 +00:00
|
|
|
|
2022-02-24 13:49:18 +00:00
|
|
|
let request = SignInPayload {
|
2021-09-01 09:57:06 +00:00
|
|
|
email: random_email(),
|
|
|
|
password,
|
2021-11-07 13:45:18 +00:00
|
|
|
name: "".to_string(),
|
2021-09-01 09:57:06 +00:00
|
|
|
};
|
|
|
|
|
2021-12-08 09:33:22 +00:00
|
|
|
UserModuleEventBuilder::new(sdk)
|
2021-09-28 07:29:29 +00:00
|
|
|
.event(SignIn)
|
2022-02-24 13:49:18 +00:00
|
|
|
.payload(request)
|
2021-10-18 10:40:15 +00:00
|
|
|
.async_send()
|
|
|
|
.await
|
2021-09-28 07:29:29 +00:00
|
|
|
.assert_error();
|
2021-09-01 09:57:06 +00:00
|
|
|
}
|
|
|
|
}
|