Skip to content

Commit

Permalink
add users table tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Nov 11, 2023
1 parent 9e295fc commit d2a4336
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions crates/kitsune-db/tests/unicode_collation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use diesel_async::{scoped_futures::ScopedFutureExt, AsyncPgConnection, RunQueryD
use kitsune_db::{
model::{
account::{Account, ActorType, NewAccount},
user::User,
user::{NewUser, User},
},
schema::{accounts, users},
};
Expand Down Expand Up @@ -41,6 +41,27 @@ async fn create_account(conn: &mut AsyncPgConnection, username: &str) -> Result<
.map_err(Into::into)
}

async fn create_user(conn: &mut AsyncPgConnection, username: &str) -> Result<User> {
let account = create_account(conn, Uuid::now_v7().to_string().as_str()).await?;

diesel::insert_into(users::table)
.values(NewUser {
id: Uuid::now_v7(),
account_id: account.id,
oidc_id: None,
username,
email: format!("{username}@kitsune.example").as_str(),
password: None,
domain: "kitsune.example",
private_key: "---WHATEVER---",
confirmation_token: Uuid::now_v7().to_string().as_str(),
})
.returning(User::as_returning())
.get_result(conn)
.await
.map_err(Into::into)
}

#[tokio::test]
#[serial_test::serial]
async fn accounts_username() {
Expand Down Expand Up @@ -76,5 +97,31 @@ async fn accounts_username() {
#[tokio::test]
#[serial_test::serial]
async fn users_username() {
database_test(|db_pool| async move {}).await;
database_test(|db_pool| async move {
db_pool
.with_connection(|conn| {
async move {
let initial_insert = create_user(conn, "aumetra").await;
assert!(initial_insert.is_ok());

let case_mutation = create_user(conn, "AuMeTrA").await;
assert!(case_mutation.is_err());

let unicode_mutation_1 = create_user(conn, "äumeträ").await;
assert!(unicode_mutation_1.is_err());

let unicode_mutation_2 = create_user(conn, "🅰umetr🅰").await;
assert!(unicode_mutation_2.is_err());

let unicode_case_mutation = create_user(conn, "🅰UMETR🅰").await;
assert!(unicode_case_mutation.is_err());

Result::Ok(())
}
.scoped()
})
.await
.unwrap();
})
.await;
}

0 comments on commit d2a4336

Please sign in to comment.