Skip to content

Commit 2884a99

Browse files
S1M0N38claude
andcommitted
test(api): add comprehensive test suite for shop API endpoint
- Add TestShop class with setup/teardown for shop state testing - Test successful next_round action transitions from shop to blind select - Test invalid action error handling with proper error response validation - Test invalid state error when shop called outside shop state - Include 3 test methods covering success and error cases Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6bcab8a commit 2884a99

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tests/test_api_functions.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,80 @@ def test_play_hand_or_discard_invalid_state(
448448
)
449449

450450

451+
class TestShop:
452+
"""Tests for the shop API endpoint."""
453+
454+
@pytest.fixture(autouse=True)
455+
def setup_and_teardown(
456+
self, udp_client: socket.socket
457+
) -> Generator[None, None, None]:
458+
"""Set up and tear down each test method."""
459+
# Start a run
460+
start_run_args = {
461+
"deck": "Red Deck",
462+
"stake": 1,
463+
"challenge": None,
464+
"seed": "OOOO155", # four of a kind in first hand
465+
}
466+
send_and_receive_api_message(udp_client, "start_run", start_run_args)
467+
468+
# Select blind
469+
send_and_receive_api_message(
470+
udp_client, "skip_or_select_blind", {"action": "select"}
471+
)
472+
473+
# Play a winning hand (four of a kind) to reach shop
474+
game_state = send_and_receive_api_message(
475+
udp_client,
476+
"play_hand_or_discard",
477+
{"action": "play_hand", "cards": [0, 1, 2, 3]},
478+
)
479+
assert game_state["state"] == State.ROUND_EVAL.value
480+
481+
# Cash out to reach shop
482+
game_state = send_and_receive_api_message(udp_client, "cash_out", {})
483+
assert game_state["state"] == State.SHOP.value
484+
yield
485+
send_and_receive_api_message(udp_client, "go_to_menu", {})
486+
487+
def test_shop_next_round_success(self, udp_client: socket.socket) -> None:
488+
"""Test successful shop next_round action transitions to blind select."""
489+
# Execute next_round action
490+
game_state = send_and_receive_api_message(
491+
udp_client, "shop", {"action": "next_round"}
492+
)
493+
494+
# Verify we're in blind select state after next_round
495+
assert game_state["state"] == State.BLIND_SELECT.value
496+
497+
def test_shop_invalid_action_error(self, udp_client: socket.socket) -> None:
498+
"""Test shop returns error for invalid action."""
499+
# Try invalid action
500+
response = send_and_receive_api_message(
501+
udp_client, "shop", {"action": "invalid_action"}
502+
)
503+
504+
# Verify error response
505+
assert_error_response(
506+
response, "Invalid action arg for shop", ["action"]
507+
)
508+
509+
def test_shop_invalid_state_error(self, udp_client: socket.socket) -> None:
510+
"""Test shop returns error when not in shop state."""
511+
# Go to menu first to ensure we're not in shop state
512+
send_and_receive_api_message(udp_client, "go_to_menu", {})
513+
514+
# Try to use shop when not in shop state - should return error
515+
response = send_and_receive_api_message(
516+
udp_client, "shop", {"action": "next_round"}
517+
)
518+
519+
# Verify error response
520+
assert_error_response(
521+
response, "Cannot select shop action when not in shop", ["current_state"]
522+
)
523+
524+
451525
class TestCashOut:
452526
"""Tests for the cash_out API endpoint."""
453527

0 commit comments

Comments
 (0)