Skip to content

Commit

Permalink
Add proper tests for querying enums
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Crossley <[email protected]>
  • Loading branch information
jcrossley3 committed Nov 6, 2024
1 parent 68d08bc commit 3d2e504
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common/src/db/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions common/src/db/query/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>()
"Enum({}) {:?}",
name.to_string(),
variants.iter().map(|v| v.to_string()).collect::<Vec<_>>()
)?,
t => write!(f, " {t:?}")?,
}
Expand Down
8 changes: 8 additions & 0 deletions common/src/db/query/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit 3d2e504

Please sign in to comment.