From 2540254b8cfcaf3f9e3948bc0af10e73e4b3af01 Mon Sep 17 00:00:00 2001 From: Jim Crossley Date: Tue, 5 Nov 2024 18:36:21 -0500 Subject: [PATCH] Add proper tests for querying enums Signed-off-by: Jim Crossley --- common/src/db/query.rs | 2 +- common/src/db/query/columns.rs | 10 ++++------ common/src/db/query/filter.rs | 8 ++++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/common/src/db/query.rs b/common/src/db/query.rs index bee4071e..2bc72c23 100644 --- a/common/src/db/query.rs +++ b/common/src/db/query.rs @@ -244,7 +244,7 @@ pub(crate) mod tests { impl ActiveModelBehavior for ActiveModel {} #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] - #[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "severity")] + #[sea_orm(rs_type = "String", db_type = "Enum")] pub enum Severity { #[sea_orm(string_value = "low")] Low, diff --git a/common/src/db/query/columns.rs b/common/src/db/query/columns.rs index 5fb3738f..32011e50 100644 --- a/common/src/db/query/columns.rs +++ b/common/src/db/query/columns.rs @@ -27,13 +27,11 @@ impl Display for Columns { ColumnType::Text | ColumnType::String(_) | ColumnType::Char(_) => { write!(f, "String")? } - ColumnType::Enum { - name: _, - variants: v, - } => write!( + ColumnType::Enum { name, variants } => write!( f, - "Enum {:?}", - v.iter().map(|v| v.to_string()).collect::>() + "Enum({}) {:?}", + name.to_string(), + variants.iter().map(|v| v.to_string()).collect::>() )?, t => write!(f, " {t:?}")?, } diff --git a/common/src/db/query/filter.rs b/common/src/db/query/filter.rs index fc2a5bee..8edd7386 100644 --- a/common/src/db/query/filter.rs +++ b/common/src/db/query/filter.rs @@ -412,6 +412,14 @@ pub(crate) mod tests { where_clause("published!=NULL")?, r#""advisory"."published" IS NOT NULL"# ); + assert_eq!( + where_clause("severity=high")?, + r#""advisory"."severity" = (CAST('high' AS "Severity"))"# + ); + assert_eq!( + where_clause("severity>low")?, + r#""advisory"."severity" > (CAST('low' AS "Severity"))"# + ); Ok(()) }