From 31ac24b21c0741e13bfbaf433f2b98ea3db8ca48 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sun, 5 Jul 2020 22:17:18 -0700 Subject: [PATCH] test: Add basic testing for Scribe This verifies that the server rejects a move to the wrong mini grid. --- test | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/test b/test index 65af6c2..8659c64 100755 --- a/test +++ b/test @@ -441,6 +441,143 @@ result=$(tictactoe_move 4) test "$result" = '{"legal":false,"message":"Square is already occupied"}' TEST_END +TEST_SECTION "Scribe game" + +TEST "Create Scribe game" +scribe_game_id=$(new_game scribe) +test "$scribe_game_id" != "" +TEST_END $scribe_game_id + +scribe_game_path=scribe/$scribe_game_id + +# Usage: scribe_profile +scribe_profile() +{ + curl_put /profile "{ \"nickname\": \"$1\" }" "-c .cookie-scribe" +} + +# Pulls a single named event out of the scribe event stream +# +# Usage: scribe_get_event +scribe_get_event() +{ + curl_get $scribe_game_path/events "-m 0.1 -b .cookie-scribe" 2>&1 \ + | grep "^event: $1" -A 1 \ + | grep ^data: \ + | sed -e 's,^data: *,,' +} + +# Usage: scribe_player_name +scribe_get_player_name() +{ + scribe_get_event player-info | jq -r .name +} + +TEST_SUBSECTION "Scribe player-info" + +TEST "Hit LMNO /profile to set name to 'test-suite'" +scribe_profile test-suite +TEST_END + +TEST "Verify player-info event reports 'test-suite' name" +result=$(scribe_get_player_name) +test "$result" = "test-suite" +TEST_END + +scribe_player_info() +{ + scribe_get_event player-info +} + +scribe_set_player_name() +{ + curl_put $scribe_game_path/player "{ \"name\": \"$1\" }" "-b .cookie-scribe" +} + +scribe_set_player_team() +{ + curl_put $scribe_game_path/player "{ \"team\": \"$1\" }" "-b .cookie-scribe" +} + +TEST_SUBSECTION "Scribe /player" + +TEST "Change name to 'testy'" +scribe_set_player_name testy +result=$(scribe_player_info) +test "$result" = '{"id":1,"active":true,"name":"testy","team":""}' +TEST_END + +TEST "Change team to '+'" +scribe_set_player_team + +result=$(scribe_player_info) +test "$result" = '{"id":1,"active":true,"name":"testy","team":"+"}' +TEST_END + +TEST "Change team to 'o'" +scribe_set_player_team o +result=$(scribe_player_info) +test "$result" = '{"id":1,"active":true,"name":"testy","team":"o"}' +TEST_END + +TEST "Verify cannot change team to 'X'" +scribe_set_player_team X +result=$(scribe_player_info) +test "$result" = '{"id":1,"active":true,"name":"testy","team":"o"}' +TEST_END + +TEST "Leave current team" +scribe_set_player_team "" +result=$(scribe_player_info) +test "$result" = '{"id":1,"active":true,"name":"testy","team":""}' +TEST_END + +scribe_move() +{ + curl_post $scribe_game_path/move "{ \"move\": $1 }" "-b .cookie-scribe" +} + +TEST_SUBSECTION "Scribe /move" + +TEST "First move doesn't require a team" +result=$(scribe_move '[4,0]') +test "$result" = '{"legal":true}' +TEST_END + +TEST "Second move does require a team" +result=$(scribe_move '[0,3]') +test "$result" = '{"legal":false,"message":"It'"'"'s not your turn to move"}' +TEST_END + +TEST "Illegal to move when it's not your turn" +scribe_set_player_team + +result=$(scribe_move '[0,3]') +test "$result" = '{"legal":false,"message":"It'"'"'s not your turn to move"}' +TEST_END + +TEST "Legal move to an empty square" +scribe_set_player_team o +result=$(scribe_move '[0,3]') +test "$result" = '{"legal":true}' +TEST_END + +TEST "Move to same again is now illegal" +scribe_set_player_team + +result=$(scribe_move '[0,3]') +test "$result" = '{"legal":false,"message":"Square is already occupied"}' +TEST_END + +TEST "Move must be in correct mini-grid by last move" +scribe_set_player_team + +result=$(scribe_move '[1,8]') +test "$result" = '{"legal":false,"message":"Move is inconsistent with your previous move"}' +TEST_END + +TEST "Move in correct mini-grid is now legal" +result=$(scribe_move '[0,8]') +test "$result" = '{"legal":true}' +TEST_END + + TEST_SECTION "Empathy game" TEST_SUBSECTION "Create a game and register 3 players" -- 2.43.0