Skip to content

Commit 6ef6d13

Browse files
committed
feat: tests for graph store additions
1 parent dd64b8d commit 6ef6d13

File tree

2 files changed

+111
-2
lines changed

2 files changed

+111
-2
lines changed

libs/@local/graph/postgres-store/src/store/postgres/query/expression/conditional.rs

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,8 @@ mod tests {
688688

689689
use super::*;
690690
use crate::store::postgres::query::{
691-
Alias, PostgresQueryPath as _, SelectCompiler, test_helper::max_version_expression,
691+
Alias, Identifier, PostgresQueryPath as _, SelectCompiler,
692+
test_helper::max_version_expression,
692693
};
693694

694695
#[test]
@@ -800,6 +801,99 @@ mod tests {
800801
assert_eq!(empty_array.transpile_to_string(), "ARRAY[]::text[]");
801802
}
802803

804+
#[test]
805+
fn transpile_null_constant() {
806+
assert_eq!(
807+
Expression::Constant(Constant::Null).transpile_to_string(),
808+
"NULL"
809+
);
810+
}
811+
812+
#[test]
813+
fn transpile_u128_constant() {
814+
assert_eq!(
815+
Expression::Constant(Constant::U128(
816+
340_282_366_920_938_463_463_374_607_431_768_211_455
817+
))
818+
.transpile_to_string(),
819+
"340282366920938463463374607431768211455"
820+
);
821+
}
822+
823+
#[test]
824+
fn transpile_json_agg() {
825+
assert_eq!(
826+
Expression::Function(Function::JsonAgg(Box::new(Expression::Parameter(1))))
827+
.transpile_to_string(),
828+
"jsonb_agg($1)"
829+
);
830+
}
831+
832+
#[test]
833+
fn transpile_unnest_multiple() {
834+
assert_eq!(
835+
Expression::Function(Function::Unnest(vec![
836+
Expression::Parameter(1),
837+
Expression::Parameter(2),
838+
Expression::Parameter(3),
839+
]))
840+
.transpile_to_string(),
841+
"UNNEST($1, $2, $3)"
842+
);
843+
}
844+
845+
#[test]
846+
fn transpile_field_access() {
847+
assert_eq!(
848+
Expression::FieldAccess {
849+
expr: Box::new(Expression::Parameter(1)),
850+
field: ColumnName::from(Identifier::from("filter")),
851+
}
852+
.transpile_to_string(),
853+
r#"($1)."filter""#
854+
);
855+
}
856+
857+
#[test]
858+
fn transpile_is_not_false() {
859+
assert_eq!(
860+
Expression::Unary(UnaryExpression {
861+
op: UnaryOperator::IsNotFalse,
862+
expr: Box::new(Expression::Parameter(1)),
863+
})
864+
.transpile_to_string(),
865+
"$1 IS NOT FALSE"
866+
);
867+
}
868+
869+
#[test]
870+
fn transpile_cast_types() {
871+
assert_eq!(
872+
Expression::Parameter(1)
873+
.cast(PostgresType::JsonB)
874+
.transpile_to_string(),
875+
"($1::jsonb)"
876+
);
877+
assert_eq!(
878+
Expression::Parameter(1)
879+
.cast(PostgresType::Numeric)
880+
.transpile_to_string(),
881+
"($1::numeric)"
882+
);
883+
assert_eq!(
884+
Expression::Parameter(1)
885+
.cast(PostgresType::Int)
886+
.transpile_to_string(),
887+
"($1::int)"
888+
);
889+
assert_eq!(
890+
Expression::Parameter(1)
891+
.cast(PostgresType::BigInt)
892+
.transpile_to_string(),
893+
"($1::bigint)"
894+
);
895+
}
896+
803897
fn test_condition<'p, 'f: 'p>(
804898
filter: &'f Filter<'p, DataTypeWithMetadata>,
805899
rendered: &'static str,

libs/@local/graph/postgres-store/src/store/postgres/query/statement/select.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ mod tests {
123123
use uuid::Uuid;
124124

125125
use crate::store::postgres::query::{
126-
Distinctness, PostgresRecord, SelectCompiler, test_helper::trim_whitespace,
126+
Distinctness, PostgresRecord, SelectCompiler, SelectExpression, SelectStatement,
127+
Transpile as _, test_helper::trim_whitespace,
127128
};
128129

129130
#[track_caller]
@@ -1286,6 +1287,20 @@ mod tests {
12861287
);
12871288
}
12881289

1290+
#[test]
1291+
fn transpile_offset() {
1292+
let statement = SelectStatement::builder()
1293+
.selects(vec![SelectExpression::Asterisk(None)])
1294+
.limit(10)
1295+
.offset(20)
1296+
.build();
1297+
1298+
assert_eq!(
1299+
trim_whitespace(&statement.transpile_to_string()),
1300+
"SELECT * LIMIT 10 OFFSET 20"
1301+
);
1302+
}
1303+
12891304
mod predefined {
12901305
use type_system::{
12911306
knowledge::entity::id::{EntityId, EntityUuid},

0 commit comments

Comments
 (0)