2023-10-25 15:25:31 +08:00
|
|
|
use event_integration::user_event::{login_password, unique_email};
|
2023-10-24 20:11:06 +08:00
|
|
|
use event_integration::{event_builder::EventBuilder, EventIntegrationTest};
|
2023-08-12 17:36:31 +08:00
|
|
|
use flowy_user::entities::{AuthTypePB, SignInPayloadPB, SignUpPayloadPB};
|
2023-05-23 23:55:21 +08:00
|
|
|
use flowy_user::errors::ErrorCode;
|
|
|
|
use flowy_user::event_map::UserEvent::*;
|
2021-09-01 17:57:06 +08:00
|
|
|
|
2023-05-23 23:55:21 +08:00
|
|
|
use crate::user::local_test::helper::*;
|
2023-05-21 18:53:59 +08:00
|
|
|
|
2021-10-18 18:40:15 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn sign_up_with_invalid_email() {
|
2023-02-13 09:29:49 +08:00
|
|
|
for email in invalid_email_test_case() {
|
2023-10-30 12:35:06 +08:00
|
|
|
let sdk = EventIntegrationTest::new().await;
|
2023-02-13 09:29:49 +08:00
|
|
|
let request = SignUpPayloadPB {
|
|
|
|
email: email.to_string(),
|
|
|
|
name: valid_name(),
|
|
|
|
password: login_password(),
|
2023-05-21 18:53:59 +08:00
|
|
|
auth_type: AuthTypePB::Local,
|
2023-08-12 17:36:31 +08:00
|
|
|
device_id: "".to_string(),
|
2023-02-13 09:29:49 +08:00
|
|
|
};
|
2021-09-01 17:57:06 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
assert_eq!(
|
2023-05-23 23:55:21 +08:00
|
|
|
EventBuilder::new(sdk)
|
2023-02-13 09:29:49 +08:00
|
|
|
.event(SignUp)
|
|
|
|
.payload(request)
|
|
|
|
.async_send()
|
|
|
|
.await
|
|
|
|
.error()
|
2023-05-23 23:55:21 +08:00
|
|
|
.unwrap()
|
2023-02-13 09:29:49 +08:00
|
|
|
.code,
|
2023-08-22 00:19:15 +08:00
|
|
|
ErrorCode::EmailFormatInvalid
|
2023-02-13 09:29:49 +08:00
|
|
|
);
|
|
|
|
}
|
2021-09-01 17:57:06 +08:00
|
|
|
}
|
2021-10-18 18:40:15 +08:00
|
|
|
#[tokio::test]
|
2023-05-23 23:55:21 +08:00
|
|
|
async fn sign_up_with_long_password() {
|
2023-10-30 12:35:06 +08:00
|
|
|
let sdk = EventIntegrationTest::new().await;
|
2023-05-23 23:55:21 +08:00
|
|
|
let request = SignUpPayloadPB {
|
2023-10-24 20:11:06 +08:00
|
|
|
email: unique_email(),
|
2023-05-23 23:55:21 +08:00
|
|
|
name: valid_name(),
|
|
|
|
password: "1234".repeat(100).as_str().to_string(),
|
|
|
|
auth_type: AuthTypePB::Local,
|
2023-08-12 17:36:31 +08:00
|
|
|
device_id: "".to_string(),
|
2023-05-23 23:55:21 +08:00
|
|
|
};
|
2021-09-01 17:57:06 +08:00
|
|
|
|
2023-05-23 23:55:21 +08:00
|
|
|
assert_eq!(
|
|
|
|
EventBuilder::new(sdk)
|
2023-02-13 09:29:49 +08:00
|
|
|
.event(SignUp)
|
|
|
|
.payload(request)
|
|
|
|
.async_send()
|
|
|
|
.await
|
2023-05-23 23:55:21 +08:00
|
|
|
.error()
|
|
|
|
.unwrap()
|
|
|
|
.code,
|
2023-08-22 00:19:15 +08:00
|
|
|
ErrorCode::PasswordTooLong
|
2023-05-23 23:55:21 +08:00
|
|
|
);
|
2021-09-01 17:57:06 +08:00
|
|
|
}
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn sign_in_with_invalid_email() {
|
|
|
|
for email in invalid_email_test_case() {
|
2023-10-30 12:35:06 +08:00
|
|
|
let sdk = EventIntegrationTest::new().await;
|
2022-07-19 14:40:56 +08:00
|
|
|
let request = SignInPayloadPB {
|
2023-02-13 09:29:49 +08:00
|
|
|
email: email.to_string(),
|
|
|
|
password: login_password(),
|
|
|
|
name: "".to_string(),
|
2023-05-21 18:53:59 +08:00
|
|
|
auth_type: AuthTypePB::Local,
|
2023-08-12 17:36:31 +08:00
|
|
|
device_id: "".to_string(),
|
2021-09-01 17:57:06 +08:00
|
|
|
};
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
assert_eq!(
|
2023-05-23 23:55:21 +08:00
|
|
|
EventBuilder::new(sdk)
|
2023-11-27 18:54:31 -08:00
|
|
|
.event(SignInWithEmailPassword)
|
2022-02-24 21:49:18 +08:00
|
|
|
.payload(request)
|
2021-10-18 18:40:15 +08:00
|
|
|
.async_send()
|
|
|
|
.await
|
2023-02-13 09:29:49 +08:00
|
|
|
.error()
|
2023-05-23 23:55:21 +08:00
|
|
|
.unwrap()
|
2023-02-13 09:29:49 +08:00
|
|
|
.code,
|
2023-08-22 00:19:15 +08:00
|
|
|
ErrorCode::EmailFormatInvalid
|
2023-02-13 09:29:49 +08:00
|
|
|
);
|
|
|
|
}
|
2021-09-01 17:57:06 +08:00
|
|
|
}
|
|
|
|
|
2021-10-18 18:40:15 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn sign_in_with_invalid_password() {
|
2023-02-13 09:29:49 +08:00
|
|
|
for password in invalid_password_test_case() {
|
2023-10-30 12:35:06 +08:00
|
|
|
let sdk = EventIntegrationTest::new().await;
|
2021-09-28 15:29:29 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
let request = SignInPayloadPB {
|
2023-10-24 20:11:06 +08:00
|
|
|
email: unique_email(),
|
2023-02-13 09:29:49 +08:00
|
|
|
password,
|
|
|
|
name: "".to_string(),
|
2023-05-21 18:53:59 +08:00
|
|
|
auth_type: AuthTypePB::Local,
|
2023-08-12 17:36:31 +08:00
|
|
|
device_id: "".to_string(),
|
2023-02-13 09:29:49 +08:00
|
|
|
};
|
2021-09-01 17:57:06 +08:00
|
|
|
|
2023-05-23 23:55:21 +08:00
|
|
|
assert!(EventBuilder::new(sdk)
|
2023-11-27 18:54:31 -08:00
|
|
|
.event(SignInWithEmailPassword)
|
2023-02-13 09:29:49 +08:00
|
|
|
.payload(request)
|
|
|
|
.async_send()
|
|
|
|
.await
|
2023-05-23 23:55:21 +08:00
|
|
|
.error()
|
|
|
|
.is_some())
|
2023-02-13 09:29:49 +08:00
|
|
|
}
|
2021-09-01 17:57:06 +08:00
|
|
|
}
|