Skip to content

Commit fabb270

Browse files
committed
refactor(test): address code review feedback for metadata test
- Enhance test comments to clearly explain what behavior is verified - Add NOTE explaining why raw SQLx is used instead of QueryAssertion - Replace unwrap() with expect() for clearer error context
1 parent f025834 commit fabb270

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tests/sqlx/tests/jsonb_path_operators_tests.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,14 @@ async fn double_arrow_in_where_clause(pool: PgPool) -> Result<()> {
9797

9898
#[sqlx::test(fixtures(path = "../fixtures", scripts("encrypted_json")))]
9999
async fn arrow_operator_returns_metadata_fields(pool: PgPool) -> Result<()> {
100-
// Test: e -> 'selector' returns JSONB with 'i' (index) and 'v' (version) fields
100+
// Test: e -> 'selector' returns JSONB with 'i' (index) and 'v' (version) metadata fields.
101+
// This verifies that the arrow operator returns the full encrypted metadata structure,
102+
// not just the value. The metadata includes the index term ('i') and version ('v').
101103
// SQL equivalent: src/operators/->_test.sql lines 106-118
104+
//
105+
// NOTE: This test uses raw SQLx instead of QueryAssertion because we need to verify
106+
// specific JSONB field presence. QueryAssertion is designed for row count and basic
107+
// value assertions, but doesn't support introspecting JSONB object structure.
102108

103109
let sql = format!(
104110
"SELECT (e -> '{}'::text)::jsonb FROM encrypted LIMIT 1",
@@ -111,7 +117,9 @@ async fn arrow_operator_returns_metadata_fields(pool: PgPool) -> Result<()> {
111117
result.is_object(),
112118
"-> operator should return JSONB object"
113119
);
114-
let obj = result.as_object().unwrap();
120+
let obj = result
121+
.as_object()
122+
.expect("Result should be a JSONB object after is_object() check");
115123
assert!(
116124
obj.contains_key("i"),
117125
"Result should contain 'i' (index metadata) field"

0 commit comments

Comments
 (0)