Skip to content

Commit 12cab28

Browse files
committed
test(sqlx): add <= and >= comparison operator tests
- Add <= operator and lte() function tests with ORE - Add JSONB <= comparison test - Add >= operator and gte() function tests with ORE - Add JSONB >= comparison tests (both directions) - Migrated from src/operators/<=_test.sql (12 assertions) - Migrated from src/operators/>=_test.sql (24 assertions) - Coverage: 132/513 (25.7%)
1 parent 8eb3c3e commit 12cab28

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

tests/sqlx/tests/comparison_tests.rs

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,136 @@ async fn greater_than_operator_jsonb_greater_than_encrypted(pool: PgPool) -> Res
248248

249249
Ok(())
250250
}
251+
252+
// ============================================================================
253+
// Task 4: Less Than or Equal (<=) Operator Tests
254+
// ============================================================================
255+
256+
#[sqlx::test]
257+
async fn less_than_or_equal_operator_with_ore(pool: PgPool) -> Result<()> {
258+
// Test: e <= e with ORE encryption
259+
// Value 42 should have 42 records <= it (1-42 inclusive)
260+
// Original SQL lines 10-24 in src/operators/<=_test.sql
261+
// Uses ore table from migrations/002_install_ore_data.sql (ids 1-99)
262+
263+
let ore_term = get_ore_encrypted(&pool, 42).await?;
264+
265+
let sql = format!(
266+
"SELECT id FROM ore WHERE e <= '{}'::eql_v2_encrypted",
267+
ore_term
268+
);
269+
270+
// Should return 42 records (ids 1-42 inclusive)
271+
QueryAssertion::new(&pool, &sql).count(42).await;
272+
273+
Ok(())
274+
}
275+
276+
#[sqlx::test]
277+
async fn lte_function_with_ore(pool: PgPool) -> Result<()> {
278+
// Test: eql_v2.lte() function with ORE
279+
// Original SQL lines 32-46 in src/operators/<=_test.sql
280+
281+
let ore_term = get_ore_encrypted(&pool, 42).await?;
282+
283+
let sql = format!(
284+
"SELECT id FROM ore WHERE eql_v2.lte(e, '{}'::eql_v2_encrypted)",
285+
ore_term
286+
);
287+
288+
QueryAssertion::new(&pool, &sql).count(42).await;
289+
290+
Ok(())
291+
}
292+
293+
#[sqlx::test]
294+
async fn less_than_or_equal_with_jsonb(pool: PgPool) -> Result<()> {
295+
// Test: e <= jsonb with ORE
296+
// Original SQL lines 55-69 in src/operators/<=_test.sql
297+
298+
let json_value = get_ore_encrypted_as_jsonb(&pool, 42).await?;
299+
300+
let sql = format!(
301+
"SELECT id FROM ore WHERE e <= '{}'::jsonb",
302+
json_value
303+
);
304+
305+
QueryAssertion::new(&pool, &sql).count(42).await;
306+
307+
Ok(())
308+
}
309+
310+
// ============================================================================
311+
// Task 5: Greater Than or Equal (>=) Operator Tests
312+
// ============================================================================
313+
314+
#[sqlx::test]
315+
async fn greater_than_or_equal_operator_with_ore(pool: PgPool) -> Result<()> {
316+
// Test: e >= e with ORE encryption
317+
// Value 42 should have 58 records >= it (42-99 inclusive)
318+
// Original SQL lines 10-24 in src/operators/>=_test.sql
319+
// Uses ore table from migrations/002_install_ore_data.sql (ids 1-99)
320+
321+
let ore_term = get_ore_encrypted(&pool, 42).await?;
322+
323+
let sql = format!(
324+
"SELECT id FROM ore WHERE e >= '{}'::eql_v2_encrypted",
325+
ore_term
326+
);
327+
328+
QueryAssertion::new(&pool, &sql).count(58).await;
329+
330+
Ok(())
331+
}
332+
333+
#[sqlx::test]
334+
async fn gte_function_with_ore(pool: PgPool) -> Result<()> {
335+
// Test: eql_v2.gte() function with ORE
336+
// Original SQL lines 32-46 in src/operators/>=_test.sql
337+
338+
let ore_term = get_ore_encrypted(&pool, 42).await?;
339+
340+
let sql = format!(
341+
"SELECT id FROM ore WHERE eql_v2.gte(e, '{}'::eql_v2_encrypted)",
342+
ore_term
343+
);
344+
345+
QueryAssertion::new(&pool, &sql).count(58).await;
346+
347+
Ok(())
348+
}
349+
350+
#[sqlx::test]
351+
async fn greater_than_or_equal_with_jsonb(pool: PgPool) -> Result<()> {
352+
// Test: e >= jsonb with ORE
353+
// Original SQL lines 55-85 in src/operators/>=_test.sql
354+
355+
let json_value = get_ore_encrypted_as_jsonb(&pool, 42).await?;
356+
357+
let sql = format!(
358+
"SELECT id FROM ore WHERE e >= '{}'::jsonb",
359+
json_value
360+
);
361+
362+
QueryAssertion::new(&pool, &sql).count(58).await;
363+
364+
Ok(())
365+
}
366+
367+
#[sqlx::test]
368+
async fn greater_than_or_equal_jsonb_gte_encrypted(pool: PgPool) -> Result<()> {
369+
// Test: jsonb >= e with ORE (reverse direction)
370+
// Original SQL lines 77-80 in src/operators/>=_test.sql
371+
372+
let json_value = get_ore_encrypted_as_jsonb(&pool, 42).await?;
373+
374+
let sql = format!(
375+
"SELECT id FROM ore WHERE '{}'::jsonb >= e",
376+
json_value
377+
);
378+
379+
// jsonb(42) >= e means e <= 42, so 42 records (1-42)
380+
QueryAssertion::new(&pool, &sql).count(42).await;
381+
382+
Ok(())
383+
}

0 commit comments

Comments
 (0)