Files
r701/r701/tests/e2e.rs
T
nicolabellutiandClaude Sonnet 5 cc8181ebdc
Check, format and test / build (push) Successful in 44s
Turned the repo into a Cargo workspace, with r701 as a member
Moving the library into its own r701/ directory makes room for the
Tauri GUI client (Oxibadge) to be added as a sibling workspace member
in a following commit. edition/license/repository are now inherited
from the new workspace root instead of being duplicated per member.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-06 12:49:54 +02:00

63 lines
1.8 KiB
Rust

//! End-to-end tests exercising R701's public API against the emulated
//! device in `mock`.
mod mock;
use r701::R701;
use tokio_stream::StreamExt;
#[tokio::test]
async fn connects_and_pings_successfully() {
let addr = mock::spawn().await;
assert!(R701::connect(addr).await.is_ok());
}
#[tokio::test]
#[allow(clippy::unwrap_used)]
async fn gets_employee_name() {
let addr = mock::spawn().await;
let r701 = R701::connect(addr).await.unwrap();
let expected_name = mock::fake_users()[&1].clone();
match r701.get_name(1).await.unwrap() {
Some(Ok(name)) => assert_eq!(name, expected_name),
other => panic!("expected Some(Ok({expected_name:?})), got {other:?}"),
}
}
#[tokio::test]
#[allow(clippy::unwrap_used)]
async fn gets_none_for_unknown_employee() {
let addr = mock::spawn().await;
let r701 = R701::connect(addr).await.unwrap();
assert_eq!(r701.get_name(999).await.unwrap(), None);
}
#[tokio::test]
#[allow(clippy::unwrap_used, clippy::cast_possible_truncation)]
async fn gets_total_record_count() {
let addr = mock::spawn().await;
let r701 = R701::connect(addr).await.unwrap();
let expected_count = mock::fake_records().len() as u16;
assert_eq!(r701.get_total_record_count().await.unwrap(), expected_count);
}
#[tokio::test]
#[allow(clippy::unwrap_used)]
async fn streams_records() {
let addr = mock::spawn().await;
let r701 = R701::connect(addr).await.unwrap();
// The device streams newest first, the reverse of fake_records' order
let expected_records: Vec<_> = mock::fake_records().into_iter().rev().collect();
let mut records = r701.into_record_iter().await.unwrap();
for expected in expected_records {
let record = records.next().await.unwrap().unwrap();
assert_eq!(record, expected);
}
assert!(records.next().await.is_none());
}