Skip to content

Commit

Permalink
Make broadcast payloads a string for easier testing
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelclapham committed Aug 23, 2024
1 parent 7eb1e38 commit 9f42370
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
14 changes: 5 additions & 9 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,7 @@ func Test_session_owner_can_broadcast_to_another_client(t *testing.T) {
}

// Client 1 (session owner) broadcast to other clients in session
sentPayload := ExamplePayload{
Title: "test title",
Body: "test body",
}
sentPayload := "{\"test\":\"testy\"}"
broadcastToSessionMsg := BroadcastToSessionMsg{
Type: "BroadcastToSession",
Payload: sentPayload,
Expand All @@ -457,17 +454,16 @@ func Test_session_owner_can_broadcast_to_another_client(t *testing.T) {
t.Fatalf("Error parsing BroadcastFromSessionMsg")
}

receivedPayload := broadcastFromSessionMsg.Payload.(map[string]interface{})
receivedPayload := broadcastFromSessionMsg.Payload

if receivedPayload["Body"] != sentPayload.Body {
if sentPayload != receivedPayload {
t.Logf("Received payload: %v", broadcastFromSessionMsg.Payload)
t.Logf("Sent payload: %v", sentPayload)
t.Fatalf(
"Expected payload body received to be same as one sent but sent %s is different from received %s",
sentPayload.Body,
receivedPayload["Body"],
sentPayload,
receivedPayload,
)

}

}
12 changes: 6 additions & 6 deletions msg_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ type ClientLeftSessionMsg struct {

// BroadcastToSessionMsg - Used by client to send content to all clients in session
type BroadcastToSessionMsg struct {
Type string `json:"type"`
Payload interface{} `json:"payload"`
Type string `json:"type"`
Payload string `json:"payload"`
}

// BroadcastFromSessionMsg - Used by server to send content all clients in a session
type BroadcastFromSessionMsg struct {
Type string `json:"type"`
FromSessionOwner bool `json:"fromSessionOwner"`
SenderID string `json:"senderId"`
Payload interface{} `json:"payload"`
Type string `json:"type"`
FromSessionOwner bool `json:"fromSessionOwner"`
SenderID string `json:"senderId"`
Payload string `json:"payload"`
}

// ErrorMsg - Websocket error message
Expand Down

0 comments on commit 9f42370

Please sign in to comment.