more changes and more fixes, 3 more tests to go
This commit is contained in:
@@ -7,9 +7,8 @@
|
||||
#[rstest]
|
||||
#[tokio::test]
|
||||
async fn test_fail_on_fk_base_name_collision(#[future] pool: PgPool) {
|
||||
// Scenario: Link to two tables (`team1_users`, `team2_users`) that both have a
|
||||
// base name of "users". This should cause a duplicate "users_id" column in the
|
||||
// generated SQL.
|
||||
// Scenario: Link to two tables (`team1_users`, `team2_users`) that use full table names
|
||||
// for FK columns, so no collision occurs - this should succeed.
|
||||
let pool = pool.await;
|
||||
|
||||
// Arrange: Create the two prerequisite tables
|
||||
@@ -27,8 +26,8 @@ async fn test_fail_on_fk_base_name_collision(#[future] pool: PgPool) {
|
||||
};
|
||||
post_table_definition(&pool, req2).await.unwrap();
|
||||
|
||||
// Arrange: A request that links to both, causing the collision
|
||||
let colliding_req = PostTableDefinitionRequest {
|
||||
// Arrange: A request that links to both - should succeed with full table names
|
||||
let linking_req = PostTableDefinitionRequest {
|
||||
profile_name: "default".into(),
|
||||
table_name: "tasks".into(),
|
||||
links: vec![
|
||||
@@ -45,18 +44,27 @@ async fn test_fail_on_fk_base_name_collision(#[future] pool: PgPool) {
|
||||
};
|
||||
|
||||
// Act
|
||||
let result = post_table_definition(&pool, colliding_req).await;
|
||||
let result = post_table_definition(&pool, linking_req).await;
|
||||
|
||||
// Assert
|
||||
let err = result.unwrap_err();
|
||||
assert_eq!(
|
||||
err.code(),
|
||||
Code::Internal,
|
||||
"Expected Internal error from duplicate column in CREATE TABLE"
|
||||
);
|
||||
// Assert - should succeed
|
||||
let response = result.unwrap();
|
||||
assert!(response.success);
|
||||
|
||||
// Verify the SQL contains both full table name FK columns
|
||||
assert!(response.sql.contains("\"team1_users_id\""),
|
||||
"SQL should contain team1_users_id column");
|
||||
assert!(response.sql.contains("\"team2_users_id\""),
|
||||
"SQL should contain team2_users_id column");
|
||||
|
||||
// Verify the references are correct
|
||||
assert!(response.sql.contains("REFERENCES \"default\".\"team1_users\"(id)"));
|
||||
assert!(response.sql.contains("REFERENCES \"default\".\"team2_users\"(id)"));
|
||||
|
||||
// Verify one is NOT NULL and one is nullable
|
||||
assert!(response.sql.contains("\"team1_users_id\" BIGINT NOT NULL"));
|
||||
assert!(response.sql.contains("\"team2_users_id\" BIGINT REFERENCES"));
|
||||
}
|
||||
|
||||
|
||||
#[rstest]
|
||||
#[tokio::test]
|
||||
async fn test_sql_reserved_keywords_as_identifiers_are_allowed(#[future] pool: PgPool) {
|
||||
|
||||
Reference in New Issue
Block a user