summaryrefslogtreecommitdiffstats
path: root/tests/server_core.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/server_core.rs')
-rw-r--r--tests/server_core.rs57
1 files changed, 57 insertions, 0 deletions
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() {
871 .unwrap(); 871 .unwrap();
872 assert_eq!(pending, 0); 872 assert_eq!(pending, 0);
873} 873}
874
875#[test]
876fn history_requires_login_and_valid_counts() {
877 let (mut core, _path) = setup("history-guards", WIN3);
878 let mut state = ConnectionState::default();
879
880 assert_eq!(
881 core.handle_message(&mut state, "HISTORY"),
882 "ERROR Not logged in"
883 );
884
885 register(&mut core, &mut state, "alice");
886 login(&mut core, &mut state, "alice");
887
888 assert_eq!(
889 core.handle_message(&mut state, "HISTORY nope"),
890 "ERROR Invalid HISTORY count"
891 );
892 assert_eq!(
893 core.handle_message(&mut state, "HISTORY 0"),
894 "ERROR Invalid HISTORY count"
895 );
896 assert_eq!(
897 core.handle_message(&mut state, "HISTORY 1 2"),
898 "ERROR Invalid HISTORY format. Usage: HISTORY [count]"
899 );
900}
901
902#[test]
903fn history_lists_recent_plays_newest_first() {
904 let (mut core, _path) = setup("history-list", WIN3);
905 let mut state = ConnectionState::default();
906 register(&mut core, &mut state, "alice");
907 login(&mut core, &mut state, "alice");
908
909 for _ in 0..3 {
910 assert!(core
911 .handle_message(&mut state, "PLAY_START slots 10")
912 .starts_with("GAME_RESULT"));
913 }
914
915 let response = core.handle_message(&mut state, "HISTORY 2");
916 let json = response.strip_prefix("HISTORY ").expect("history response");
917 let records: Vec<zagan_bet::history::PlayRecord> = serde_json::from_str(json).unwrap();
918
919 assert_eq!(records.len(), 2, "the limit must be honoured");
920 for record in &records {
921 assert_eq!(record.game, "slots");
922 assert_eq!(record.bet, 10);
923 assert_eq!(record.winnings, 10, "three C pay the stake back");
924 assert_eq!(record.summary(), "win");
925 assert_eq!(record.details["win_type"], "win");
926 }
927
928 // Newest first: the timestamps must not increase across the list.
929 assert!(records[0].at >= records[1].at);
930}