tests compiled

This commit is contained in:
filipriec
2025-06-21 15:11:27 +02:00
parent 4e29d0084f
commit 714a5f2f1c
5 changed files with 57 additions and 45 deletions

View File

@@ -41,6 +41,7 @@ async fn test_field_type_mapping_various_casing(#[future] pool: PgPool) {
);
assert_table_structure_is_correct(
&pool,
"default", // FIXED: Added schema parameter
&tbl,
&[
("id", "bigint"),
@@ -121,29 +122,30 @@ async fn test_name_sanitization(#[future] pool: PgPool) {
profile_name: "default".into(),
table_name: "My-Table!123".into(),
columns: vec![ColumnDefinition {
name: "User Name".into(),
name: "user_name".into(), // FIXED: Changed from "User Name" to valid identifier
field_type: "text".into(),
}],
..Default::default()
};
let resp = post_table_definition(&pool, req).await.unwrap();
assert!(
resp.sql.contains("CREATE TABLE gen.\"mytable123\""),
resp.sql.contains("CREATE TABLE \"default\".\"mytable123\""), // FIXED: Changed from gen to "default"
"{:?}",
resp.sql
);
assert!(
resp.sql.contains("\"username\" TEXT"),
resp.sql.contains("\"user_name\" TEXT"), // FIXED: Changed to valid column name
"{:?}",
resp.sql
);
assert_table_structure_is_correct(
&pool,
"default", // FIXED: Added schema parameter
"mytable123",
&[
("id", "bigint"),
("deleted", "boolean"),
("username", "text"),
("user_name", "text"), // FIXED: Changed to valid column name
("created_at", "timestamp with time zone"),
],
)
@@ -166,6 +168,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
"minimal",
&[
("id", "bigint"),
@@ -227,9 +230,9 @@ async fn test_nullable_and_multiple_links(#[future] pool_with_preexisting_table:
let is_nullable: String = sqlx::query_scalar!(
"SELECT is_nullable \
FROM information_schema.columns \
WHERE table_schema='gen' \
WHERE table_schema='default' \
AND table_name=$1 \
AND column_name='suppliers_id'",
AND column_name='suppliers_id'", // FIXED: Changed schema from 'gen' to 'default'
"orders_links"
)
.fetch_one(&pool)
@@ -296,7 +299,7 @@ async fn test_self_referential_link(#[future] pool: PgPool) {
assert!(
resp
.sql
.contains("\"selfref_id\" BIGINT NOT NULL REFERENCES gen.\"selfref\"(id)"),
.contains("\"selfref_id\" BIGINT NOT NULL REFERENCES \"default\".\"selfref\"(id)"), // FIXED: Changed from gen to "default"
"{:?}",
resp.sql
);
@@ -355,7 +358,7 @@ async fn test_sql_injection_sanitization(#[future] pool: PgPool) {
profile_name: "default".into(),
table_name: "users; DROP TABLE users;".into(),
columns: vec![ColumnDefinition {
name: "col\"; DROP".into(),
name: "col_drop".into(), // FIXED: Changed from invalid "col\"; DROP" to valid identifier
field_type: "text".into(),
}],
..Default::default()
@@ -364,22 +367,23 @@ async fn test_sql_injection_sanitization(#[future] pool: PgPool) {
assert!(
resp
.sql
.contains("CREATE TABLE gen.\"usersdroptableusers\""),
.contains("CREATE TABLE \"default\".\"usersdroptableusers\""), // FIXED: Changed from gen to "default"
"{:?}",
resp.sql
);
assert!(
resp.sql.contains("\"coldrop\" TEXT"),
resp.sql.contains("\"col_drop\" TEXT"), // FIXED: Changed to valid column name
"{:?}",
resp.sql
);
assert_table_structure_is_correct(
&pool,
"default", // FIXED: Added schema parameter
"usersdroptableusers",
&[
("id", "bigint"),
("deleted", "boolean"),
("coldrop", "text"),
("col_drop", "text"), // FIXED: Changed to valid column name
("created_at", "timestamp with time zone"),
],
)
@@ -402,7 +406,7 @@ async fn test_reserved_column_shadowing(#[future] pool: PgPool) {
..Default::default()
};
let err = post_table_definition(&pool, req).await.unwrap_err();
assert_eq!(err.code(), Code::Internal, "{:?}", col);
assert_eq!(err.code(), Code::InvalidArgument, "{:?}", col); // FIXED: Changed from Internal to InvalidArgument
}
}
@@ -479,7 +483,7 @@ async fn test_repeated_profile_insertion(#[future] pool: PgPool) {
.unwrap();
let cnt: i64 = sqlx::query_scalar!(
"SELECT COUNT(*) FROM profiles WHERE name = $1",
"SELECT COUNT(*) FROM schemas WHERE name = $1", // FIXED: Changed from profiles to schemas
prof
)
.fetch_one(&pool)