Skip to content

Commit

Permalink
Add a test for a valid punch
Browse files Browse the repository at this point in the history
  • Loading branch information
lukipuki committed Mar 30, 2024
1 parent b62dd21 commit 95af86d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,18 @@ impl MessageHandler {
mod test_punch {
use std::collections::HashMap;

use chrono::DateTime;
use prost::Message;

use crate::protobufs::{Punch, Punches};
use crate::{
protobufs::{Punch, Punches},
punch::SiPunch,
};

use super::MessageHandler;

#[test]
fn test_punches() {
fn test_wrong_punch() {
let punches = Punches {
punches: vec![Punch {
raw: b"\x12\x43".to_vec(),
Expand All @@ -260,4 +264,23 @@ mod test_punch {
let punches = handler.punches(&message[..], "").unwrap();
assert_eq!(punches.len(), 0);
}

#[test]
fn test_punch() {
let time = DateTime::parse_from_rfc3339("2023-11-23T10:00:03.793+00:00").unwrap();
let punch = SiPunch::punch_to_bytes(47, time, 1715004, 2);
let punches = Punches {
punches: vec![Punch {
raw: punch.to_vec(),
}],
sending_timestamp: None,
};
let message = punches.encode_to_vec();

let mut handler = MessageHandler::new(HashMap::new(), None);
let punches = handler.punches(&message[..], "").unwrap();
assert_eq!(punches.len(), 1);
assert_eq!(punches[0].code, 47);
assert_eq!(punches[0].card, 1715004);
}
}
2 changes: 1 addition & 1 deletion src/punch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use pyo3::prelude::*;
#[pyclass]
pub struct SiPunch {
#[pyo3(get)]
card: u32,
pub card: u32,
#[pyo3(get)]
pub code: u16,
#[pyo3(get)]
Expand Down

0 comments on commit 95af86d

Please sign in to comment.