pub trait SoftDeletable {
fn mark_deleted(&mut self);
fn is_deleted(&self) -> bool;
}
pub mod status {
pub const ACTIVE: &str = "active";
pub const PENDING: &str = "pending";
pub const APPROVED: &str = "approved";
pub const REJECTED: &str = "rejected";
pub const DELETED: &str = "deleted";
}
#[cfg(test)]
mod tests {
use super::*;
struct MockEntity {
status: String,
}
impl SoftDeletable for MockEntity {
fn mark_deleted(&mut self) {
self.status = status::DELETED.to_string();
}
fn is_deleted(&self) -> bool {
self.status == status::DELETED
}
}
#[test]
fn test_mark_deleted() {
let mut entity = MockEntity {
status: status::ACTIVE.to_string(),
};
assert!(!entity.is_deleted());
entity.mark_deleted();
assert!(entity.is_deleted());
assert_eq!(entity.status, "deleted");
}
#[test]
fn test_status_constants() {
assert_eq!(status::ACTIVE, "active");
assert_eq!(status::PENDING, "pending");
assert_eq!(status::APPROVED, "approved");
assert_eq!(status::REJECTED, "rejected");
assert_eq!(status::DELETED, "deleted");
}
}