Skip to content

Commit

Permalink
[MM-61514] Fix errcheck issues in server/channels/app/web_broadcast_h…
Browse files Browse the repository at this point in the history
…ooks_test.go (mattermost#29213)

Co-authored-by: Ben Schumacher <[email protected]>
Co-authored-by: Caleb Roseland <[email protected]>
  • Loading branch information
3 people authored Dec 17, 2024
1 parent bac251f commit 0e4e7ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
1 change: 0 additions & 1 deletion server/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ issues:
channels/app/team.go|\
channels/app/team_test.go|\
channels/app/upload.go|\
channels/app/web_broadcast_hooks_test.go|\
channels/app/webhook_test.go|\
channels/jobs/batch_worker_test.go|\
channels/jobs/helper_test.go|\
Expand Down
37 changes: 25 additions & 12 deletions server/channels/app/web_broadcast_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ func TestAddMentionsHook_Process(t *testing.T) {

require.Nil(t, msg.Event().GetData()["mentions"])

hook.Process(msg, webConn, map[string]any{
err := hook.Process(msg, webConn, map[string]any{
"mentions": model.StringArray{userID},
})
require.NoError(t, err)

assert.Equal(t, `["`+userID+`"]`, msg.Event().GetData()["mentions"])
assert.Nil(t, msg.Event().GetData()["followers"])
Expand All @@ -40,9 +41,10 @@ func TestAddMentionsHook_Process(t *testing.T) {

require.Nil(t, msg.Event().GetData()["mentions"])

hook.Process(msg, webConn, map[string]any{
err := hook.Process(msg, webConn, map[string]any{
"mentions": model.StringArray{otherUserID},
})
require.NoError(t, err)

assert.Nil(t, msg.Event().GetData()["mentions"])
})
Expand All @@ -63,9 +65,10 @@ func TestAddFollowersHook_Process(t *testing.T) {

require.Nil(t, msg.Event().GetData()["followers"])

hook.Process(msg, webConn, map[string]any{
err := hook.Process(msg, webConn, map[string]any{
"followers": model.StringArray{userID},
})
require.NoError(t, err)

assert.Equal(t, `["`+userID+`"]`, msg.Event().GetData()["followers"])
})
Expand All @@ -75,9 +78,10 @@ func TestAddFollowersHook_Process(t *testing.T) {

require.Nil(t, msg.Event().GetData()["followers"])

hook.Process(msg, webConn, map[string]any{
err := hook.Process(msg, webConn, map[string]any{
"followers": model.StringArray{otherUserID},
})
require.NoError(t, err)

assert.Nil(t, msg.Event().GetData()["followers"])
})
Expand All @@ -97,47 +101,51 @@ func TestPostedAckHook_Process(t *testing.T) {
t.Run("should ack if user is in the list of users to notify", func(t *testing.T) {
msg := platform.MakeHookedWebSocketEvent(model.NewWebSocketEvent(model.WebsocketEventPosted, "", "", "", nil, ""))

hook.Process(msg, webConn, map[string]any{
err := hook.Process(msg, webConn, map[string]any{
"posted_user_id": model.NewId(),
"channel_type": model.ChannelTypeOpen,
"users": []string{userID},
})
require.NoError(t, err)

assert.True(t, msg.Event().GetData()["should_ack"].(bool))
})

t.Run("should not ack if user is not in the list of users to notify", func(t *testing.T) {
msg := platform.MakeHookedWebSocketEvent(model.NewWebSocketEvent(model.WebsocketEventPosted, "", "", "", nil, ""))

hook.Process(msg, webConn, map[string]any{
err := hook.Process(msg, webConn, map[string]any{
"posted_user_id": model.NewId(),
"channel_type": model.ChannelTypeOpen,
"users": []string{},
})
require.NoError(t, err)

assert.Nil(t, msg.Event().GetData()["should_ack"])
})

t.Run("should not ack if you are the user who posted", func(t *testing.T) {
msg := platform.MakeHookedWebSocketEvent(model.NewWebSocketEvent(model.WebsocketEventPosted, "", "", "", nil, ""))

hook.Process(msg, webConn, map[string]any{
err := hook.Process(msg, webConn, map[string]any{
"posted_user_id": userID,
"channel_type": model.ChannelTypeOpen,
"users": []string{userID},
})
require.NoError(t, err)

assert.Nil(t, msg.Event().GetData()["should_ack"])
})

t.Run("should ack if the channel is a DM", func(t *testing.T) {
msg := platform.MakeHookedWebSocketEvent(model.NewWebSocketEvent(model.WebsocketEventPosted, "", "", "", nil, ""))

hook.Process(msg, webConn, map[string]any{
err := hook.Process(msg, webConn, map[string]any{
"posted_user_id": model.NewId(),
"channel_type": model.ChannelTypeDirect,
"users": []string{},
})
require.NoError(t, err)

assert.True(t, msg.Event().GetData()["should_ack"].(bool))
})
Expand All @@ -151,11 +159,12 @@ func TestPostedAckHook_Process(t *testing.T) {
noAckWebConn.Active.Store(true)
msg := platform.MakeHookedWebSocketEvent(model.NewWebSocketEvent(model.WebsocketEventPosted, "", "", "", nil, ""))

hook.Process(msg, noAckWebConn, map[string]any{
err := hook.Process(msg, noAckWebConn, map[string]any{
"posted_user_id": model.NewId(),
"channel_type": model.ChannelTypeDirect,
"users": []string{},
})
require.NoError(t, err)

assert.Nil(t, msg.Event().GetData()["should_ack"])
})
Expand All @@ -169,11 +178,12 @@ func TestPostedAckHook_Process(t *testing.T) {
inactiveWebConn.Active.Store(true)
msg := platform.MakeHookedWebSocketEvent(model.NewWebSocketEvent(model.WebsocketEventPosted, "", "", "", nil, ""))

hook.Process(msg, inactiveWebConn, map[string]any{
err := hook.Process(msg, inactiveWebConn, map[string]any{
"posted_user_id": model.NewId(),
"channel_type": model.ChannelTypeDirect,
"users": []string{},
})
require.NoError(t, err)

assert.Nil(t, msg.Event().GetData()["should_ack"])
})
Expand All @@ -196,12 +206,15 @@ func TestAddMentionsAndAddFollowersHooks(t *testing.T) {
require.Nil(t, originalData["mentions"])
require.Nil(t, originalData["followers"])

addMentionsHook.Process(msg, webConn, map[string]any{
err := addMentionsHook.Process(msg, webConn, map[string]any{
"mentions": model.StringArray{userID},
})
addFollowersHook.Process(msg, webConn, map[string]any{
require.NoError(t, err)

err = addFollowersHook.Process(msg, webConn, map[string]any{
"followers": model.StringArray{userID},
})
require.NoError(t, err)

t.Run("should be able to add both mentions and followers to a single event", func(t *testing.T) {
assert.Equal(t, `["`+userID+`"]`, msg.Event().GetData()["followers"])
Expand Down

0 comments on commit 0e4e7ca

Please sign in to comment.