diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-01 18:51:05 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-01 18:51:05 +0100 |
| commit | 8c93f69081f0012e9a97ffc59adb7129bc1593ee (patch) | |
| tree | 4dfe458ca2e76e4d9d2ad8f52c2684d5c83178c9 /tests | |
| parent | v4.0.4: move the client transport and TOFU into the library (diff) | |
| download | zagan-bet-8c93f69081f0012e9a97ffc59adb7129bc1593ee.tar.gz zagan-bet-8c93f69081f0012e9a97ffc59adb7129bc1593ee.zip | |
v4.0.5: login and registration as core commands
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/client_core.rs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/client_core.rs b/tests/client_core.rs index d070a5b..53a024c 100644 --- a/tests/client_core.rs +++ b/tests/client_core.rs | |||
| @@ -1487,3 +1487,79 @@ fn logging_out_and_showing_the_lobby_switch_the_screen() { | |||
| 1487 | }; | 1487 | }; |
| 1488 | assert_eq!(lobby.user, None); | 1488 | assert_eq!(lobby.user, None); |
| 1489 | } | 1489 | } |
| 1490 | |||
| 1491 | #[test] | ||
| 1492 | fn a_login_command_sends_auth_and_sets_the_user() { | ||
| 1493 | let mut h = Harness::new(); | ||
| 1494 | h.core.set_logged_in(None); | ||
| 1495 | |||
| 1496 | let effects = h.core.command(Command::Login { | ||
| 1497 | user: "alice".to_string(), | ||
| 1498 | credential: "hash".to_string(), | ||
| 1499 | }); | ||
| 1500 | h.apply(effects); | ||
| 1501 | assert_eq!(h.sent.last().map(String::as_str), Some("AUTH alice hash")); | ||
| 1502 | |||
| 1503 | h.reply("OK alice"); | ||
| 1504 | let Some(View::Lobby(lobby)) = h.core.view() else { | ||
| 1505 | panic!("expected the lobby"); | ||
| 1506 | }; | ||
| 1507 | assert_eq!(lobby.user.as_deref(), Some("alice")); | ||
| 1508 | assert!(lobby.login_error.is_none()); | ||
| 1509 | assert!(h | ||
| 1510 | .screen | ||
| 1511 | .lines | ||
| 1512 | .iter() | ||
| 1513 | .any(|line| line == "Logged in as alice")); | ||
| 1514 | } | ||
| 1515 | |||
| 1516 | #[test] | ||
| 1517 | fn a_rejected_login_is_shown_on_the_lobby() { | ||
| 1518 | let mut h = Harness::new(); | ||
| 1519 | h.core.set_logged_in(None); | ||
| 1520 | h.core.command(Command::Login { | ||
| 1521 | user: "alice".to_string(), | ||
| 1522 | credential: "bad".to_string(), | ||
| 1523 | }); | ||
| 1524 | h.reply("ERROR Invalid credentials"); | ||
| 1525 | |||
| 1526 | let Some(View::Lobby(lobby)) = h.core.view() else { | ||
| 1527 | panic!("expected the lobby"); | ||
| 1528 | }; | ||
| 1529 | assert_eq!(lobby.user, None); | ||
| 1530 | assert_eq!(lobby.login_error.as_deref(), Some("Invalid credentials")); | ||
| 1531 | } | ||
| 1532 | |||
| 1533 | #[test] | ||
| 1534 | fn a_register_command_sends_register_and_reports_the_result() { | ||
| 1535 | let mut h = Harness::new(); | ||
| 1536 | h.core.set_logged_in(None); | ||
| 1537 | |||
| 1538 | let effects = h.core.command(Command::Register { | ||
| 1539 | user: "bob".to_string(), | ||
| 1540 | credential: "hash".to_string(), | ||
| 1541 | }); | ||
| 1542 | h.apply(effects); | ||
| 1543 | assert_eq!(h.sent.last().map(String::as_str), Some("REGISTER bob hash")); | ||
| 1544 | |||
| 1545 | h.reply("REGISTERED bob"); | ||
| 1546 | assert!(h | ||
| 1547 | .screen | ||
| 1548 | .lines | ||
| 1549 | .iter() | ||
| 1550 | .any(|line| line == "Account created. Log in to play.")); | ||
| 1551 | } | ||
| 1552 | |||
| 1553 | #[test] | ||
| 1554 | fn login_requires_a_connection() { | ||
| 1555 | let mut h = Harness::new(); | ||
| 1556 | h.core.set_connected(false); | ||
| 1557 | |||
| 1558 | let effects = h.core.command(Command::Login { | ||
| 1559 | user: "alice".to_string(), | ||
| 1560 | credential: "hash".to_string(), | ||
| 1561 | }); | ||
| 1562 | h.apply(effects); | ||
| 1563 | |||
| 1564 | assert!(!h.sent.iter().any(|line| line.starts_with("AUTH"))); | ||
| 1565 | } | ||
