Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added test for archiving / unarchiving
Browse files Browse the repository at this point in the history
totalimmersion committed Dec 9, 2024

Verified

This commit was signed with the committer’s verified signature.
not-an-aardvark Teddy Katz
1 parent a4346c6 commit 2c90480
Showing 2 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/stream-chat/channel.rb
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@ class Channel
sig { returns(String) }
attr_reader :channel_type

sig { returns(String) }
attr_reader :cid

sig { returns(StringKeyHash) }
attr_reader :custom_data

39 changes: 36 additions & 3 deletions spec/channel_spec.rb
Original file line number Diff line number Diff line change
@@ -289,7 +289,7 @@ def loop_times(times)
expect(response['members'].length).to eq 2
end

it 'can pin and unpin channel' do
it 'can pin and unpin a channel' do
@channel.add_members([@random_users[0][:id]])
@channel.add_members([@random_users[1][:id]])

@@ -303,7 +303,7 @@ def loop_times(times)
response = @client.query_channels(
{ 'pinned' => true, 'cid' => @channel.cid },
nil,
{ 'user_id' => @random_users[0][:id] }
user_id: @random_users[0][:id]
)
expect(response['channels'].length).to eq 1
expect(response['channels'][0]['channel']['cid']).to eq @channel.cid
@@ -316,7 +316,40 @@ def loop_times(times)
response = @client.query_channels(
{ 'pinned' => false, 'cid' => @channel.cid },
nil,
{ 'user_id' => @random_users[0][:id] }
user_id: @random_users[0][:id]
)
expect(response['channels'].length).to eq 1
expect(response['channels'][0]['channel']['cid']).to eq @channel.cid
end

it 'can archive and unarchive a channel' do
@channel.add_members([@random_users[0][:id]])
@channel.add_members([@random_users[1][:id]])

# Pin the channel
now = Time.now
response = @channel.archive(@random_users[0][:id])
expect(response['channel_member']['archived_at']).not_to be_nil
expect(Time.parse(response['channel_member']['archived_at']).to_i).to be >= now.to_i

# Query for archived channel
response = @client.query_channels(
{ 'archived' => true, 'cid' => @channel.cid },
nil,
user_id: @random_users[0][:id]
)
expect(response['channels'].length).to eq 1
expect(response['channels'][0]['channel']['cid']).to eq @channel.cid

# Unarchive the channel
response = @channel.unarchive(@random_users[0][:id])
expect(response['channel_member']).not_to have_key('archived_at')

# Query for unarchived channel
response = @client.query_channels(
{ 'archived' => false, 'cid' => @channel.cid },
nil,
user_id: @random_users[0][:id]
)
expect(response['channels'].length).to eq 1
expect(response['channels'][0]['channel']['cid']).to eq @channel.cid

0 comments on commit 2c90480

Please sign in to comment.