chore: add test
This commit is contained in:
parent
131c9ed65f
commit
c4c8911af2
|
|
@ -9,10 +9,10 @@ crate-type = ["cdylib", "rlib"]
|
|||
|
||||
[dependencies]
|
||||
bytes.workspace = true
|
||||
collab = { version = "0.1.0"}
|
||||
collab-folder = { version = "0.1.0"}
|
||||
collab-document = { version = "0.1.0"}
|
||||
collab-entity = { version = "0.1.0"}
|
||||
collab = { version = "0.1.0" }
|
||||
collab-folder = { version = "0.1.0" }
|
||||
collab-document = { version = "0.1.0" }
|
||||
collab-entity = { version = "0.1.0" }
|
||||
collab-database = { version = "0.1.0" }
|
||||
async-trait = "0.1.77"
|
||||
anyhow.workspace = true
|
||||
|
|
@ -24,4 +24,4 @@ nanoid = "0.4.0"
|
|||
serde = { version = "1.0.195", features = ["derive"] }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
getrandom = { version = "0.2", features = ["js"]}
|
||||
getrandom = { version = "0.2", features = ["js"] }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
mod collab;
|
||||
mod collab_snapshot;
|
||||
mod gotrue;
|
||||
mod pg_sql;
|
||||
mod user;
|
||||
mod websocket;
|
||||
mod workspace;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
mod util;
|
||||
mod workspace_test;
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
use lazy_static::lazy_static;
|
||||
use snowflake::Snowflake;
|
||||
use sqlx::PgPool;
|
||||
use tokio::sync::RwLock;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn setup_db(pool: &PgPool) -> anyhow::Result<()> {
|
||||
// Have to manually create schema and tables managed by gotrue but referenced by our
|
||||
// migration scripts.
|
||||
sqlx::query(r#"create schema auth"#).execute(pool).await?;
|
||||
sqlx::query(
|
||||
r#"create table auth.users(
|
||||
id uuid NOT NULL UNIQUE,
|
||||
deleted_at timestamptz null,
|
||||
CONSTRAINT users_pkey PRIMARY KEY (id)
|
||||
)"#,
|
||||
)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
sqlx::migrate!("./migrations")
|
||||
.set_ignore_missing(true)
|
||||
.run(pool)
|
||||
.await
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref ID_GEN: RwLock<Snowflake> = RwLock::new(Snowflake::new(1));
|
||||
}
|
||||
|
||||
pub async fn test_create_user(
|
||||
pool: &PgPool,
|
||||
user_uuid: Uuid,
|
||||
email: &str,
|
||||
name: &str,
|
||||
) -> anyhow::Result<()> {
|
||||
let uid = ID_GEN.write().await.next_id();
|
||||
database::user::create_user(pool, uid, &user_uuid, &email, &name)
|
||||
.await
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
use crate::pg_sql::util::{setup_db, test_create_user};
|
||||
use sqlx::PgPool;
|
||||
|
||||
#[sqlx::test(migrations = false)]
|
||||
async fn basic_test(pool: PgPool) -> sqlx::Result<()> {
|
||||
setup_db(&pool).await.unwrap();
|
||||
|
||||
let user_uuid = uuid::Uuid::new_v4();
|
||||
let name = user_uuid.to_string();
|
||||
let email = format!("{}@appflowy.io", name);
|
||||
|
||||
test_create_user(&pool, user_uuid, &email, &name)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Reference in New Issue