Open source Nest implementation
pub async fn testing_client() -> rocket::local::asynchronous::Client {
    use rocket::local::asynchronous::Client;
    Client::tracked(nidobyte::rocket())
        .await
        .expect("cannot create rocket testing instance")
}

pub static TEST_USER_PASSWORD: &str = "password";

use nidobyte::{database::Database, models::users::User};

pub async fn user(db: &rocket::State<Database>) -> nidobyte::models::users::User {
    let username = random_name();

    User::create(
        db,
        username.clone(),
        TEST_USER_PASSWORD.to_string(),
        format!("{}@nidobyte.test", username.clone()),
    )
    .await
    .unwrap()
}

use nidobyte::models::projects;

pub async fn project(db: &rocket::State<Database>) -> projects::Project {
    let owner = user(db).await;

    projects::create(db, owner.id, random_name()).await.unwrap()
}

use rand::Rng;
fn random_name() -> String {
    const CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789";
    let mut rng = rand::thread_rng();

    (0..12) .map(|_| {
            let idx = rng.gen_range(0..CHARSET.len());
            CHARSET[idx] as char
        })
        .collect()
}