tests compiled
This commit is contained in:
@@ -30,7 +30,7 @@ async fn setup_isolated_gen_schema_db() -> PgPool {
|
||||
|
||||
let unique_schema_name = format!(
|
||||
"test_{}",
|
||||
rand::thread_rng()
|
||||
rand::rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(12)
|
||||
.map(char::from)
|
||||
@@ -62,10 +62,10 @@ async fn setup_isolated_gen_schema_db() -> PgPool {
|
||||
.await
|
||||
.expect("Migrations failed in isolated schema");
|
||||
|
||||
sqlx::query!("INSERT INTO profiles (name) VALUES ('default') ON CONFLICT (name) DO NOTHING")
|
||||
sqlx::query!("INSERT INTO schemas (name) VALUES ('default') ON CONFLICT (name) DO NOTHING")
|
||||
.execute(&pool)
|
||||
.await
|
||||
.expect("Failed to insert test profile in isolated schema");
|
||||
.expect("Failed to insert test schema in isolated schema");
|
||||
|
||||
pool
|
||||
}
|
||||
@@ -112,34 +112,37 @@ async fn pool_with_preexisting_table(#[future] pool: PgPool) -> PgPool {
|
||||
/// Checks the PostgreSQL information_schema to verify a table and its columns exist.
|
||||
async fn assert_table_structure_is_correct(
|
||||
pool: &PgPool,
|
||||
schema_name: &str, // ADD: schema parameter
|
||||
table_name: &str,
|
||||
expected_cols: &[(&str, &str)],
|
||||
) {
|
||||
let table_exists = sqlx::query_scalar::<_, bool>(
|
||||
"SELECT EXISTS (
|
||||
SELECT FROM information_schema.tables
|
||||
WHERE table_schema = 'gen' AND table_name = $1
|
||||
WHERE table_schema = $1 AND table_name = $2
|
||||
)",
|
||||
)
|
||||
.bind(schema_name) // CHANGE: use dynamic schema instead of 'gen'
|
||||
.bind(table_name)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(table_exists, "Table 'gen.{}' was not created", table_name);
|
||||
assert!(table_exists, "Table '{}.{}' was not created", schema_name, table_name); // CHANGE: dynamic schema in error message
|
||||
|
||||
for (col_name, col_type) in expected_cols {
|
||||
let record = sqlx::query(
|
||||
"SELECT data_type FROM information_schema.columns
|
||||
WHERE table_schema = 'gen' AND table_name = $1 AND column_name = $2",
|
||||
WHERE table_schema = $1 AND table_name = $2 AND column_name = $3",
|
||||
)
|
||||
.bind(schema_name) // CHANGE: use dynamic schema instead of 'gen'
|
||||
.bind(table_name)
|
||||
.bind(col_name)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let found_type = record.unwrap_or_else(|| panic!("Column '{}' not found in table '{}'", col_name, table_name)).get::<String, _>("data_type");
|
||||
let found_type = record.unwrap_or_else(|| panic!("Column '{}' not found in table '{}.{}'", col_name, schema_name, table_name)).get::<String, _>("data_type"); // CHANGE: dynamic schema in error message
|
||||
|
||||
// Handle type mappings, e.g., TEXT -> character varying, NUMERIC -> numeric
|
||||
let normalized_found_type = found_type.to_lowercase();
|
||||
@@ -184,16 +187,17 @@ async fn test_create_table_success(#[future] pool: PgPool) {
|
||||
|
||||
// Assert
|
||||
assert!(response.success);
|
||||
assert!(response.sql.contains("CREATE TABLE gen.\"invoices\""));
|
||||
assert!(response.sql.contains("CREATE TABLE \"default\".\"invoices\""));
|
||||
assert!(response.sql.contains("\"invoice_number\" TEXT"));
|
||||
assert!(response.sql.contains("\"amount\" NUMERIC(10, 2)"));
|
||||
assert!(response
|
||||
.sql
|
||||
.contains("CREATE INDEX \"idx_invoices_invoice_number\""));
|
||||
|
||||
// Verify actual DB state
|
||||
// Verify actual DB state - FIXED: Added schema parameter
|
||||
assert_table_structure_is_correct(
|
||||
&pool,
|
||||
"default", // Schema name parameter
|
||||
"invoices",
|
||||
&[
|
||||
("id", "bigint"),
|
||||
@@ -257,15 +261,16 @@ async fn test_create_table_with_link(
|
||||
// Assert
|
||||
assert!(response.success);
|
||||
assert!(response.sql.contains(
|
||||
"\"customers_id\" BIGINT NOT NULL REFERENCES gen.\"customers\"(id)"
|
||||
"\"customers_id\" BIGINT NOT NULL REFERENCES \"default\".\"customers\"(id)"
|
||||
));
|
||||
assert!(response
|
||||
.sql
|
||||
.contains("CREATE INDEX \"idx_orders_customers_fk\""));
|
||||
|
||||
// Verify actual DB state
|
||||
// Verify actual DB state - FIXED: Added schema parameter
|
||||
assert_table_structure_is_correct(
|
||||
&pool,
|
||||
"default", // Schema name parameter
|
||||
"orders",
|
||||
&[("customers_id", "bigint")],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user