3 # Arrange for some cleanup to be executed if the user interrupts the
4 # test sutie (for example, by pressing ControlC at the controlling
7 empathy_deactivate_all >/dev/null 2>&1
11 trap cleanup_and_report INT
15 echo "Usage:$0 <URL-to-test>"
19 echo "Error: No test URL given." >&2
26 CURL="curl --silent --show-error"
32 echo $1 | sed -e "s/./$2/g"
48 printf "%*s" $(( 52 - ${#1} )) | tr ' ' '.'
49 (( tests_total++ )) || true
52 # Result of test depends on the exit status of last command
58 (( tests_failed++ )) || true
62 # If we got an argument, append it after test result
70 # Print report of all previous test results
78 if [ "$tests_failed" == "" ]; then
79 echo "All $tests_total tests passed."
83 echo "$tests_failed of $tests_total tests failed."
89 # Does a string contain a regular expression pattern
93 # contains "All's well that ends well" "s.well"
99 # POST to a URL endpoint with optional JSON data
103 # curl_post <ENDPOINT> [data] [CURL_OPTIONS]
106 $CURL ${3:-} -X POST ${2:+-H 'Content-Type: application/json' -d "$2"} $URL/$1
109 # POST to a URL endpoint with optional JSON data using a cookie
113 # curl_post_cookie <name> <ENDPOINT> [data] [CURL_OPTIONS]
115 # Where <name> is a string for which there is a defined variable
116 # named ${name}_cookie which in turn holds a value that is a filename
121 curl_post $2 "${3:-}" "-b ${!cookie} ${4:-}"
124 # PUT to a URL endpoint with optional JSON data
128 # curl_post <ENDPOINT> [data] [CURL_OPTIONS]
131 $CURL ${3:-} -X PUT ${2:+-H 'Content-Type: application/json' -d "$2"} $URL/$1
134 # GET from a URL endpoint
138 # curl_get <ENDPOINT> [CURL_OPTIONS]
144 # GET from a URL endpoint using a cookie
148 # curl_get_cookie <name> <ENDPOINT> [CURL_OPTIONS]
150 # Where <name> is a string for which there is a defined variable
151 # named ${name}_cookie which in turn holds a value that is a filename
156 curl_get $2 "-b ${!cookie} ${3:-}"
159 # Create a new game of the specified engine type
166 curl_post new/$1 | jq -r .
169 TEST_SECTION "LMNO (super-site for games)"
171 TEST_SUBSECTION "Testing home page"
172 home_page=$($CURL $URL)
174 TEST "Contains 'Join Game'"
175 contains "$home_page" "Join Game"
178 TEST "Contains 'Host a new game'"
179 contains "$home_page" "Host a new game"
182 TEST_SUBSECTION "Creating some new games"
185 empires_game_id=$(new_game empires)
186 test "$empires_game_id" != ""
187 TEST_END $empires_game_id
190 tictactoe_game_id=$(new_game tictactoe)
191 test "$tictactoe_game_id" != ""
192 TEST_END $tictactoe_game_id
194 TEST_SUBSECTION "Test redirects"
196 TEST "Redirect of /GAMEID at top level"
197 redirect=$(curl_get $empires_game_id)
198 test "$redirect" = "Moved Permanently. Redirecting to /empires/$empires_game_id/"
201 TEST "Redirect of lowercase /gameid at top level"
202 empires_game_id_lower=$(tr '[:upper:]' '[:lower:]' <<< $empires_game_id)
203 redirect=$(curl_get $empires_game_id_lower)
204 test "$redirect" = "Moved Permanently. Redirecting to /$empires_game_id/"
207 TEST "Redirect of lowercase /empires/gameid"
208 redirect=$(curl_get empires/$empires_game_id_lower)
209 test "$redirect" = "Moved Permanently. Redirecting to /empires/$empires_game_id/"
212 TEST_SECTION "Empires game"
214 empires_game_path=empires/$empires_game_id
216 TEST_SUBSECTION "Empires game /register"
220 curl_post $empires_game_path/register "{\"name\": \"$1\", \"character\": \"$2\"}"
223 empires_players_string()
225 curl_get $empires_game_path/players | jq -r .[].name | tr '\n' ','
228 empires_characters_string()
230 curl_get $empires_game_path/characters | jq -r .[] | tr '\n' ','
233 TEST "Registering a player returns an ID"
234 carl_id=$(empires_register Carl "Bugs Bunny" | jq -r .)
235 test "$carl_id" = "1"
238 TEST "Registering several more players"
239 empires_register Richard "Bob Hope" > /dev/null
240 empires_register Kevin "Elvis Presley" > /dev/null
241 empires_register Stacy Phineas > /dev/null
242 empires_register David "Red Power Ranger" > /dev/null
243 empires_register Nancy "Audrey Hepburn" > /dev/null
244 bogus_id=$(empires_register Bogus "Mr. Bogus")
247 TEST 'Verify complete players list (with "Bogus")'
248 players=$(empires_players_string)
249 test "$players" = "Carl,Richard,Kevin,Stacy,David,Nancy,Bogus,"
252 TEST 'Verify complete players list (with "Mr. Bogus")'
253 characters=$(empires_characters_string)
254 test "$characters" = "Bugs Bunny,Bob Hope,Elvis Presley,Phineas,Red Power Ranger,Audrey Hepburn,Mr. Bogus,"
257 TEST_SUBSECTION "Empires game /deregister"
261 curl_post $empires_game_path/deregister/$1
264 TEST "Removing the bogus player"
265 empires_deregister $bogus_id
268 TEST 'Verify modified players list (w/o "Bogus")"'
269 players=$(empires_players_string)
270 test "$players" = "Carl,Richard,Kevin,Stacy,David,Nancy,"
273 TEST 'Verify modified characters list (w/o "Mr. Bogus")'
274 characters=$(empires_characters_string)
275 test "$characters" = "Bugs Bunny,Bob Hope,Elvis Presley,Phineas,Red Power Ranger,Audrey Hepburn,"
278 TEST_SUBSECTION "Empires game /capture"
282 curl_post $empires_game_path/capture/$1/$2
285 empires_empires_string()
287 # Get empires as a compact string (much more compact than JSON)
288 curl_get $empires_game_path/empires | jq -c '.[] | [.id,.captures]' | tr '\n' ','
291 TEST "Verify empires before any captures"
292 empires=$(empires_empires_string)
293 test "$empires" = "[1,[]],[2,[]],[3,[]],[4,[]],[5,[]],[6,[]],"
296 TEST "Perform some captures"
303 TEST "Verify empires after captures"
304 empires=$(empires_empires_string)
305 test "$empires" = "[1,[2]],[2,[]],[3,[5,4]],[4,[6]],[5,[]],[6,[]],"
308 TEST_SUBSECTION "Empires game /liberate"
312 curl_post $empires_game_path/liberate/$1
315 TEST "Liberate a player"
319 TEST "Verify empires after liberate"
320 empires=$(empires_empires_string)
321 test "$empires" = "[1,[]],[2,[]],[3,[5,4]],[4,[6]],[5,[]],[6,[]],"
324 TEST_SUBSECTION "Empires game /reset"
328 curl_post $empires_game_path/reset
331 TEST "Reset the game"
335 TEST "Verify players is now empty"
336 players=$(empires_players_string)
340 TEST_SECTION "Tic Tac Toe game"
342 tictactoe_game_path=tictactoe/$tictactoe_game_id
346 curl_put /profile "{ \"nickname\": \"$1\" }" "-c .cookie-tictactoe"
351 curl_post $tictactoe_game_path/move "{ \"move\": $1 }" "-b .cookie-tictactoe"
354 tictactoe_player_info()
356 curl_get $tictactoe_game_path/events "-m 0.1 -b .cookie-tictactoe" 2>&1 \
357 | grep player-info -A 1 \
361 tictactoe_player_name()
363 curl_put $tictactoe_game_path/player "{ \"name\": \"$1\" }" "-b .cookie-tictactoe"
366 tictactoe_player_team()
368 curl_put $tictactoe_game_path/player "{ \"team\": \"$1\" }" "-b .cookie-tictactoe"
371 TEST_SUBSECTION "Tic Tac Toe player-info"
373 TEST "Hit LMNO /profile to set name to 'curl'"
374 tictactoe_profile curl
377 TEST "Verify player-info event reports 'curl' name"
378 result=$(tictactoe_player_info)
379 test "$result" = 'data: {"id":1,"active":true,"name":"curl","team":""}'
382 TEST_SUBSECTION "Tic Tac Toe /player"
384 TEST "Change name to 'newname'"
385 tictactoe_player_name newname
386 result=$(tictactoe_player_info)
387 test "$result" = 'data: {"id":1,"active":true,"name":"newname","team":""}'
390 TEST "Change team to 'X'"
391 tictactoe_player_team X
392 result=$(tictactoe_player_info)
393 test "$result" = 'data: {"id":1,"active":true,"name":"newname","team":"X"}'
396 TEST "Change team to 'O'"
397 tictactoe_player_team O
398 result=$(tictactoe_player_info)
399 test "$result" = 'data: {"id":1,"active":true,"name":"newname","team":"O"}'
402 TEST "Verify cannot change team to 'Z'"
403 tictactoe_player_team Z
404 result=$(tictactoe_player_info)
405 test "$result" = 'data: {"id":1,"active":true,"name":"newname","team":"O"}'
408 TEST "Leave current team"
409 tictactoe_player_team ""
410 result=$(tictactoe_player_info)
411 test "$result" = 'data: {"id":1,"active":true,"name":"newname","team":""}'
414 TEST_SUBSECTION "Tic Tac Toe /move"
416 TEST "First move doesn't require a team"
417 result=$(tictactoe_move 0)
418 test "$result" = '{"legal":true}'
421 TEST "Second move does require a team"
422 result=$(tictactoe_move 4)
423 test "$result" = '{"legal":false,"message":"It'"'"'s not your turn to move"}'
426 TEST "Illegal to move when it's not your turn"
427 tictactoe_player_team X
428 result=$(tictactoe_move 4)
429 test "$result" = '{"legal":false,"message":"It'"'"'s not your turn to move"}'
432 TEST "Legal move to center square"
433 tictactoe_player_team O
434 result=$(tictactoe_move 4)
435 test "$result" = '{"legal":true}'
438 TEST "Move to center square again is now illegal"
439 tictactoe_player_team X
440 result=$(tictactoe_move 4)
441 test "$result" = '{"legal":false,"message":"Square is already occupied"}'
444 TEST_SECTION "Scribe game"
446 TEST "Create Scribe game"
447 scribe_game_id=$(new_game scribe)
448 test "$scribe_game_id" != ""
449 TEST_END $scribe_game_id
451 scribe_game_path=scribe/$scribe_game_id
453 # Usage: scribe_profile <name>
456 curl_put /profile "{ \"nickname\": \"$1\" }" "-c .cookie-scribe"
459 # Pulls a single named event out of the scribe event stream
461 # Usage: scribe_get_event <event_name>
464 curl_get $scribe_game_path/events "-m 0.1 -b .cookie-scribe" 2>&1 \
465 | grep "^event: $1" -A 1 \
467 | sed -e 's,^data: *,,'
470 # Usage: scribe_player_name
471 scribe_get_player_name()
473 scribe_get_event player-info | jq -r .name
476 TEST_SUBSECTION "Scribe player-info"
478 TEST "Hit LMNO /profile to set name to 'test-suite'"
479 scribe_profile test-suite
482 TEST "Verify player-info event reports 'test-suite' name"
483 result=$(scribe_get_player_name)
484 test "$result" = "test-suite"
489 scribe_get_event player-info
492 scribe_set_player_name()
494 curl_put $scribe_game_path/player "{ \"name\": \"$1\" }" "-b .cookie-scribe"
497 scribe_set_player_team()
499 curl_put $scribe_game_path/player "{ \"team\": \"$1\" }" "-b .cookie-scribe"
502 TEST_SUBSECTION "Scribe /player"
504 TEST "Change name to 'testy'"
505 scribe_set_player_name testy
506 result=$(scribe_player_info)
507 test "$result" = '{"id":1,"active":true,"name":"testy","team":""}'
510 TEST "Change team to '+'"
511 scribe_set_player_team +
512 result=$(scribe_player_info)
513 test "$result" = '{"id":1,"active":true,"name":"testy","team":"+"}'
516 TEST "Change team to 'o'"
517 scribe_set_player_team o
518 result=$(scribe_player_info)
519 test "$result" = '{"id":1,"active":true,"name":"testy","team":"o"}'
522 TEST "Verify cannot change team to 'X'"
523 scribe_set_player_team X
524 result=$(scribe_player_info)
525 test "$result" = '{"id":1,"active":true,"name":"testy","team":"o"}'
528 TEST "Leave current team"
529 scribe_set_player_team ""
530 result=$(scribe_player_info)
531 test "$result" = '{"id":1,"active":true,"name":"testy","team":""}'
536 curl_post $scribe_game_path/move "{ \"move\": $1 }" "-b .cookie-scribe"
539 TEST_SUBSECTION "Scribe /move"
541 TEST "First move doesn't require a team"
542 result=$(scribe_move '[4,0]')
543 test "$result" = '{"legal":true}'
546 TEST "Second move does require a team"
547 result=$(scribe_move '[0,3]')
548 test "$result" = '{"legal":false,"message":"It'"'"'s not your turn to move"}'
551 TEST "Illegal to move when it's not your turn"
552 scribe_set_player_team +
553 result=$(scribe_move '[0,3]')
554 test "$result" = '{"legal":false,"message":"It'"'"'s not your turn to move"}'
557 TEST "Legal move to an empty square"
558 scribe_set_player_team o
559 result=$(scribe_move '[0,3]')
560 test "$result" = '{"legal":true}'
563 TEST "Move to same again is now illegal"
564 scribe_set_player_team +
565 result=$(scribe_move '[0,3]')
566 test "$result" = '{"legal":false,"message":"Square is already occupied"}'
569 TEST "Move must be in correct mini-grid by last move"
570 scribe_set_player_team +
571 result=$(scribe_move '[1,8]')
572 test "$result" = '{"legal":false,"message":"Move is inconsistent with your previous move"}'
575 TEST "Move in correct mini-grid is now legal"
576 result=$(scribe_move '[0,8]')
577 test "$result" = '{"legal":true}'
580 TEST "Several moves to fill up the mini-grid 0"
581 scribe_set_player_team o
582 scribe_move '[3,0]' >/dev/null
583 scribe_set_player_team +
584 scribe_move '[8,0]' >/dev/null
585 scribe_set_player_team o
586 scribe_move '[0,0]' >/dev/null
587 scribe_set_player_team +
588 scribe_move '[0,1]' >/dev/null
589 scribe_set_player_team o
590 scribe_move '[0,2]' >/dev/null
591 scribe_set_player_team +
592 scribe_move '[1,0]' >/dev/null
593 scribe_set_player_team o
594 scribe_move '[2,0]' >/dev/null
595 scribe_set_player_team +
596 scribe_move '[0,5]' >/dev/null
597 scribe_set_player_team o
598 scribe_move '[0,6]' >/dev/null
599 scribe_set_player_team +
600 scribe_move '[5,0]' >/dev/null
601 scribe_set_player_team o
602 scribe_move '[6,0]' >/dev/null
603 scribe_set_player_team +
604 scribe_move '[0,7]' >/dev/null
605 scribe_set_player_team o
606 scribe_move '[0,4]' >/dev/null
607 scribe_set_player_team +
608 result=$(scribe_move '[7,0]')
609 test "$result" = '{"legal":true}'
612 TEST "Full mini grid allows a free move"
613 scribe_set_player_team o
614 scribe_move '[4,1]' >/dev/null
615 scribe_set_player_team +
616 result=$(scribe_move '[1,1]')
617 test "$result" = '{"legal":true}'
620 TEST_SECTION "Empathy game"
622 TEST_SUBSECTION "Create a game and register 3 players"
624 TEST "Create the game"
625 empathy_game_id=$(new_game empathy)
626 test "$empathy_game_id" != ""
627 TEST_END $empathy_game_id
629 empathy_game_path=empathy/$empathy_game_id
631 # Usage: empathy_get <player_name> <endpoint> [curl_options]
634 curl_get_cookie $1 $empathy_game_path/$2 "${3:-}"
637 # Usage: empathy_post <player_name> <endpoint> [data]
640 curl_post_cookie $1 $empathy_game_path/$2 "${3:-}"
643 # Given a player name as $1 (eg. "empathy_player_activate alice") set both
644 # $1_cookie and $1_pid (that is $alice_cookie and $alice_pid) to
645 # a filename containing a cookie and the PID of a running event-streaming
647 empathy_player_activate()
650 player_cookie=${player}_cookie
651 player_pid=${player}_pid
653 eval ${player_cookie}=".cookie-empathy-$player"
654 curl_put /profile "{ \"nickname\": \"$player\" }" "-c ${!player_cookie}"
655 empathy_get $player events >/dev/null 2>&1 &
656 eval ${player_pid}=$!
657 empathy_players+=($player)
660 empathy_player_reactivate()
663 player_pid=${player}_pid
665 empathy_get $player events >/dev/null 2>&1 &
666 eval ${player_pid}=$!
669 # Usage: empathy_player_deactivate <player_name>
670 empathy_player_deactivate()
673 player_pid=${player}_pid
674 if [ "${!player_pid}" != "" ]; then
675 pkill -P ${!player_pid}
677 eval ${player_pid}=""
680 empathy_deactivate_all()
682 for player in ${empathy_players[*]}; do
683 empathy_player_deactivate $player
687 # Pulls a single named event out of the empathy event stream
689 # Usage: empathy_get_event <player_name> <event_name>
692 empathy_get $1 events "-m 0.1" 2>&1 \
693 | grep "^event: $2" -A 1 \
695 | sed -e 's,^data: *,,'
698 # Usage: empathy_player_name <player_name>
699 empathy_player_name()
701 empathy_get_event $1 player-info | jq -r .name
704 TEST "Set 'alice' in session"
705 empathy_player_activate alice
706 test "$alice_cookie" = ".cookie-empathy-alice"
709 TEST "Register alice and verify name"
710 result=$(empathy_player_name alice)
711 test "$result" = "alice"
715 empathy_player_activate bob
716 result=$(empathy_player_name bob)
717 test "$result" = "bob"
720 TEST "Register charlie"
721 empathy_player_activate charlie
722 result=$(empathy_player_name charlie)
723 test "$result" = "charlie"
726 TEST_SUBSECTION "Category selection"
728 # Usage: empathy_submit_prompt <player_name> <count> <prompt_string>
729 empathy_submit_prompt()
731 empathy_post $1 prompts "{ \"items\": $2, \"prompt\": \"$3\"}"
734 TEST "Huge numbers are rejected"
735 result=$(empathy_submit_prompt alice 10000 "10,000 Maniacs")
736 test "$result" = '{"valid":false,"message":"Maximum number of items is 20"}'
739 TEST "Submit a category"
740 prompt_id=$(empathy_submit_prompt alice 4 "4 things on a beach" | jq .id)
741 test "$prompt_id" = "1"
744 # Usage: empathy_vote <player_name> <prompt_id>
747 empathy_post $1 vote/$2
750 TEST "Vote on this category"
751 empathy_vote alice $prompt_id
755 # Usage: empathy_start <player_name> <prompt_id>
758 empathy_post $1 start/$2
761 TEST "Start the game with this category"
762 empathy_start alice $prompt_id
766 # Usage: empathy_answer <player_name> <prompt_id> <answers_string>
769 empathy_post $1 answer/$2 "{ \"answers\": [$3]}"
772 TEST_SUBSECTION "Submitting answers"
774 TEST "Submit from a non-player fails"
775 bogus_cookie=/dev/null
776 result=$(empathy_answer bogus $prompt_id '"Sun", "Sand", "Water", "People"')
777 test "$result" = '{"valid":false,"message":"Player not found"}'
780 TEST "Submit from alice succeeds"
781 result=$(empathy_answer alice $prompt_id '"sun", "sand", "water", "people"')
782 test "$result" = '{"valid":true}'
785 TEST "Submit from bob succeeds"
786 result=$(empathy_answer bob $prompt_id '"sand", "sands", "SunLight", "towels"')
787 test "$result" = '{"valid":true}'
790 # Usage: empathy_ambiguities <player_name>
791 empathy_ambiguities()
793 empathy_get_event $1 game-state | jq .ambiguities
796 TEST "Judging hasn't started with player unsubmitted"
797 result=$(echo $(empathy_ambiguities alice))
798 test "$result" = "null"
801 TEST "Submit from charlie succeeds"
802 result=$(empathy_answer charlie $prompt_id '"SunShine", "Grains of Sand", "wafer", "people"')
803 test "$result" = '{"valid":true}'
806 TEST_SUBSECTION "Transition from answering to judging (no voting needed)"
808 TEST "Judging already started"
809 result=$(echo $(empathy_ambiguities alice))
810 test "$result" != "null"
813 TEST_SUBSECTION "Judging answers"
815 # Usage: empathy_ambiguities_list <player_name>
816 empathy_ambiguities_list()
818 empathy_get_event $1 game-state | jq .ambiguities[]
821 TEST "Received all unique words"
822 # echo here is to strip newlines
823 result=$(echo $(empathy_ambiguities_list alice))
824 test "$result" = '"Grains of Sand" "people" "sand" "sands" "sun" "SunLight" "SunShine" "towels" "wafer" "water"'
827 # Usage: empathy_judged <player_name> <prompt_id> <word_groups_string>
830 empathy_post $1 judged/$2 "{ \"word_groups\": $3}"
833 TEST "Submit word groups from alice"
834 result=$(empathy_judged alice $prompt_id '[{"words":["sun","SunLight","SunShine"],"kudos":false},{"words":["sand","sands","Grains of Sand"],"kudos":false},{"words":["water","wafer"],"kudos":false}]')
835 test "$result" = '{"valid":true}'
838 TEST "Submit word groups from bob"
839 result=$(empathy_judged bob $prompt_id '[{"words":["sands","grains of sand"],"kudos":false},{"words":["water","wafer"],"kudos":false}]')
840 test "$result" = '{"valid":true}'
843 # Usage: empathy_scores <player_name>
846 empathy_get_event $1 game-state | jq .scores
849 TEST "Scoring hasn't started with player unsubmitted"
850 result=$(echo $(empathy_scores alice))
851 test "$result" = "null"
854 TEST "Submit word groups from charlie"
855 result=$(empathy_judged charlie $prompt_id '[{"words":["SunLight","SunShine"],"kudos":false},{"words":["sand","Grains of Sand"],"kudos":false}]')
856 test "$result" = '{"valid":true}'
859 TEST_SUBSECTION "Transition from judging to scoring (no voting needed)"
861 TEST "Scoring already started"
862 result=$(echo $(empathy_scores alice))
863 test "$result" != "null"
866 # Usage: empathy_scores_names_numbers <player_name>
867 empathy_scores_names_numbers()
869 empathy_get_event $1 game-state | jq '.scores.scores[]|.players[],.score'
872 TEST_SUBSECTION "Scoring"
874 TEST "Verify final scores as expected"
875 # echo here is to strip newlines
876 result=$(echo $(empathy_scores_names_numbers alice))
877 test "$result" = '"charlie" 9 "alice" 8 "bob" 6'
880 # Usage: empathy_words_submitted <player_name>
881 empathy_words_submitted()
883 empathy_get_event $1 game-state | jq '.scores.words[].word'
886 TEST "Verify final list of words submitted"
887 # echo here is to strip newlines
888 result=$(echo $(empathy_words_submitted alice))
889 test "$result" = '"Grains of Sand/sand/sands" "SunLight/SunShine" "wafer/water" "people" "sun" "towels"'
892 TEST_SUBSECTION "New game (using voting to advance phases)"
896 curl_post $empathy_game_path/reset
899 TEST "Any post to /reset resets the game"
904 TEST "Verify scoring is over"
905 result=$(echo $(empathy_scores alice))
906 test "$result" = "null"
909 # Usage: empathy_answering <player_name> <prompt_id>
912 empathy_post $1 answering/$2
915 TEST "Start 4-player game, 3 submissions"
916 empathy_player_activate dale
917 result=$(empathy_player_name dale)
918 test "$result" = "dale"
919 prompt_id=$(empathy_submit_prompt alice 4 "3 little words" | jq .id)
920 empathy_start alice $prompt_id
921 empathy_answer alice $prompt_id '"I", "love", "you"' >/dev/null
922 empathy_answer bob $prompt_id '"I", "love", "food"' >/dev/null
923 empathy_answer charlie $prompt_id '"food", "is", "good"' >/dev/null
924 result=$(empathy_answering dale $prompt_id)
925 test "$result" = '{"valid":true}'
928 TEST "Judging hasn't started with player unsubmitted"
929 result=$(echo $(empathy_ambiguities alice))
930 test "$result" = "null"
933 # Usage: empathy_end_answers <player_name> <prompt_id>
934 empathy_end_answers()
936 empathy_post $1 end-answers/$2
939 TEST "Minority of players vote to end answering"
940 empathy_end_answers alice $prompt_id
941 empathy_end_answers bob $prompt_id
945 TEST "Judging still hasn't started"
946 result=$(echo $(empathy_ambiguities alice))
947 test "$result" = "null"
950 TEST "Majority of players vote to end answering"
951 empathy_end_answers charlie $prompt_id
955 TEST "Judging has now started"
956 result=$(echo $(empathy_ambiguities alice))
957 test "$result" != "null"
960 # Usage: empathy_players_judging <player_name>
961 empathy_players_judging()
963 empathy_get_event $1 game-state | jq .players_judging[]
966 TEST "Verify active players listed as judging"
967 # echo here is to strip newlines
968 result=$(echo $(empathy_players_judging alice))
969 test "$result" = '"alice" "bob" "charlie"'
972 TEST "Submit word groups from majority"
973 empathy_judged alice $prompt_id '[]' >/dev/null
974 result=$(empathy_judged bob $prompt_id '[]')
975 test "$result" = '{"valid":true}'
978 TEST "Scoring hasn't started with player unsubmitted"
979 result=$(echo $(empathy_scores alice))
980 test "$result" = "null"
983 # Usage: empathy_end_judging <player_name> <prompt_id>
984 empathy_end_judging()
986 empathy_post $1 end-judging/$2
989 TEST "Minority of players vote to end judging"
990 empathy_end_judging alice $prompt_id
994 TEST "Scoring still hasn't started"
995 result=$(echo $(empathy_scores alice))
996 test "$result" = "null"
999 TEST "Majority of players vote to end judging"
1000 empathy_end_judging bob $prompt_id
1004 TEST "Scoring has now started"
1005 result=$(echo $(empathy_scores alice))
1006 test "$result" != "null"
1009 TEST_SUBSECTION "New game (no voting needed when all answered players judge)"
1011 TEST "Start 4-player game, 3 submissions"
1013 prompt_id=$(empathy_submit_prompt alice 4 "1 truth or dare" | jq .id)
1014 empathy_start alice $prompt_id
1015 empathy_answer alice $prompt_id '"truth"' >/dev/null
1016 empathy_answer bob $prompt_id '"truth"' >/dev/null
1017 empathy_answer charlie $prompt_id '"dare"' >/dev/null
1018 empathy_end_answers alice $prompt_id
1019 empathy_end_answers bob $prompt_id
1020 empathy_end_answers charlie $prompt_id
1024 TEST "Submit word groups from 2 players"
1025 empathy_judged alice $prompt_id '[]' >/dev/null
1026 result=$(empathy_judged bob $prompt_id '[]')
1027 test "$result" = '{"valid":true}'
1030 TEST "Scoring hasn't started with player unsubmitted"
1031 result=$(echo $(empathy_scores alice))
1032 test "$result" = "null"
1035 TEST "Submit word groups from a non-answering player"
1036 result=$(empathy_judged dale $prompt_id '[]')
1037 test "$result" = '{"valid":true}'
1040 TEST "Scoring still hasn't started"
1041 result=$(echo $(empathy_scores alice))
1042 test "$result" = "null"
1045 TEST "Submit word groups from last answering player"
1046 result=$(empathy_judged charlie $prompt_id '[]')
1047 test "$result" = '{"valid":true}'
1050 TEST "Scoring has now started"
1051 result=$(echo $(empathy_scores alice))
1052 test "$result" != "null"
1055 TEST_SUBSECTION "Non players don't affect judging requirements"
1057 TEST "Start 2-player game with 6 registered players"
1059 empathy_player_activate eric
1060 empathy_player_activate fred
1061 prompt_id=$(empathy_submit_prompt alice 4 "1 truth or dare" | jq .id)
1062 empathy_start alice $prompt_id
1063 empathy_answer alice $prompt_id '"truth"' >/dev/null
1064 empathy_answer bob $prompt_id '"true"' >/dev/null
1065 empathy_end_answers alice $prompt_id
1066 empathy_end_answers bob $prompt_id
1070 TEST "1 player votes for a match"
1071 empathy_judged alice $prompt_id '[{"words":["truth","true"],"kudos":false}]' >/dev/null
1072 result=$(empathy_judged bob $prompt_id '[]')
1073 test "$result" = '{"valid":true}'
1076 TEST "Verify the match passed the vote"
1077 # echo here is to strip newlines
1078 result=$(echo $(empathy_scores_names_numbers alice))
1079 test "$result" = '"alice" "bob" 2 "charlie" "dale" "eric" "fred" 0'
1083 echo "NOTE: Slow tests ahead!"
1084 echo "If you are impatient and somehow \"know\" you don't care about the"
1085 echo "tests below then you can interrupt the test suite with Control-C"
1086 echo "to get a summary report on the tests that have already been run."
1088 TEST_SUBSECTION "Inactive players don't appear in scores"
1090 TEST "Start 2-player game with 6 registered players"
1092 prompt_id=$(empathy_submit_prompt alice 4 "1 best pet" | jq .id)
1093 empathy_start alice $prompt_id
1094 empathy_answer alice $prompt_id '"cats"' >/dev/null
1095 empathy_answer bob $prompt_id '"dogs"' >/dev/null
1096 empathy_end_answers alice $prompt_id
1097 empathy_end_answers bob $prompt_id
1101 TEST "Deactivate 3 players"
1102 empathy_player_deactivate dale
1103 empathy_player_deactivate eric
1104 empathy_player_deactivate fred
1109 TEST "Finish game with 2 active players"
1110 empathy_judged alice $prompt_id '[]' >/dev/null
1111 result=$(empathy_judged bob $prompt_id '[]')
1112 test "$result" = '{"valid":true}'
1115 TEST "Verify scores don't include inactive players"
1116 # echo here is to strip newlines
1117 result=$(echo $(empathy_scores_names_numbers alice))
1118 test "$result" = '"alice" "bob" 1 "charlie" 0'
1121 TEST_SUBSECTION "Deactivated players don't block future game phase advances"
1123 TEST "New 3-player game, 2 submit right away"
1125 prompt_id=$(empathy_submit_prompt charlie 4 "2 legit 2 quit" | jq .id)
1126 empathy_start alice $prompt_id
1127 empathy_answer alice $prompt_id '"what", "gives?"' >/dev/null
1128 empathy_answer bob $prompt_id '"so", "confused"' >/dev/null
1132 TEST "Judging hasn't started with player unsubmitted"
1133 result=$(echo $(empathy_ambiguities alice))
1134 test "$result" = "null"
1137 TEST "Final active player submits"
1138 result=$(empathy_answer charlie $prompt_id '"best", "category"')
1139 test "$result" = '{"valid":true}'
1142 TEST "Judging has started (don't need inactive players)"
1143 result=$(echo $(empathy_ambiguities alice))
1144 test "$result" != "null"
1147 TEST "Submit word groups from 2 players"
1148 empathy_judged alice $prompt_id '[]' >/dev/null
1149 result=$(empathy_judged bob $prompt_id '[]')
1150 test "$result" = '{"valid":true}'
1153 TEST "Scoring hasn't started with player unsubmitted"
1154 result=$(echo $(empathy_scores alice))
1155 test "$result" = "null"
1158 TEST "Submit word groups from last answering player"
1159 result=$(empathy_judged charlie $prompt_id '[]')
1160 test "$result" = '{"valid":true}'
1163 TEST "Scoring has now started"
1164 result=$(echo $(empathy_scores alice))
1165 test "$result" != "null"
1168 TEST_SUBSECTION "Reactivated player is fully active"
1170 TEST "The dale player is currently deactivated"
1171 test "$dale_pid" = ""
1174 TEST "Reactivate dale"
1175 empathy_player_reactivate dale
1176 test "$dale_pid" != ""
1179 TEST "New 4-player game, 3 submit right away"
1181 prompt_id=$(empathy_submit_prompt alice 1 "favorite letter" | jq .id)
1182 empathy_start alice $prompt_id
1183 empathy_answer alice $prompt_id '"A"' >/dev/null
1184 empathy_answer bob $prompt_id '"B"' >/dev/null
1185 empathy_answer charlie $prompt_id '"C"' >/dev/null
1189 TEST "Judging hasn't started with player unsubmitted"
1190 result=$(echo $(empathy_ambiguities alice))
1191 test "$result" = "null"
1194 TEST "Final active player submits"
1195 result=$(empathy_answer dale $prompt_id '"D"')
1196 test "$result" = '{"valid":true}'
1199 TEST "Judging has started now"
1200 result=$(echo $(empathy_ambiguities alice))
1201 test "$result" != "null"