5 more tests to go

This commit is contained in:
filipriec
2025-06-21 21:01:49 +02:00
parent 298f56a53c
commit 06d98aab5c
5 changed files with 22 additions and 16 deletions

View File

@@ -24,13 +24,17 @@ async fn get_root_connection() -> PgConnection {
/// This is the key to test isolation.
pub async fn setup_isolated_db() -> PgPool {
let mut root_conn = get_root_connection().await;
// Make schema names more unique - include timestamp + random
let schema_name = format!(
"test_{}",
"test_{}_{}",
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos(),
rand::thread_rng()
// --- CHANGE 2: Pass a reference to Alphanumeric directly ---
.sample_iter(&Alphanumeric)
.take(12)
.take(8)
.map(char::from)
.collect::<String>()
.to_lowercase()

View File

@@ -157,8 +157,9 @@ async fn test_name_sanitization(#[future] pool: PgPool) {
#[tokio::test]
async fn test_create_minimal_table(#[future] pool: PgPool) {
let pool = pool.await;
let profile_name = "test_minimal";
let req = PostTableDefinitionRequest {
profile_name: "default".into(),
profile_name: profile_name.into(),
table_name: "minimal".into(),
..Default::default()
};
@@ -168,7 +169,7 @@ async fn test_create_minimal_table(#[future] pool: PgPool) {
assert!(resp.sql.contains("created_at TIMESTAMPTZ"));
assert_table_structure_is_correct(
&pool,
"default", // FIXED: Added schema parameter
profile_name,
"minimal",
&[
("id", "bigint"),

View File

@@ -162,26 +162,24 @@ async fn test_fail_gracefully_if_schema_is_missing(#[future] pool: PgPool) {
#[rstest]
#[tokio::test]
async fn test_column_name_with_id_suffix_is_rejected(#[future] pool: PgPool) {
// Test that column names ending with '_id' are properly rejected during input validation
let pool = pool.await;
// Test 1: Column ending with '_id' should be rejected
let request = PostTableDefinitionRequest {
profile_name: "default".into(),
table_name: "orders".into(), // Valid table name
table_name: "orders".into(),
columns: vec![ColumnDefinition {
name: "legacy_order_id".into(), // This should be rejected
name: "legacy_order_id".into(),
field_type: "integer".into(),
}],
..Default::default()
};
// Act & Assert - should fail validation
let result = post_table_definition(&pool, request).await;
assert!(result.is_err(), "Column names ending with '_id' should be rejected");
if let Err(status) = result {
assert_eq!(status.code(), tonic::Code::InvalidArgument);
assert!(status.message().contains("Invalid column name"));
// Update this line to match the actual error message:
assert!(status.message().contains("Column name cannot be") && status.message().contains("end with '_id'"));
}
// Test 2: Column named exactly 'id' should be rejected
@@ -189,14 +187,17 @@ async fn test_column_name_with_id_suffix_is_rejected(#[future] pool: PgPool) {
profile_name: "default".into(),
table_name: "orders".into(),
columns: vec![ColumnDefinition {
name: "id".into(), // This should be rejected
name: "id".into(),
field_type: "integer".into(),
}],
..Default::default()
};
let result2 = post_table_definition(&pool, request2).await;
assert!(result2.is_err(), "Column named 'id' should be rejected");
if let Err(status) = result2 {
assert_eq!(status.code(), tonic::Code::InvalidArgument);
assert!(status.message().contains("Column name cannot be") && status.message().contains("'id'"));
}
}
#[rstest]