Skip to content

Commit

Permalink
feat: added test for archiving / unarchiving
Browse files Browse the repository at this point in the history
  • Loading branch information
totalimmersion committed Dec 9, 2024
1 parent a4346c6 commit 8ed2b20
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/stream-chat/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
42 changes: 35 additions & 7 deletions spec/channel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]])

Expand All @@ -300,11 +300,7 @@ def loop_times(times)
expect(Time.parse(response['channel_member']['pinned_at']).to_i).to be >= now.to_i

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

Expand All @@ -316,7 +312,39 @@ 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
Expand Down

0 comments on commit 8ed2b20

Please sign in to comment.