From f07221b4e1d8aa464a44fe566884ccc0565406e9 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 1 Nov 2026 16:17:19 +0100 Subject: v3.2.0: straight and split bets anywhere on the felt; add history command --- tests/server_core.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'tests/server_core.rs') diff --git a/tests/server_core.rs b/tests/server_core.rs index 47e80e7..6d6cffd 100644 --- a/tests/server_core.rs +++ b/tests/server_core.rs @@ -871,3 +871,60 @@ fn an_insufficient_bet_leaves_no_reservation() { .unwrap(); assert_eq!(pending, 0); } + +#[test] +fn history_requires_login_and_valid_counts() { + let (mut core, _path) = setup("history-guards", WIN3); + let mut state = ConnectionState::default(); + + assert_eq!( + core.handle_message(&mut state, "HISTORY"), + "ERROR Not logged in" + ); + + register(&mut core, &mut state, "alice"); + login(&mut core, &mut state, "alice"); + + assert_eq!( + core.handle_message(&mut state, "HISTORY nope"), + "ERROR Invalid HISTORY count" + ); + assert_eq!( + core.handle_message(&mut state, "HISTORY 0"), + "ERROR Invalid HISTORY count" + ); + assert_eq!( + core.handle_message(&mut state, "HISTORY 1 2"), + "ERROR Invalid HISTORY format. Usage: HISTORY [count]" + ); +} + +#[test] +fn history_lists_recent_plays_newest_first() { + let (mut core, _path) = setup("history-list", WIN3); + let mut state = ConnectionState::default(); + register(&mut core, &mut state, "alice"); + login(&mut core, &mut state, "alice"); + + for _ in 0..3 { + assert!(core + .handle_message(&mut state, "PLAY_START slots 10") + .starts_with("GAME_RESULT")); + } + + let response = core.handle_message(&mut state, "HISTORY 2"); + let json = response.strip_prefix("HISTORY ").expect("history response"); + let records: Vec = serde_json::from_str(json).unwrap(); + + assert_eq!(records.len(), 2, "the limit must be honoured"); + for record in &records { + assert_eq!(record.game, "slots"); + assert_eq!(record.bet, 10); + assert_eq!(record.winnings, 10, "three C pay the stake back"); + assert_eq!(record.summary(), "win"); + assert_eq!(record.details["win_type"], "win"); + } + + // Newest first: the timestamps must not increase across the list. + assert!(records[0].at >= records[1].at); +} -- cgit v1.2.3