Skip to content

Commit

Permalink
added tests for restricted message visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
totalimmersion committed Jan 29, 2025
1 parent 3ed9d73 commit 5c31e35
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func TestChannel_SendRestrictedVisibilityMessage(t *testing.T) {

resp, err := ch.SendMessage(ctx, msg, adminUser.ID)
require.NoError(t, err, "send message")
assert.Equal(t, resp.Message.RestrictedVisibility, msg.RestrictedVisibility)
assert.Equal(t, msg.RestrictedVisibility, resp.Message.RestrictedVisibility)
}

func TestChannel_Truncate(t *testing.T) {
Expand Down
54 changes: 54 additions & 0 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -146,3 +147,56 @@ func TestClient_SendMessage_KeepChannelHidden(t *testing.T) {
require.NoError(t, err)
require.Empty(t, result.Channels)
}

func TestClient_UpdateRestrictedVisibilityMessage(t *testing.T) {
c := initClient(t)
ch := initChannel(t, c)
ctx := context.Background()
adminUser := randomUserWithRole(t, c, "admin")
user1 := randomUser(t, c)
user2 := randomUser(t, c)
msg := &Message{
Text: "test message",
RestrictedVisibility: []string{
user1.ID,
},
}

resp, err := ch.SendMessage(ctx, msg, adminUser.ID)
require.NoError(t, err, "send message")

msg = resp.Message
msg.RestrictedVisibility = []string{user2.ID}
resp, err = c.UpdateMessage(ctx, msg, msg.ID)
require.NoError(t, err, "send message")
assert.Equal(t, []string{user2.ID}, resp.Message.RestrictedVisibility)
}

func TestClient_PartialUpdateRestrictedVisibilityMessage(t *testing.T) {
c := initClient(t)
ch := initChannel(t, c)
ctx := context.Background()
adminUser := randomUserWithRole(t, c, "admin")
user1 := randomUser(t, c)
user2 := randomUser(t, c)
msg := &Message{
Text: "test message",
RestrictedVisibility: []string{
user1.ID,
},
}

_, err := ch.SendMessage(ctx, msg, adminUser.ID)
require.NoError(t, err, "send message")

resp, err := c.PartialUpdateMessage(ctx, msg.ID, &MessagePartialUpdateRequest{
UserID: adminUser.ID,
PartialUpdate: PartialUpdate{
Set: map[string]interface{}{
"restricted_visibility": []string{user2.ID},
},
},
})
require.NoError(t, err, "send message")
assert.Equal(t, []string{user2.ID}, resp.Message.RestrictedVisibility)
}

0 comments on commit 5c31e35

Please sign in to comment.