what2watch/src/test_utils.rs

43 lines
1.1 KiB
Rust
Raw Normal View History

use axum_test::{TestServer, TestServerConfig};
use uuid::Uuid;
use crate::User;
pub fn get_user() -> User {
User {
username: "test_user".to_string(),
pwhash: "$argon2id$v=19$m=19456,t=2,p=1$GWsCH1w5RYaP9WWmq+xw0g$hmOEqC+MU+vnEk3bOdkoE+z01mOmmOeX08XyPyjqua8".to_string(),
id: Uuid::nil(),
..Default::default()
}
}
pub async fn tserver() -> TestServer {
let pool = crate::db::get_pool().await;
let secret = [0u8; 64];
let user = get_user();
sqlx::query(crate::signup::CREATE_QUERY)
.bind(user.id)
.bind(&user.username)
.bind(&user.displayname)
.bind(&user.email)
.bind(&user.pwhash)
.execute(&pool)
.await
.unwrap();
let r = sqlx::query("select count(*) from witches")
.fetch_one(&pool)
.await;
assert!(r.is_ok());
let app = crate::app(pool, &secret).await.into_make_service();
let config = TestServerConfig {
save_cookies: true,
..Default::default()
};
TestServer::new_with_config(app, config).unwrap()
}