use super::types::Type;
use chrono::offset::Utc;
use chrono::DateTime;
use uuid::Uuid;
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct EdgeKey {
pub outbound_id: Uuid,
pub t: Type,
pub inbound_id: Uuid,
}
impl EdgeKey {
pub fn new(outbound_id: Uuid, t: Type, inbound_id: Uuid) -> EdgeKey {
EdgeKey {
outbound_id,
t,
inbound_id,
}
}
}
#[derive(Clone, Debug)]
pub struct Edge {
pub key: EdgeKey,
pub created_datetime: DateTime<Utc>,
}
impl Edge {
pub fn new_with_current_datetime(key: EdgeKey) -> Edge {
Self::new(key, Utc::now())
}
pub fn new(key: EdgeKey, created_datetime: DateTime<Utc>) -> Edge {
Edge { key, created_datetime }
}
}
#[cfg(test)]
mod tests {
use super::{Edge, EdgeKey};
use crate::models::Type;
use chrono::Utc;
use uuid::Uuid;
#[test]
fn should_create_edge_with_current_datetime() {
let start_datetime = Utc::now();
let edge = Edge::new_with_current_datetime(EdgeKey::new(Uuid::default(), Type::default(), Uuid::default()));
let end_datetime = Utc::now();
assert!(edge.created_datetime >= start_datetime);
assert!(edge.created_datetime <= end_datetime);
}
}