forked from Team254/cheesy-arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audience_display_test.go
86 lines (77 loc) · 2.52 KB
/
audience_display_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2014 Team 254. All Rights Reserved.
// Author: [email protected] (Patrick Fairbank)
package main
import (
"github.com/gorilla/websocket"
"github.com/stretchr/testify/assert"
"sync"
"testing"
)
func TestAudienceDisplay(t *testing.T) {
clearDb()
defer clearDb()
var err error
db, err = OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
eventSettings, _ = db.GetEventSettings()
mainArena.Setup()
recorder := getHttpResponse("/displays/audience")
assert.Equal(t, 200, recorder.Code)
assert.Contains(t, recorder.Body.String(), "Audience Display - Untitled Event - Cheesy Arena")
}
func TestAudienceDisplayWebsocket(t *testing.T) {
clearDb()
defer clearDb()
var err error
db, err = OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
eventSettings, _ = db.GetEventSettings()
mainArena.Setup()
server, wsUrl := startTestServer()
defer server.Close()
conn, _, err := websocket.DefaultDialer.Dial(wsUrl+"/displays/audience/websocket", nil)
assert.Nil(t, err)
defer conn.Close()
ws := &Websocket{conn, new(sync.Mutex)}
// Should get a few status updates right after connection.
readWebsocketType(t, ws, "matchTiming")
readWebsocketType(t, ws, "matchTime")
readWebsocketType(t, ws, "setAudienceDisplay")
readWebsocketType(t, ws, "setMatch")
readWebsocketType(t, ws, "realtimeScore")
readWebsocketType(t, ws, "setFinalScore")
readWebsocketType(t, ws, "allianceSelection")
// Run through a match cycle.
mainArena.matchLoadTeamsNotifier.Notify(nil)
readWebsocketType(t, ws, "setMatch")
mainArena.AllianceStations["R1"].Bypass = true
mainArena.AllianceStations["R2"].Bypass = true
mainArena.AllianceStations["R3"].Bypass = true
mainArena.AllianceStations["B1"].Bypass = true
mainArena.AllianceStations["B2"].Bypass = true
mainArena.AllianceStations["B3"].Bypass = true
mainArena.StartMatch()
mainArena.Update()
messages := readWebsocketMultiple(t, ws, 3)
screen, ok := messages["setAudienceDisplay"]
if assert.True(t, ok) {
assert.Equal(t, "match", screen)
}
sound, ok := messages["playSound"]
if assert.True(t, ok) {
assert.Equal(t, "match-start", sound)
}
_, ok = messages["matchTime"]
assert.True(t, ok)
mainArena.realtimeScoreNotifier.Notify(nil)
readWebsocketType(t, ws, "realtimeScore")
mainArena.scorePostedNotifier.Notify(nil)
readWebsocketType(t, ws, "setFinalScore")
// Test other overlays.
mainArena.allianceSelectionNotifier.Notify(nil)
readWebsocketType(t, ws, "allianceSelection")
mainArena.lowerThirdNotifier.Notify(nil)
readWebsocketType(t, ws, "lowerThird")
}