Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,12 +948,17 @@ func ExampleChannel_Query() {
// amount of messages sent when the CountMessages feature is enabled (default behaviour).
func TestChannel_MessageCount_DefaultEnabled(t *testing.T) {
c := initClient(t)
ch := initChannel(t, c)
ctx := context.Background()

_, err := c.UpdateChannelType(ctx, "team", map[string]interface{}{"count_messages": true})
require.NoError(t, err)

time.Sleep(500 * time.Millisecond)
ch := initChannel(t, c)

// Send a single message to the channel
user := randomUser(t, c)
_, err := ch.SendMessage(ctx, &Message{Text: "hello world"}, user.ID)
_, err = ch.SendMessage(ctx, &Message{Text: "hello world"}, user.ID)
require.NoError(t, err, "send message")

// Refresh the channel state to get the updated message_count field
Expand All @@ -962,6 +967,10 @@ func TestChannel_MessageCount_DefaultEnabled(t *testing.T) {
// message_count should be present and equal to 1
require.NotNil(t, ch.MessageCount, "message_count should not be nil when CountMessages is enabled")
assert.Equal(t, 1, *ch.MessageCount)

// Clean up: reset the CountMessages feature to false
_, err = c.UpdateChannelType(ctx, "team", map[string]interface{}{"count_messages": false})
require.NoError(t, err)
}

// TestChannel_MessageCount_Disabled verifies that message_count is omitted when the
Expand Down