chore: add test
This commit is contained in:
parent
131c9ed65f
commit
c4c8911af2
|
|
@ -1,6 +1,7 @@
|
||||||
mod collab;
|
mod collab;
|
||||||
mod collab_snapshot;
|
mod collab_snapshot;
|
||||||
mod gotrue;
|
mod gotrue;
|
||||||
|
mod pg_sql;
|
||||||
mod user;
|
mod user;
|
||||||
mod websocket;
|
mod websocket;
|
||||||
mod workspace;
|
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