test: test with dev client (#91)
* test: test with dev client * chore: add nginx conf * chore: fix clippy * chore: disable docker in lint
This commit is contained in:
parent
583f82b7fb
commit
c0aea377d0
|
|
@ -41,4 +41,5 @@ jobs:
|
|||
- name: Run tests
|
||||
run: |
|
||||
cargo install sqlx-cli --version=${{ env.SQLX_VERSION }} --features ${{ env.SQLX_FEATURES }} --no-default-features --locked
|
||||
cargo sqlx prepare --check --workspace
|
||||
RUST_LOG=debug cargo test
|
||||
|
|
|
|||
|
|
@ -28,18 +28,6 @@ jobs:
|
|||
- name: Copy and rename dev.env to .env
|
||||
run: cp dev.env .env
|
||||
|
||||
- name: Run the dependency services
|
||||
run: docker-compose --file docker-compose-dev.yml up -d
|
||||
|
||||
- name: Install Development Dependencies
|
||||
run: |
|
||||
cargo install sqlx-cli --version=${{ env.SQLX_VERSION }} --features ${{ env.SQLX_FEATURES }} --no-default-features --locked
|
||||
|
||||
- name: Check sqlx-data.json
|
||||
run: |
|
||||
cargo sqlx migrate run
|
||||
cargo sqlx prepare --check --workspace
|
||||
|
||||
- name: Rustfmt
|
||||
run: cargo fmt --check
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::params::{AdminUserParams, GenerateLinkParams, GenerateLinkResponse};
|
||||
use anyhow::Context;
|
||||
|
||||
use super::grant::Grant;
|
||||
use gotrue_entity::{
|
||||
|
|
@ -26,14 +27,21 @@ impl Client {
|
|||
|
||||
pub async fn health(&self) -> Result<(), GoTrueError> {
|
||||
let url: String = format!("{}/health", self.base_url);
|
||||
let resp = self.client.get(url).send().await?;
|
||||
let resp = self
|
||||
.client
|
||||
.get(&url)
|
||||
.send()
|
||||
.await
|
||||
.context(format!("calling {} failed", url))?;
|
||||
Ok(check_response(resp).await?)
|
||||
}
|
||||
|
||||
pub async fn settings(&self) -> Result<GoTrueSettings, GoTrueError> {
|
||||
let url: String = format!("{}/settings", self.base_url);
|
||||
let resp = self.client.get(url).send().await?;
|
||||
let settings: GoTrueSettings = from_response(resp).await?;
|
||||
let resp = self.client.get(&url).send().await?;
|
||||
let settings: GoTrueSettings = from_response(resp)
|
||||
.await
|
||||
.context(format!("calling {} failed", url))?;
|
||||
Ok(settings)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ http {
|
|||
location /callback {
|
||||
proxy_pass http://gotrue:9999;
|
||||
}
|
||||
location /settings{
|
||||
proxy_pass http://gotrue:9999;
|
||||
}
|
||||
|
||||
# AppFlowy-Cloud
|
||||
location / {
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ pub async fn init_state(config: &Config) -> AppState {
|
|||
let gotrue_client = get_gotrue_client(&config.gotrue).await;
|
||||
setup_admin_account(&gotrue_client, &pg_pool, &config.gotrue).await;
|
||||
let redis_client = get_redis_client(config.redis_uri.expose_secret()).await;
|
||||
let collab_storage = init_storage(&config, pg_pool.clone()).await;
|
||||
let collab_storage = init_storage(config, pg_pool.clone()).await;
|
||||
|
||||
AppState {
|
||||
pg_pool,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use gotrue::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
client_api_client,
|
||||
localhost_client,
|
||||
user::utils::{generate_unique_email, ADMIN_USER},
|
||||
LOCALHOST_GOTRUE,
|
||||
};
|
||||
|
|
@ -86,7 +86,7 @@ async fn admin_generate_link_and_user_sign_in() {
|
|||
let resp_text = resp.text().await.unwrap();
|
||||
let appflowy_sign_in_url = extract_sign_in_url(&resp_text).unwrap();
|
||||
|
||||
let client = client_api_client();
|
||||
let client = localhost_client();
|
||||
let is_new = client
|
||||
.sign_in_with_url(&appflowy_sign_in_url)
|
||||
.await
|
||||
|
|
|
|||
|
|
@ -11,6 +11,19 @@ pub const LOCALHOST_URL: &str = "http://localhost:8000";
|
|||
pub const LOCALHOST_WS: &str = "ws://localhost:8000/ws";
|
||||
pub const LOCALHOST_GOTRUE: &str = "http://localhost:9998";
|
||||
|
||||
pub fn client_api_client() -> Client {
|
||||
/// Return a client that connects to the local host. It requires to run the server locally.
|
||||
/// ```shell
|
||||
/// ./build/run_local_server.sh
|
||||
/// ```
|
||||
pub fn localhost_client() -> Client {
|
||||
Client::new(LOCALHOST_URL, LOCALHOST_WS, LOCALHOST_GOTRUE)
|
||||
}
|
||||
|
||||
pub const DEV_URL: &str = "https://test.appflowy.cloud";
|
||||
pub const DEV_WS: &str = "wss://test.appflowy.cloud/ws";
|
||||
pub const DEV_GOTRUE: &str = "https://test.appflowy.cloud";
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn test_appflowy_cloud_client() -> Client {
|
||||
Client::new(DEV_URL, DEV_WS, DEV_GOTRUE)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use tracing_subscriber::fmt::Subscriber;
|
|||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
use crate::client_api_client;
|
||||
use crate::localhost_client;
|
||||
use crate::user::utils::{generate_unique_registered_user, User};
|
||||
|
||||
pub(crate) struct TestClient {
|
||||
|
|
@ -47,7 +47,7 @@ impl TestClient {
|
|||
|
||||
pub(crate) async fn new(device_id: String, registered_user: User) -> Self {
|
||||
setup_log();
|
||||
let api_client = client_api_client();
|
||||
let api_client = localhost_client();
|
||||
api_client
|
||||
.sign_in_password(®istered_user.email, ®istered_user.password)
|
||||
.await
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use shared_entity::error_code::ErrorCode;
|
||||
|
||||
use crate::client_api_client;
|
||||
use crate::localhost_client;
|
||||
use crate::user::utils::{generate_unique_email, generate_unique_registered_user, ADMIN_USER};
|
||||
|
||||
#[tokio::test]
|
||||
async fn sign_in_unknown_user() {
|
||||
let email = generate_unique_email();
|
||||
let password = "Hello123!";
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
let err = c.sign_in_password(&email, password).await.unwrap_err();
|
||||
assert_eq!(err.code, ErrorCode::OAuthError);
|
||||
assert!(!err.message.is_empty());
|
||||
|
|
@ -15,7 +15,7 @@ async fn sign_in_unknown_user() {
|
|||
|
||||
#[tokio::test]
|
||||
async fn sign_in_wrong_password() {
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
|
||||
let email = generate_unique_email();
|
||||
let password = "Hello123!";
|
||||
|
|
@ -32,7 +32,7 @@ async fn sign_in_wrong_password() {
|
|||
|
||||
#[tokio::test]
|
||||
async fn sign_in_unconfirmed_email() {
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
|
||||
let email = generate_unique_email();
|
||||
let password = "Hello123!";
|
||||
|
|
@ -49,7 +49,7 @@ async fn sign_in_success() {
|
|||
|
||||
{
|
||||
// First Time
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
let is_new = c
|
||||
.sign_in_password(®istered_user.email, ®istered_user.password)
|
||||
.await
|
||||
|
|
@ -73,7 +73,7 @@ async fn sign_in_success() {
|
|||
|
||||
{
|
||||
// Subsequent Times
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
let is_new = c
|
||||
.sign_in_password(®istered_user.email, ®istered_user.password)
|
||||
.await
|
||||
|
|
@ -89,7 +89,7 @@ async fn sign_in_success() {
|
|||
#[tokio::test]
|
||||
async fn sign_in_with_invalid_url() {
|
||||
let url_str = "appflowy-flutter://#access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTQ1ODIyMjMsInN1YiI6Ijk5MGM2NDNjLTMyMWEtNGNmMi04OWY1LTNhNmJhZGFjMTg5NCIsImVtYWlsIjoiNG5uaWhpbGF0ZWRAZ21haWwuY29tIiwicGhvbmUiOiIiLCJhcHBfbWV0YWRhdGEiOnsicHJvdmlkZXIiOiJnb29nbGUiLCJwcm92aWRlcnMiOlsiZ29vZ2xlIl19LCJ1c2VyX21ldGFkYXRhIjp7ImF2YXRhcl91cmwiOiJodHRwczovL2xoMy5nb29nbGV1c2VyY29udGVudC5jb20vYS9BQ2c4b2NJdGZpa28xX0lpMmZiNzM4VnpGekViLVBqT0NCY3FUQzdrNjVIX0hnRTQwOVk9czk2LWMiLCJlbWFpbCI6IjRubmloaWxhdGVkQGdtYWlsLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJmdWxsX25hbWUiOiJmdSB6aXhpYW5nIiwiaXNzIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vdXNlcmluZm8vdjIvbWUiLCJuYW1lIjoiZnUgeml4aWFuZyIsInBpY3R1cmUiOiJodHRwczovL2xoMy5nb29nbGV1c2VyY29udGVudC5jb20vYS9BQ2c4b2NJdGZpa28xX0lpMmZiNzM4VnpGekViLVBqT0NCY3FUQzdrNjVIX0hnRTQwOVk9czk2LWMiLCJwcm92aWRlcl9pZCI6IjEwMTQ5OTYxMDMxOTYxNjE0NTcyNSIsInN1YiI6IjEwMTQ5OTYxMDMxOTYxNjE0NTcyNSJ9LCJyb2xlIjoiIn0.I-7j-Tdj62P56zhzEqvBc7cHMldv5MA_MM7xtrBibbE&expires_in=3600&provider_token=ya29.a0AfB_byCovXs1CUiC9_f9VBTupQPsIxwh9aSlOg0PLYJvv1x1zvVfssrQfW6_Aq9no7EKpCzFUCLElOvK1Xz4x4K5r7tug79tr5b1yiOoUMWTeWTXyV61fZHQbZ9vscAiyKYtq5NqYTiytHcQEFlKr7UMfu6BTbKsUwaCgYKAaISARISFQGOcNnC0Vsx2QCAXgYO3XbfcF91WQ0169&refresh_token=Hi3Jc3I_pj9YrexcR91i5g&token_type=bearer";
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
match c.sign_in_with_url(url_str).await {
|
||||
Ok(_) => panic!("should not be ok"),
|
||||
Err(e) => {
|
||||
|
|
@ -103,7 +103,7 @@ async fn sign_in_with_invalid_url() {
|
|||
|
||||
#[tokio::test]
|
||||
async fn sign_in_with_url() {
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
let user_email = generate_unique_email();
|
||||
let url_str = c
|
||||
.generate_sign_in_url_with_email(&ADMIN_USER.email, &ADMIN_USER.password, &user_email)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{client_api_client, user::utils::generate_unique_registered_user_client};
|
||||
use crate::{localhost_client, user::utils::generate_unique_registered_user_client};
|
||||
|
||||
#[tokio::test]
|
||||
async fn sign_out_but_not_sign_in() {
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
let res = c.sign_out().await;
|
||||
assert!(res.is_err());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use gotrue_entity::OAuthProvider;
|
|||
use shared_entity::error_code::ErrorCode;
|
||||
|
||||
use crate::{
|
||||
client_api_client,
|
||||
localhost_client,
|
||||
user::utils::{generate_unique_email, generate_unique_registered_user_client},
|
||||
};
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
async fn sign_up_success() {
|
||||
let email = generate_unique_email();
|
||||
let password = "Hello!123#";
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
c.sign_up(&email, password).await.unwrap();
|
||||
}
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ async fn sign_up_success() {
|
|||
async fn sign_up_invalid_email() {
|
||||
let invalid_email = "not_email_address";
|
||||
let password = "Hello!123#";
|
||||
let error = client_api_client()
|
||||
let error = localhost_client()
|
||||
.sign_up(invalid_email, password)
|
||||
.await
|
||||
.unwrap_err();
|
||||
|
|
@ -33,7 +33,7 @@ async fn sign_up_invalid_email() {
|
|||
async fn sign_up_invalid_password() {
|
||||
let email = generate_unique_email();
|
||||
let password = "3";
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
let error = c.sign_up(&email, password).await.unwrap_err();
|
||||
assert_eq!(error.code, ErrorCode::InvalidRequestParams);
|
||||
assert_eq!(error.message, "Password should be at least 6 characters");
|
||||
|
|
@ -47,7 +47,7 @@ async fn sign_up_but_existing_user() {
|
|||
|
||||
#[tokio::test]
|
||||
async fn sign_up_oauth_not_available() {
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
let err = c
|
||||
.generate_oauth_url_with_provider(&OAuthProvider::Zoom)
|
||||
.await
|
||||
|
|
@ -63,9 +63,17 @@ async fn sign_up_oauth_not_available() {
|
|||
|
||||
#[tokio::test]
|
||||
async fn sign_up_with_google_oauth() {
|
||||
let c = client_api_client();
|
||||
let _ = c
|
||||
let c = localhost_client();
|
||||
let url = c
|
||||
.generate_oauth_url_with_provider(&OAuthProvider::Google)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(!url.is_empty());
|
||||
|
||||
// let c = test_appflowy_cloud_client();
|
||||
// let url = c
|
||||
// .generate_oauth_url_with_provider(&OAuthProvider::Google)
|
||||
// .await
|
||||
// .unwrap();
|
||||
// assert!(!url.is_empty());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use shared_entity::dto::UserUpdateParams;
|
||||
use shared_entity::error_code::ErrorCode;
|
||||
|
||||
use crate::client_api_client;
|
||||
use crate::localhost_client;
|
||||
use crate::user::utils::{generate_unique_email, generate_unique_registered_user_client};
|
||||
|
||||
#[tokio::test]
|
||||
async fn update_but_not_logged_in() {
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
let new_email = generate_unique_email();
|
||||
let new_password = "Hello123!";
|
||||
let res = c
|
||||
|
|
@ -56,7 +56,7 @@ async fn update_password_and_revert() {
|
|||
}
|
||||
{
|
||||
// revert password to old_password
|
||||
let c = client_api_client();
|
||||
let c = localhost_client();
|
||||
c.sign_in_password(&user.email, new_password).await.unwrap();
|
||||
c.update(UserUpdateParams::new().with_password(&user.password))
|
||||
.await
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use sqlx::types::Uuid;
|
|||
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use crate::client_api_client;
|
||||
use crate::localhost_client;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref ADMIN_USER: User = {
|
||||
|
|
@ -28,7 +28,7 @@ pub fn generate_unique_email() -> String {
|
|||
|
||||
pub async fn generate_unique_registered_user() -> User {
|
||||
// log in as admin
|
||||
let admin_client = client_api_client();
|
||||
let admin_client = localhost_client();
|
||||
admin_client
|
||||
.sign_in_password(&ADMIN_USER.email, &ADMIN_USER.password)
|
||||
.await
|
||||
|
|
@ -50,7 +50,7 @@ pub async fn generate_unique_registered_user() -> User {
|
|||
|
||||
pub async fn generate_unique_registered_user_client() -> (Client, User) {
|
||||
let registered_user = generate_unique_registered_user().await;
|
||||
let registered_user_client = client_api_client();
|
||||
let registered_user_client = localhost_client();
|
||||
registered_user_client
|
||||
.sign_in_password(®istered_user.email, ®istered_user.password)
|
||||
.await
|
||||
|
|
|
|||
Loading…
Reference in New Issue