use super::*;
#[test]
fn non_escaping_and_shadowed_constructor_arguments_preserve_transaction() {
let path = crate::test_support::fixture_root("postgres-transaction-callbacks")
.join("non-escaping-args.ts");
let source = std::fs::read_to_string(&path).expect("fixture");
let mut options = EmbeddedSqlOptions::configured("@example/db", &["query".into()])
.with_scoped_executors(&["beginTransaction".into()], &[])
.with_transaction_executor_types(&["TransactionQuery".into()]);
options.track_transaction_helpers = true;
let calls = extract_embedded_sql_from_source(&path, &source, &options).calls;
let expected = [
(16, true),
(18, false),
(31, false),
(38, false),
(45, false),
(52, false),
(65, true),
(79, false),
(91, false),
(103, true),
(115, false),
(127, false),
(139, true),
(154, false),
(168, true),
(182, false),
(196, false),
(210, true),
(223, true),
(230, true),
(237, false),
(244, false),
(251, false),
(258, false),
(265, false),
(276, false),
(287, true),
(297, false),
(311, false),
(320, true),
(335, true),
(345, true),
];
assert_eq!(calls.len(), expected.len() + 1, "{calls:?}");
assert_eq!(calls[0].sql_text.as_deref(), Some("SELECT 1"));
assert_eq!(calls[1].sql_text.as_deref(), Some("SELECT id FROM users"));
assert!(calls[0].executor_transaction_known, "{calls:?}");
for (call, (line, known)) in calls[1..].iter().zip(expected) {
assert_eq!(call.line, line, "{call:?}");
assert_eq!(call.executor_transaction_known, known, "{call:?}");
}
}
#[test]
fn captured_const_tagged_statement_preserves_bound_value_origins_in_callback() {
let path = crate::test_support::fixture_root("postgres-transaction-callbacks")
.join("captured-constant.ts");
let source = std::fs::read_to_string(&path).expect("fixture");
let mut options = EmbeddedSqlOptions::configured("@example/db", &["query".into()])
.with_scoped_executors(&["beginTransaction".into()], &[])
.with_transaction_executor_types(&["TransactionQuery".into()])
.with_trusted_sql_tags(&[crate::TrustedSqlTag {
module: "@example/db".into(),
name: "sql".into(),
}]);
options.track_transaction_helpers = true;
let calls = extract_embedded_sql_from_source(&path, &source, &options).calls;
assert_eq!(calls.len(), 2, "{calls:?}");
assert_eq!(calls[0].bound_value_origins.len(), 1, "{calls:?}");
assert_eq!(calls[1].bound_value_origins.len(), 1, "{calls:?}");
assert_eq!(
calls[0].bound_value_origins[0].2, calls[1].bound_value_origins[0].2,
"{calls:?}"
);
}