summaryrefslogtreecommitdiffstats
path: root/tests/client_core.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/client_core.rs')
-rw-r--r--tests/client_core.rs90
1 files changed, 71 insertions, 19 deletions
diff --git a/tests/client_core.rs b/tests/client_core.rs
index bb8772e..b0bba6f 100644
--- a/tests/client_core.rs
+++ b/tests/client_core.rs
@@ -608,24 +608,29 @@ fn roulette_cursor_places_bets_and_spins() {
608 assert!(h.board()[1].contains("Balance: 1000 Kr")); 608 assert!(h.board()[1].contains("Balance: 1000 Kr"));
609 assert!(h.board()[1].contains("Chip: 10 Kr")); 609 assert!(h.board()[1].contains("Chip: 10 Kr"));
610 assert!(h.board()[9].contains("Bets: (none)")); 610 assert!(h.board()[9].contains("Bets: (none)"));
611 // The cursor starts on number 1, the bottom-left corner. 611 // The cursor starts on number 1, the bottom-left cell.
612 assert!(h.board()[5].contains("[ 1 ]")); 612 assert!(h.board()[5].contains("[ 1 ]"));
613 assert!(h.board()[10].contains("Bet: 1 · pays 36x"));
613 614
614 // Up twice: straight 2, then the split between 2 and 3. 615 // One step up is the split between 1 and 2, two steps is number 2.
615 h.key(Key::Up); 616 h.key(Key::Up);
617 assert!(h.board()[5].contains("[ 1 ]"));
618 assert!(h.board()[4].contains("[ 2 ]"));
619 assert!(h.board()[10].contains("Bet: 1/2 · pays 18x"));
620
616 h.key(Key::Up); 621 h.key(Key::Up);
622 assert!(!h.board()[5].contains("[ 1 ]"));
617 assert!(h.board()[4].contains("[ 2 ]")); 623 assert!(h.board()[4].contains("[ 2 ]"));
618 assert!(h.board()[3].contains("[ 3 ]")); 624 assert!(h.board()[10].contains("Bet: 2 · pays 36x"));
619 625
620 h.key(Key::Enter); 626 h.key(Key::Enter);
621 assert!(h.board()[9].contains("2/3 10")); 627 assert!(h.board()[9].contains("2 10"));
622 assert!(h.board()[9].contains("Total: 10 Kr"));
623 628
624 // Back down to number 1 and place a straight. 629 // Right from 2 is the split with 5.
625 h.key(Key::Down); 630 h.key(Key::Right);
626 h.key(Key::Down); 631 assert!(h.board()[10].contains("Bet: 2/5 · pays 18x"));
627 h.key(Key::Enter); 632 h.key(Key::Enter);
628 assert!(h.board()[9].contains("1 10")); 633 assert!(h.board()[9].contains("2/5 10"));
629 assert!(h.board()[9].contains("Total: 20 Kr")); 634 assert!(h.board()[9].contains("Total: 20 Kr"));
630 635
631 h.key(Key::Char(' ')); 636 h.key(Key::Char(' '));
@@ -636,18 +641,17 @@ fn roulette_cursor_places_bets_and_spins() {
636 .expect("roulette request"); 641 .expect("roulette request");
637 assert_eq!( 642 assert_eq!(
638 request, 643 request,
639 "PLAY_START roulette 20 {\"chips\":[{\"target\":{\"bet\":\"split\",\"a\":2,\"b\":3},\"amount\":10},{\"target\":{\"bet\":\"straight\",\"number\":1},\"amount\":10}]}" 644 "PLAY_START roulette 20 {\"chips\":[{\"target\":{\"bet\":\"straight\",\"number\":2},\"amount\":10},{\"target\":{\"bet\":\"split\",\"a\":2,\"b\":5},\"amount\":10}]}"
640 ); 645 );
641 646
642 let bets = r#"{"chips":[{"target":{"bet":"split","a":2,"b":3},"amount":10},{"target":{"bet":"straight","number":1},"amount":10}]}"#; 647 let bets = r#"{"chips":[{"target":{"bet":"straight","number":2},"amount":10},{"target":{"bet":"split","a":2,"b":5},"amount":10}]}"#;
643 h.reply(&format!( 648 h.reply(&format!(
644 "ROULETTE_RESULT session-1 180 20 1160 3 red {bets}" 649 "ROULETTE_RESULT session-1 540 20 1520 2 black {bets}"
645 )); 650 ));
646 651
647 assert_eq!(h.board().len(), 12); 652 assert!(h.board()[1].contains("Balance: 1520 Kr"));
648 assert!(h.board()[1].contains("Balance: 1160 Kr")); 653 assert!(h.board()[10].contains("Won 540 Kr at 2 BLACK EVEN"));
649 assert!(h.board()[10].contains("Won 180 Kr at 3 RED ODD")); 654 assert!(h.board()[10].contains("+520"));
650 assert!(h.board()[10].contains("+160"));
651} 655}
652 656
653#[test] 657#[test]
@@ -658,19 +662,18 @@ fn roulette_cursor_reaches_the_outside_rows() {
658 h.key(Key::Down); 662 h.key(Key::Down);
659 assert!(h.board()[6].starts_with("[") && h.board()[6].contains("1st 12")); 663 assert!(h.board()[6].starts_with("[") && h.board()[6].contains("1st 12"));
660 h.key(Key::Down); 664 h.key(Key::Down);
661 assert!(h.board()[7].starts_with("[") && h.board()[7].contains("2:1")); 665 assert!(h.board()[7].starts_with("[") && h.board()[7].contains("col 1 2:1"));
662 h.key(Key::Down); 666 h.key(Key::Down);
663 assert!(h.board()[8].starts_with("[") && h.board()[8].contains("1-18")); 667 assert!(h.board()[8].starts_with("[") && h.board()[8].contains("1-18"));
664 668
665 h.key(Key::Enter); 669 h.key(Key::Enter);
666 assert!(h.board()[9].contains("1-18 10")); 670 assert!(h.board()[9].contains("1-18 10"));
667 671
668 // Back up to the felt: the bottom edge of the first dozen is the 1/4 split. 672 // Back up to the felt: the dozens return to number 1.
669 h.key(Key::Up); 673 h.key(Key::Up);
670 h.key(Key::Up); 674 h.key(Key::Up);
671 h.key(Key::Up); 675 h.key(Key::Up);
672 assert!(h.board()[5].contains("[ 1 ]")); 676 assert!(h.board()[5].contains("[ 1 ]"));
673 assert!(h.board()[5].contains("[ 4 ]"));
674} 677}
675 678
676#[test] 679#[test]
@@ -1146,3 +1149,52 @@ fn a_round_is_live_only_while_money_is_reserved() {
1146 h.push(&crash_line("CRASH_BUSTED", &busted)); 1149 h.push(&crash_line("CRASH_BUSTED", &busted));
1147 assert!(!h.core.is_live_game()); 1150 assert!(!h.core.is_live_game());
1148} 1151}
1152
1153#[test]
1154fn history_prints_recent_plays() {
1155 let mut h = Harness::new();
1156 h.line("history");
1157 assert_eq!(h.sent.last().map(String::as_str), Some("HISTORY"));
1158
1159 let json = r#"[{"game":"roulette","bet":10,"winnings":20,"balance_after":1010,"at":"2026-10-30 01:20:11","details":{"number":"17","color":"black"}}]"#;
1160 h.reply(&format!("HISTORY {json}"));
1161
1162 assert!(h
1163 .screen
1164 .lines
1165 .iter()
1166 .any(|line| line.starts_with("Recent plays (1)")));
1167 let row = h
1168 .screen
1169 .lines
1170 .iter()
1171 .find(|line| line.contains("roulette"))
1172 .expect("play row");
1173 assert!(row.contains("2026-10-30 01:20"), "row: {row}");
1174 assert!(row.contains("1010"), "row: {row}");
1175 assert!(row.contains("17 black"), "row: {row}");
1176}
1177
1178#[test]
1179fn history_without_plays_says_so() {
1180 let mut h = Harness::new();
1181 h.line("history");
1182 h.reply("HISTORY []");
1183 assert!(h
1184 .screen
1185 .lines
1186 .iter()
1187 .any(|line| line == "No plays recorded yet."));
1188}
1189
1190#[test]
1191fn history_rejects_a_bad_count_without_sending() {
1192 let mut h = Harness::new();
1193 h.line("history 0");
1194 assert!(!h.sent.iter().any(|line| line == "HISTORY 0"));
1195 assert!(h
1196 .screen
1197 .lines
1198 .iter()
1199 .any(|line| line.contains("Usage: history [1-50]")));
1200}