more fixes

This commit is contained in:
filipriec
2025-06-21 21:43:39 +02:00
parent 06d98aab5c
commit 87b9f6ab87
3 changed files with 77 additions and 19 deletions

View File

@@ -246,26 +246,44 @@ async fn test_nullable_and_multiple_links(#[future] pool_with_preexisting_table:
// 8) Duplicate links in one request → Internal.
#[rstest]
#[tokio::test]
async fn test_fail_on_duplicate_links(#[future] pool_with_preexisting_table: PgPool) {
let pool = pool_with_preexisting_table.await;
async fn test_fail_on_duplicate_links(#[future] pool: PgPool) {
let pool = pool.await;
let unique_id = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos();
let customers_table = format!("customers_{}", unique_id);
// Create the prerequisite table
let prereq_req = PostTableDefinitionRequest {
profile_name: "default".into(),
table_name: customers_table.clone(),
columns: vec![],
links: vec![],
indexes: vec![],
};
post_table_definition(&pool, prereq_req).await.expect("Failed to create prerequisite table");
// Now, test the duplicate link scenario
let req = PostTableDefinitionRequest {
profile_name: "default".into(),
table_name: "dup_links".into(),
table_name: format!("dup_links_{}", unique_id),
columns: vec![],
indexes: vec![],
links: vec![
TableLink {
linked_table_name: "customers".into(),
linked_table_name: customers_table.clone(),
required: true,
},
TableLink {
linked_table_name: "customers".into(),
linked_table_name: customers_table.clone(),
required: false,
},
],
};
let err = post_table_definition(&pool, req).await.unwrap_err();
assert_eq!(err.code(), Code::Internal);
assert_eq!(err.code(), Code::InvalidArgument);
assert!(err.message().contains(&format!("Duplicate link to table '{}'", customers_table)));
}
// 9) Selfreferential FK: link child back to sameprofile parent.