- add: initial database and auth services
This commit is contained in:
30
database-service/tests/get_user.rs
Normal file
30
database-service/tests/get_user.rs
Normal 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");
|
||||
}
|
||||
Reference in New Issue
Block a user