Skip to content

Commit a013ff0

Browse files
feat: added test for archiving / unarchiving
1 parent a4346c6 commit a013ff0

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

spec/channel_spec.rb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def loop_times(times)
289289
expect(response['members'].length).to eq 2
290290
end
291291

292-
it 'can pin and unpin channel' do
292+
it 'can pin and unpin a channel' do
293293
@channel.add_members([@random_users[0][:id]])
294294
@channel.add_members([@random_users[1][:id]])
295295

@@ -321,4 +321,37 @@ def loop_times(times)
321321
expect(response['channels'].length).to eq 1
322322
expect(response['channels'][0]['channel']['cid']).to eq @channel.cid
323323
end
324+
325+
it 'can archive and unarchive a channel' do
326+
@channel.add_members([@random_users[0][:id]])
327+
@channel.add_members([@random_users[1][:id]])
328+
329+
# Pin the channel
330+
now = Time.now
331+
response = @channel.archive(@random_users[0][:id])
332+
expect(response['channel_member']['archived_at']).not_to be_nil
333+
expect(Time.parse(response['channel_member']['archived_at']).to_i).to be >= now.to_i
334+
335+
# Query for pinned channel
336+
response = @client.query_channels(
337+
{ 'archived' => true, 'cid' => @channel.cid },
338+
nil,
339+
{ 'user_id' => @random_users[0][:id] }
340+
)
341+
expect(response['channels'].length).to eq 1
342+
expect(response['channels'][0]['channel']['cid']).to eq @channel.cid
343+
344+
# Unpin the channel
345+
response = @channel.unarchive(@random_users[0][:id])
346+
expect(response['channel_member']).not_to have_key('archived_at')
347+
348+
# Query for unpinned channel
349+
response = @client.query_channels(
350+
{ 'archived' => false, 'cid' => @channel.cid },
351+
nil,
352+
{ 'user_id' => @random_users[0][:id] }
353+
)
354+
expect(response['channels'].length).to eq 1
355+
expect(response['channels'][0]['channel']['cid']).to eq @channel.cid
356+
end
324357
end

0 commit comments

Comments
 (0)