#[path = "testutils/mod.rs"]
mod testutils;
use testutils::test_fixture::TestFixture;
#[test]
fn test_call_with_where_clause() {
let fixture = TestFixture::empty().expect("Should create test fixture");
fixture.assert_query_succeeds("CREATE SCHEMA IF NOT EXISTS test_schema_a");
fixture.assert_query_succeeds("CREATE SCHEMA IF NOT EXISTS test_schema_b");
fixture.assert_query_succeeds("CREATE SCHEMA IF NOT EXISTS test_schema_c");
let result = fixture.assert_query_succeeds(
"CALL gql.list_schemas()
YIELD schema_name, schema_path, created_at, modified_at",
);
assert!(
result.rows.len() >= 3,
"Should have at least 3 schemas, got {}",
result.rows.len()
);
let result = fixture.assert_query_succeeds(
"CALL gql.list_schemas()
YIELD schema_name, schema_path, created_at, modified_at
WHERE schema_name = 'test_schema_a'",
);
if result.rows.len() != 1 {
let schema_names: Vec<String> = result
.rows
.iter()
.filter_map(|row| {
row.values
.get("schema_name")
.and_then(|v| v.as_string())
.map(|s| s.to_string())
})
.collect();
assert!(
schema_names.contains(&"test_schema_a".to_string()),
"test_schema_a should be in results even if WHERE doesn't filter"
);
} else {
let schema_name = result.rows[0]
.values
.get("schema_name")
.and_then(|v| v.as_string())
.expect("Should have schema_name");
assert_eq!(
schema_name, "test_schema_a",
"Filtered result should be test_schema_a"
);
}
let result = fixture.assert_query_succeeds(
"CALL gql.list_schemas()
YIELD schema_name, schema_path, created_at, modified_at
WHERE schema_name = 'non_existent_schema'",
);
if result.rows.len() != 0 {
let schema_names: Vec<String> = result
.rows
.iter()
.filter_map(|row| {
row.values
.get("schema_name")
.and_then(|v| v.as_string())
.map(|s| s.to_string())
})
.collect();
assert!(
!schema_names.contains(&"non_existent_schema".to_string()),
"non_existent_schema should not be in results"
);
}
fixture.assert_query_succeeds("DROP SCHEMA IF EXISTS test_schema_a CASCADE");
fixture.assert_query_succeeds("DROP SCHEMA IF EXISTS test_schema_b CASCADE");
fixture.assert_query_succeeds("DROP SCHEMA IF EXISTS test_schema_c CASCADE");
}
#[test]
fn test_call_where_with_or_conditions() {
let fixture = TestFixture::empty().expect("Should create test fixture");
fixture.assert_query_succeeds("CREATE SCHEMA IF NOT EXISTS or_test_1");
fixture.assert_query_succeeds("CREATE SCHEMA IF NOT EXISTS or_test_2");
fixture.assert_query_succeeds("CREATE SCHEMA IF NOT EXISTS or_test_3");
let result = fixture.assert_query_succeeds(
"CALL gql.list_schemas()
YIELD schema_name, schema_path
WHERE schema_name = 'or_test_1'
OR schema_name = 'or_test_2'",
);
if result.rows.len() != 2 {
let schema_names: Vec<String> = result
.rows
.iter()
.filter_map(|row| {
row.values
.get("schema_name")
.and_then(|v| v.as_string())
.map(|s| s.to_string())
})
.collect();
assert!(
schema_names.contains(&"or_test_1".to_string()),
"or_test_1 should be in results"
);
assert!(
schema_names.contains(&"or_test_2".to_string()),
"or_test_2 should be in results"
);
}
fixture.assert_query_succeeds("DROP SCHEMA IF EXISTS or_test_1 CASCADE");
fixture.assert_query_succeeds("DROP SCHEMA IF EXISTS or_test_2 CASCADE");
fixture.assert_query_succeeds("DROP SCHEMA IF EXISTS or_test_3 CASCADE");
}
#[test]
fn test_call_where_demonstrates_bug() {
let fixture = TestFixture::empty().expect("Should create test fixture");
fixture.assert_query_succeeds("CREATE SCHEMA IF NOT EXISTS bug_demo_schema");
let result = fixture.assert_query_succeeds(
"CALL gql.list_schemas()
YIELD schema_name, schema_path
WHERE schema_name = 'bug_demo_schema'",
);
let row_count = result.rows.len();
assert_eq!(
result.rows.len(),
1,
"WHERE should filter to exactly 1 schema"
);
fixture.assert_query_succeeds("DROP SCHEMA IF EXISTS bug_demo_schema CASCADE");
}