]> git.cworth.org Git - lmno-server/blob - test
test: Add failing test case for unnecessary delay for end-judging voting
[lmno-server] / test
1 #!/bin/bash
2
3 usage ()
4 {
5     echo "Usage:$0 <URL-to-test>"
6 }
7
8 if [ $# -lt 1 ]; then
9     echo "Error: No test URL given." >&2
10     echo "" >&2
11     usage >&2
12     exit 1
13 fi
14
15 URL=$1
16 CURL="curl --silent --show-error"
17
18 _TEST_SECTION()
19 {
20     echo ""
21     echo $1
22     echo $1 | sed -e "s/./$2/g"
23 }
24
25 TEST_SECTION()
26 {
27     _TEST_SECTION "$1" =
28 }
29
30 TEST_SUBSECTION()
31 {
32     _TEST_SECTION "$1" -
33 }
34
35 TEST()
36 {
37     printf "    $1"
38     printf "%*s" $(( 52 - ${#1} )) | tr ' ' '.'
39     (( tests_total++ )) || true
40 }
41
42 # Result of test depends on the exit status of last command
43 TEST_END()
44 {
45     if [ $? -eq 0 ]; then
46         echo -n "OK"
47     else
48         (( tests_failed++ )) || true
49         echo -n "FAIL"
50     fi
51
52     # If we got an argument, append it after test result
53     if [ -n "$1" ]; then
54         echo " $1"
55     else
56         echo ""
57     fi
58 }
59
60 # Print report of all previous test results
61 TEST_REPORT()
62 {
63     echo ""
64     echo "Test Report"
65     echo "==========="
66
67     if [ "$tests_failed" == "" ]; then
68         echo "All $tests_total tests passed."
69         echo ""
70         return 0
71     else
72         echo "$tests_failed of $tests_total tests failed."
73         echo ""
74         return 1
75     fi
76 }
77
78 # Does a string contain a regular expression pattern
79 #
80 # Example:
81 #
82 #    contains "All's well that ends well" "s.well"
83 contains()
84 {
85     grep -q "$2" <<< $1
86 }
87
88 # POST to a URL endpoint with optional JSON data
89 #
90 # Usage:
91 #
92 # curl_post <ENDPOINT> [data] [CURL_OPTIONS]
93 curl_post()
94 {
95     $CURL ${3:-} -X POST ${2:+-H 'Content-Type: application/json' -d "$2"} $URL/$1
96 }
97
98 # POST to a URL endpoint with optional JSON data using a cookie
99 #
100 # Usage:
101 #
102 # curl_post_cookie <name> <ENDPOINT> [data] [CURL_OPTIONS]
103 #
104 # Where <name> is a string for which there is a defined variable
105 # named ${name}_cookie which in turn holds a value that is a filename
106 # of a valid cookie
107 curl_post_cookie()
108 {
109     cookie=${1}_cookie
110     curl_post $2 "${3:-}" "-b ${!cookie} ${4:-}"
111 }
112
113 # PUT to a URL endpoint with optional JSON data
114 #
115 # Usage:
116 #
117 # curl_post <ENDPOINT> [data] [CURL_OPTIONS]
118 curl_put()
119 {
120     $CURL ${3:-} -X PUT ${2:+-H 'Content-Type: application/json' -d "$2"} $URL/$1
121 }
122
123 # GET from a URL endpoint
124 #
125 # Usage:
126 #
127 # curl_get <ENDPOINT> [CURL_OPTIONS]
128 curl_get()
129 {
130     $CURL ${2:-} $URL/$1
131 }
132
133 # GET from a URL endpoint using a cookie
134 #
135 # Usage:
136 #
137 # curl_get_cookie <name> <ENDPOINT> [CURL_OPTIONS]
138 #
139 # Where <name> is a string for which there is a defined variable
140 # named ${name}_cookie which in turn holds a value that is a filename
141 # of a valid cookie
142 curl_get_cookie()
143 {
144     cookie=${1}_cookie
145     curl_get $2 "-b ${!cookie} ${3:-}"
146 }
147
148 # Create a new game of the specified engine type
149 #
150 # Usage:
151 #
152 # new_game <ENGINE>
153 new_game()
154 {
155     curl_post new/$1 | jq -r .
156 }
157
158 TEST_SECTION "LMNO (super-site for games)"
159
160 TEST_SUBSECTION "Testing home page"
161 home_page=$($CURL $URL)
162
163 TEST "Contains 'Join Game'"
164 contains "$home_page" "Join Game"
165 TEST_END
166
167 TEST "Contains 'Host a new game'"
168 contains "$home_page" "Host a new game"
169 TEST_END
170
171 TEST_SUBSECTION "Creating some new games"
172
173 TEST "Empires"
174 empires_game_id=$(new_game empires)
175 test "$empires_game_id" != ""
176 TEST_END $empires_game_id
177
178 TEST "Tic Tac Toe"
179 tictactoe_game_id=$(new_game tictactoe)
180 test "$tictactoe_game_id" != ""
181 TEST_END $tictactoe_game_id
182
183 TEST_SUBSECTION "Test redirects"
184
185 TEST "Redirect of /GAMEID at top level"
186 redirect=$(curl_get $empires_game_id)
187 test "$redirect" = "Moved Permanently. Redirecting to /empires/$empires_game_id/"
188 TEST_END
189
190 TEST "Redirect of lowercase /gameid at top level"
191 empires_game_id_lower=$(tr '[:upper:]' '[:lower:]' <<< $empires_game_id)
192 redirect=$(curl_get $empires_game_id_lower)
193 test "$redirect" = "Moved Permanently. Redirecting to /$empires_game_id/"
194 TEST_END
195
196 TEST "Redirect of lowercase /empires/gameid"
197 redirect=$(curl_get empires/$empires_game_id_lower)
198 test "$redirect" = "Moved Permanently. Redirecting to /empires/$empires_game_id/"
199 TEST_END
200
201 TEST_SECTION "Empires game"
202
203 empires_game_path=empires/$empires_game_id
204
205 TEST_SUBSECTION "Empires game /register"
206
207 empires_register()
208 {
209     curl_post $empires_game_path/register "{\"name\": \"$1\", \"character\": \"$2\"}"
210 }
211
212 empires_players_string()
213 {
214     curl_get $empires_game_path/players | jq -r .[].name | tr '\n' ','
215 }
216
217 empires_characters_string()
218 {
219     curl_get $empires_game_path/characters | jq -r .[] | tr '\n' ','
220 }
221
222 TEST "Registering a player returns an ID"
223 carl_id=$(empires_register Carl "Bugs Bunny" | jq -r .)
224 test "$carl_id" = "1"
225 TEST_END
226
227 TEST "Registering several more players"
228 empires_register Richard "Bob Hope" > /dev/null
229 empires_register Kevin "Elvis Presley" > /dev/null
230 empires_register Stacy Phineas > /dev/null
231 empires_register David "Red Power Ranger" > /dev/null
232 empires_register Nancy "Audrey Hepburn" > /dev/null
233 bogus_id=$(empires_register Bogus "Mr. Bogus")
234 TEST_END
235
236 TEST 'Verify complete players list (with "Bogus")'
237 players=$(empires_players_string)
238 test "$players" = "Carl,Richard,Kevin,Stacy,David,Nancy,Bogus,"
239 TEST_END
240
241 TEST 'Verify complete players list (with "Mr. Bogus")'
242 characters=$(empires_characters_string)
243 test "$characters" = "Bugs Bunny,Bob Hope,Elvis Presley,Phineas,Red Power Ranger,Audrey Hepburn,Mr. Bogus,"
244 TEST_END
245
246 TEST_SUBSECTION "Empires game /deregister"
247
248 empires_deregister()
249 {
250     curl_post $empires_game_path/deregister/$1
251 }
252
253 TEST "Removing the bogus player"
254 empires_deregister $bogus_id
255 TEST_END
256
257 TEST 'Verify modified players list (w/o "Bogus")"'
258 players=$(empires_players_string)
259 test "$players" = "Carl,Richard,Kevin,Stacy,David,Nancy,"
260 TEST_END
261
262 TEST 'Verify modified characters list (w/o "Mr. Bogus")'
263 characters=$(empires_characters_string)
264 test "$characters" = "Bugs Bunny,Bob Hope,Elvis Presley,Phineas,Red Power Ranger,Audrey Hepburn,"
265 TEST_END
266
267 TEST_SUBSECTION "Empires game /capture"
268
269 empires_capture()
270 {
271     curl_post $empires_game_path/capture/$1/$2
272 }
273
274 empires_empires_string()
275 {
276     # Get empires as a compact string (much more compact than JSON)
277     curl_get $empires_game_path/empires | jq -c '.[] | [.id,.captures]' | tr '\n' ','
278 }
279
280 TEST "Verify empires before any captures"
281 empires=$(empires_empires_string)
282 test "$empires" = "[1,[]],[2,[]],[3,[]],[4,[]],[5,[]],[6,[]],"
283 TEST_END
284
285 TEST "Perform some captures"
286 empires_capture 1 2
287 empires_capture 3 5
288 empires_capture 4 6
289 empires_capture 3 4
290 TEST_END
291
292 TEST "Verify empires after captures"
293 empires=$(empires_empires_string)
294 test "$empires" = "[1,[2]],[2,[]],[3,[5,4]],[4,[6]],[5,[]],[6,[]],"
295 TEST_END
296
297 TEST_SUBSECTION "Empires game /liberate"
298
299 empires_liberate()
300 {
301     curl_post $empires_game_path/liberate/$1
302 }
303
304 TEST "Liberate a player"
305 empires_liberate 2
306 TEST_END
307
308 TEST "Verify empires after liberate"
309 empires=$(empires_empires_string)
310 test "$empires" = "[1,[]],[2,[]],[3,[5,4]],[4,[6]],[5,[]],[6,[]],"
311 TEST_END
312
313 TEST_SUBSECTION "Empires game /reset"
314
315 empires_reset()
316 {
317     curl_post $empires_game_path/reset
318 }
319
320 TEST "Reset the game"
321 empires_reset
322 TEST_END
323
324 TEST "Verify players is now empty"
325 players=$(empires_players_string)
326 test "$players" = ""
327 TEST_END
328
329 TEST_SECTION "Tic Tac Toe game"
330
331 tictactoe_game_path=tictactoe/$tictactoe_game_id
332
333 tictactoe_profile()
334 {
335     curl_put /profile "{ \"nickname\": \"$1\" }" "-c .cookie-tictactoe"
336 }
337
338 tictactoe_move()
339 {
340     curl_post $tictactoe_game_path/move "{ \"move\": $1 }" "-b .cookie-tictactoe"
341 }
342
343 tictactoe_player_info()
344 {
345     curl_get $tictactoe_game_path/events  "-m 0.1 -b .cookie-tictactoe" 2>&1 \
346         | grep player-info -A 1 \
347         | grep ^data
348 }
349
350 tictactoe_player_name()
351 {
352     curl_put $tictactoe_game_path/player "{ \"name\": \"$1\" }" "-b .cookie-tictactoe"
353 }
354
355 tictactoe_player_team()
356 {
357     curl_put $tictactoe_game_path/player "{ \"team\": \"$1\" }" "-b .cookie-tictactoe"
358 }
359
360 TEST_SUBSECTION "Tic Tac Toe player-info"
361
362 TEST "Hit LMNO /profile to set name to 'curl'"
363 tictactoe_profile curl
364 TEST_END
365
366 TEST "Verify player-info event reports 'curl' name"
367 result=$(tictactoe_player_info)
368 test "$result" = 'data: {"id":1,"name":"curl","team":""}'
369 TEST_END
370
371 TEST_SUBSECTION "Tic Tac Toe /player"
372
373 TEST "Change name to 'newname'"
374 tictactoe_player_name newname
375 result=$(tictactoe_player_info)
376 test "$result" = 'data: {"id":1,"name":"newname","team":""}'
377 TEST_END
378
379 TEST "Change team to 'X'"
380 tictactoe_player_team X
381 result=$(tictactoe_player_info)
382 test "$result" = 'data: {"id":1,"name":"newname","team":"X"}'
383 TEST_END
384
385 TEST "Change team to 'O'"
386 tictactoe_player_team O
387 result=$(tictactoe_player_info)
388 test "$result" = 'data: {"id":1,"name":"newname","team":"O"}'
389 TEST_END
390
391 TEST "Verify cannot change team to 'Z'"
392 tictactoe_player_team Z
393 result=$(tictactoe_player_info)
394 test "$result" = 'data: {"id":1,"name":"newname","team":"O"}'
395 TEST_END
396
397 TEST "Leave current team"
398 tictactoe_player_team ""
399 result=$(tictactoe_player_info)
400 test "$result" = 'data: {"id":1,"name":"newname","team":""}'
401 TEST_END
402
403 TEST_SUBSECTION "Tic Tac Toe /move"
404
405 TEST "First move doesn't require a team"
406 result=$(tictactoe_move 0)
407 test "$result" = '{"legal":true}'
408 TEST_END
409
410 TEST "Second move does require a team"
411 result=$(tictactoe_move 4)
412 test "$result" = '{"legal":false,"message":"It'"'"'s not your turn to move"}'
413 TEST_END
414
415 TEST "Illegal to move when it's not your turn"
416 tictactoe_player_team X
417 result=$(tictactoe_move 4)
418 test "$result" = '{"legal":false,"message":"It'"'"'s not your turn to move"}'
419 TEST_END
420
421 TEST "Legal move to center square"
422 tictactoe_player_team O
423 result=$(tictactoe_move 4)
424 test "$result" = '{"legal":true}'
425 TEST_END
426
427 TEST "Move to center square again is now illegal"
428 tictactoe_player_team X
429 result=$(tictactoe_move 4)
430 test "$result" = '{"legal":false,"message":"Square is already occupied"}'
431 TEST_END
432
433 TEST_SECTION "Empathy game"
434
435 TEST_SUBSECTION "Create a game and register 3 players"
436
437 TEST "Create the game"
438 empathy_game_id=$(new_game empathy)
439 test "$empathy_game_id" != ""
440 TEST_END $empathy_game_id
441
442 empathy_game_path=empathy/$empathy_game_id
443
444 # Usage: empathy_get <player_name> <endpoint> [curl_options]
445 empathy_get()
446 {
447     curl_get_cookie $1 $empathy_game_path/$2 "${3:-}"
448 }
449
450 # Usage: empathy_post <player_name> <endpoint> [data]
451 empathy_post()
452 {
453     curl_post_cookie $1 $empathy_game_path/$2 "${3:-}"
454 }
455
456 # Given a player name as $1 (eg. "empathy_player_activate alice") set both
457 # $1_cookie and $1_pid (that is $alice_cookie and $alice_pid) to
458 # a filename containing a cookie and the PID of a running event-streaming
459 # process.
460 empathy_player_activate()
461 {
462     player="$1"
463     player_cookie=${player}_cookie
464     player_pid=${player}_pid
465
466     eval ${player_cookie}=".cookie-empathy-$player"
467     curl_put /profile "{ \"nickname\": \"$player\" }" "-c ${!player_cookie}"
468     empathy_get $player events >/dev/null 2>&1 &
469     eval ${player_pid}=$!
470 }
471
472 # Pulls a single named event out of the empathy event stream
473 #
474 # Usage: empathy_get_event <player_name> <event_name>
475 empathy_get_event()
476 {
477     empathy_get $1 events "-m 0.1" 2>&1 \
478         | grep "^event: $2" -A 1 \
479         | grep ^data: \
480         | sed -e 's,^data: *,,'
481 }
482
483 # Usage: empathy_player_name <player_name>
484 empathy_player_name()
485 {
486     empathy_get_event $1 player-info | jq -r .name
487 }
488
489 TEST "Set 'alice' in session"
490 empathy_player_activate alice
491 test "$alice_cookie" = ".cookie-empathy-alice"
492 TEST_END
493
494 TEST "Register alice and verify name"
495 result=$(empathy_player_name alice)
496 test "$result" = "alice"
497 TEST_END
498
499 TEST "Register bob"
500 empathy_player_activate bob
501 result=$(empathy_player_name bob)
502 test "$result" = "bob"
503 TEST_END
504
505 TEST "Register charlie"
506 empathy_player_activate charlie
507 result=$(empathy_player_name charlie)
508 test "$result" = "charlie"
509 TEST_END
510
511 TEST_SUBSECTION "Category selection"
512
513 # Usage: empathy_submit_prompt <player_name> <count> <prompt_string>
514 empathy_submit_prompt()
515 {
516     empathy_post $1 prompts "{ \"items\": $2, \"prompt\": \"$3\"}"
517 }
518
519 TEST "Huge numbers are rejected"
520 result=$(empathy_submit_prompt alice 10000 "10,000 Maniacs")
521 test "$result" = '{"valid":false,"message":"Maximum number of items is 20"}'
522 TEST_END
523
524 TEST "Submit a category"
525 prompt_id=$(empathy_submit_prompt alice 4 "4 things on a beach" | jq .id)
526 test "$prompt_id" = "1"
527 TEST_END
528
529 # Usage: empathy_vote <player_name> <prompt_id>
530 empathy_vote()
531 {
532     empathy_post $1 vote/$2
533 }
534
535 TEST "Vote on this category"
536 empathy_vote alice $prompt_id
537 test "$?" = "0"
538 TEST_END
539
540 # Usage: empathy_start <player_name> <prompt_id>
541 empathy_start()
542 {
543     empathy_post $1 start/$2
544 }
545
546 TEST "Start the game with this category"
547 empathy_start alice $prompt_id
548 test "$?" = "0"
549 TEST_END
550
551 # Usage: empathy_answer <player_name> <prompt_id> <answers_string>
552 empathy_answer()
553 {
554     empathy_post $1 answer/$2 "{ \"answers\": [$3]}"
555 }
556
557 TEST_SUBSECTION "Submitting answers"
558
559 TEST "Submit from a non-player fails"
560 bogus_cookie=/dev/null
561 result=$(empathy_answer bogus $prompt_id '"Sun", "Sand", "Water", "People"')
562 test "$result" = '{"valid":false,"message":"Player not found"}'
563 TEST_END
564
565 TEST "Submit from alice succeeds"
566 result=$(empathy_answer alice $prompt_id '"sun", "sand", "water", "people"')
567 test "$result" = '{"valid":true}'
568 TEST_END
569
570 TEST "Submit from bob succeeds"
571 result=$(empathy_answer bob $prompt_id '"sand", "sands", "SunLight", "towels"')
572 test "$result" = '{"valid":true}'
573 TEST_END
574
575 # Usage: empathy_ambiguities <player_name>
576 empathy_ambiguities()
577 {
578     empathy_get_event $1 game-state | jq .ambiguities
579 }
580
581 TEST "Judging hasn't started with player unsubmitted"
582 result=$(echo $(empathy_ambiguities alice))
583 test "$result" = "null"
584 TEST_END
585
586 TEST "Submit from charlie succeeds"
587 result=$(empathy_answer charlie $prompt_id '"SunShine", "Grains of Sand", "wafer", "people"')
588 test "$result" = '{"valid":true}'
589 TEST_END
590
591 TEST_SUBSECTION "Transition from answering to judging (no voting needed)"
592
593 TEST "Judging already started"
594 result=$(echo $(empathy_ambiguities alice))
595 test "$result" != "null"
596 TEST_END
597
598 TEST_SUBSECTION "Judging answers"
599
600 # Usage: empathy_ambiguities_list <player_name>
601 empathy_ambiguities_list()
602 {
603     empathy_get_event $1 game-state | jq .ambiguities[]
604 }
605
606 TEST "Received all unique words"
607 # echo here is to strip newlines
608 result=$(echo $(empathy_ambiguities_list alice))
609 test "$result" = '"Grains of Sand" "people" "sand" "sands" "sun" "SunLight" "SunShine" "towels" "wafer" "water"'
610 TEST_END
611
612 # Usage: empathy_judged <player_name> <prompt_id> <word_groups_string>
613 empathy_judged()
614 {
615     empathy_post $1 judged/$2 "{ \"word_groups\": $3}"
616 }
617
618 TEST "Submit word groups from alice"
619 result=$(empathy_judged alice $prompt_id '[["sun","SunLight","SunShine"],["sand","sands","Grains of Sand"],["water","wafer"]]')
620 test "$result" = '{"valid":true}'
621 TEST_END
622
623 TEST "Submit word groups from bob"
624 result=$(empathy_judged bob $prompt_id '[["sands","grains of sand"],["water","wafer"]]')
625 test "$result" = '{"valid":true}'
626 TEST_END
627
628 # Usage: empathy_scores <player_name>
629 empathy_scores()
630 {
631     empathy_get_event $1 game-state | jq .scores
632 }
633
634 TEST "Scoring hasn't started with player unsubmitted"
635 result=$(echo $(empathy_scores alice))
636 test "$result" = "null"
637 TEST_END
638
639 TEST "Submit word groups from charlie"
640 result=$(empathy_judged charlie $prompt_id '[["SunLight","SunShine"],["sand","Grains of Sand"]]')
641 test "$result" = '{"valid":true}'
642 TEST_END
643
644 TEST_SUBSECTION "Transition from judging to scoring (no voting needed)"
645
646 TEST "Scoring already started"
647 result=$(echo $(empathy_scores alice))
648 test "$result" != "null"
649 TEST_END
650
651 # Usage: empathy_scores_names_numbers <player_name>
652 empathy_scores_names_numbers()
653 {
654     empathy_get_event $1 game-state | jq '.scores.scores[]|.player,.score'
655 }
656
657 TEST_SUBSECTION "Scoring"
658
659 TEST "Verify final scores as expected"
660 # echo here is to strip newlines
661 result=$(echo $(empathy_scores_names_numbers alice))
662 test "$result" = '"charlie" 9 "alice" 8 "bob" 6'
663 TEST_END
664
665 # Usage: empathy_words_submitted <player_name>
666 empathy_words_submitted()
667 {
668     empathy_get_event $1 game-state | jq '.scores.words[].word'
669 }
670
671 TEST "Verify final list of words submitted"
672 # echo here is to strip newlines
673 result=$(echo $(empathy_words_submitted alice))
674 test "$result" = '"Grains of Sand/sand/sands" "SunLight/SunShine" "wafer/water" "people" "sun" "towels"'
675 TEST_END
676
677 TEST_SUBSECTION "New game (using voting to advance phases)"
678
679 empathy_reset()
680 {
681     curl_post $empathy_game_path/reset
682 }
683
684 TEST "Any post to /reset resets the game"
685 empathy_reset
686 test "$?" = "0"
687 TEST_END
688
689 TEST "Verify scoring is over"
690 result=$(echo $(empathy_scores alice))
691 test "$result" = "null"
692 TEST_END
693
694 # Usage: empathy_answering <player_name> <prompt_id>
695 empathy_answering()
696 {
697     empathy_post $1 answering/$2
698 }
699
700 TEST "Start 4-player game, 3 submissions"
701 empathy_player_activate dale
702 result=$(empathy_player_name dale)
703 test "$result" = "dale"
704 prompt_id=$(empathy_submit_prompt alice 4 "3 little words" | jq .id)
705 empathy_start alice $prompt_id
706 empathy_answer alice   $prompt_id '"I",    "love", "you"' >/dev/null
707 empathy_answer bob     $prompt_id '"I",    "love", "food"' >/dev/null
708 empathy_answer charlie $prompt_id '"food", "is",   "good"' >/dev/null
709 result=$(empathy_answering dale $prompt_id)
710 test "$result" = '{"valid":true}'
711 TEST_END
712
713 TEST "Judging hasn't started with player unsubmitted"
714 result=$(echo $(empathy_ambiguities alice))
715 test "$result" = "null"
716 TEST_END
717
718 # Usage: empathy_end_answers <player_name> <prompt_id>
719 empathy_end_answers()
720 {
721     empathy_post $1 end-answers/$2
722 }
723
724 TEST "Minority of players vote to end answering"
725 empathy_end_answers alice $prompt_id
726 empathy_end_answers bob $prompt_id
727 test "$?" = "0"
728 TEST_END
729
730 TEST "Judging still hasn't started"
731 result=$(echo $(empathy_ambiguities alice))
732 test "$result" = "null"
733 TEST_END
734
735 TEST "Majority of players vote to end answering"
736 empathy_end_answers charlie $prompt_id
737 test "$?" = "0"
738 TEST_END
739
740 TEST "Judging has now started"
741 result=$(echo $(empathy_ambiguities alice))
742 test "$result" != "null"
743 TEST_END
744
745 TEST "Submit word groups from majority"
746 empathy_judged alice $prompt_id '[]' >/dev/null
747 result=$(empathy_judged bob $prompt_id '[]')
748 test "$result" = '{"valid":true}'
749 TEST_END
750
751 TEST "Scoring hasn't started with player unsubmitted"
752 result=$(echo $(empathy_scores alice))
753 test "$result" = "null"
754 TEST_END
755
756 # Usage: empathy_end_judging <player_name> <prompt_id>
757 empathy_end_judging()
758 {
759     empathy_post $1 end-judging/$2
760 }
761
762 TEST "Minority of players vote to end judging"
763 empathy_end_judging alice $prompt_id
764 test "$?" = "0"
765 TEST_END
766
767 TEST "Scoring still hasn't started"
768 result=$(echo $(empathy_scores alice))
769 test "$result" = "null"
770 TEST_END
771
772 TEST "Majority of players vote to end judging"
773 empathy_end_judging bob $prompt_id
774 test "$?" = "0"
775 TEST_END
776
777 TEST "Scoring has now started"
778 result=$(echo $(empathy_scores alice))
779 test "$result" != "null"
780 TEST_END
781
782 TEST_SUBSECTION "New game (no voting needed when all answered players judge)"
783
784 TEST "Start 4-player game, 3 submissions"
785 empathy_reset
786 prompt_id=$(empathy_submit_prompt alice 4 "1 truth or dare" | jq .id)
787 empathy_start alice $prompt_id
788 empathy_answer alice   $prompt_id '"truth"' >/dev/null
789 empathy_answer bob     $prompt_id '"truth"' >/dev/null
790 empathy_answer charlie $prompt_id '"dare"' >/dev/null
791 empathy_end_answers alice $prompt_id
792 empathy_end_answers bob $prompt_id
793 empathy_end_answers charlie $prompt_id
794 test "$?" = "0"
795 TEST_END
796
797 TEST "Submit word groups from 2 players"
798 empathy_judged alice $prompt_id '[]' >/dev/null
799 result=$(empathy_judged bob $prompt_id '[]')
800 test "$result" = '{"valid":true}'
801 TEST_END
802
803 TEST "Scoring hasn't started with player unsubmitted"
804 result=$(echo $(empathy_scores alice))
805 test "$result" = "null"
806 TEST_END
807
808 TEST "Submit word groups from last answering player"
809 result=$(empathy_judged charlie $prompt_id '[]')
810 test "$result" = '{"valid":true}'
811 TEST_END
812
813 TEST "Scoring has now started"
814 result=$(echo $(empathy_scores alice))
815 test "$result" != "null"
816 TEST_END
817
818 pkill -P $alice_pid
819 pkill -P $bob_pid
820 pkill -P $charlie_pid
821 pkill -P $dale_pid
822
823 TEST_REPORT