- add: initial database and auth services

This commit is contained in:
2024-11-25 20:45:16 -05:00
parent 6a35b5b373
commit 3ff22c9a5b
24 changed files with 817 additions and 1 deletions

View File

@@ -0,0 +1,30 @@
use sqlx::{PgPool, Executor};
use tokio;
#[tokio::test]
async fn test_get_user() {
// Set up a temporary in-memory PostgreSQL database
let pool = PgPool::connect("postgres://user:password@localhost/test_database").await.unwrap();
// Create the test table
pool.execute(
r#"
CREATE TABLE users (
user_id TEXT PRIMARY KEY,
username TEXT NOT NULL,
email TEXT NOT NULL,
hashed_password TEXT NOT NULL
);
INSERT INTO users (user_id, username, email, hashed_password)
VALUES ('123', 'test_user', 'test@example.com', 'hashed_password_example');
"#,
)
.await
.unwrap();
// Test the `get_user` function
let user = get_user(&pool, "123").await.unwrap();
assert_eq!(user.user_id, "123");
assert_eq!(user.username, "test_user");
assert_eq!(user.email, "test@example.com");
}