5 more tests to go
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user