@@ -288,4 +288,67 @@ def loop_times(times)
288288 response = @channel . query_members ( filter_conditions : { notifications_muted : true } )
289289 expect ( response [ 'members' ] . length ) . to eq 2
290290 end
291+
292+ it 'can pin and unpin a channel' do
293+ @channel . add_members ( [ @random_users [ 0 ] [ :id ] ] )
294+ @channel . add_members ( [ @random_users [ 1 ] [ :id ] ] )
295+
296+ # Pin the channel
297+ now = Time . now
298+ response = @channel . pin ( @random_users [ 0 ] [ :id ] )
299+ expect ( response [ 'channel_member' ] [ 'pinned_at' ] ) . not_to be_nil
300+ expect ( Time . parse ( response [ 'channel_member' ] [ 'pinned_at' ] ) . to_i ) . to be >= now . to_i
301+
302+ # Query for pinned channel
303+ response = @client . query_channels ( { 'pinned' => true , 'cid' => @channel . cid } , sort : nil , user_id : @random_users [ 0 ] [ :id ] )
304+ expect ( response [ 'channels' ] . length ) . to eq 1
305+ expect ( response [ 'channels' ] [ 0 ] [ 'channel' ] [ 'cid' ] ) . to eq @channel . cid
306+
307+ # Unpin the channel
308+ response = @channel . unpin ( @random_users [ 0 ] [ :id ] )
309+ expect ( response [ 'channel_member' ] ) . not_to have_key ( 'pinned_at' )
310+
311+ # Query for unpinned channel
312+ response = @client . query_channels ( { 'pinned' => false , 'cid' => @channel . cid } , sort : nil , user_id : @random_users [ 0 ] [ :id ] )
313+ expect ( response [ 'channels' ] . length ) . to eq 1
314+ expect ( response [ 'channels' ] [ 0 ] [ 'channel' ] [ 'cid' ] ) . to eq @channel . cid
315+ end
316+
317+ it 'can archive and unarchive a channel' do
318+ @channel . add_members ( [ @random_users [ 0 ] [ :id ] ] )
319+ @channel . add_members ( [ @random_users [ 1 ] [ :id ] ] )
320+
321+ # Pin the channel
322+ now = Time . now
323+ response = @channel . archive ( @random_users [ 0 ] [ :id ] )
324+ expect ( response [ 'channel_member' ] [ 'archived_at' ] ) . not_to be_nil
325+ expect ( Time . parse ( response [ 'channel_member' ] [ 'archived_at' ] ) . to_i ) . to be >= now . to_i
326+
327+ # Query for archived channel
328+ response = @client . query_channels ( { 'archived' => true , 'cid' => @channel . cid } , sort : nil , user_id : @random_users [ 0 ] [ :id ] )
329+ expect ( response [ 'channels' ] . length ) . to eq 1
330+ expect ( response [ 'channels' ] [ 0 ] [ 'channel' ] [ 'cid' ] ) . to eq @channel . cid
331+
332+ # Unarchive the channel
333+ response = @channel . unarchive ( @random_users [ 0 ] [ :id ] )
334+ expect ( response [ 'channel_member' ] ) . not_to have_key ( 'archived_at' )
335+
336+ # Query for unarchived channel
337+ response = @client . query_channels ( { 'archived' => false , 'cid' => @channel . cid } , sort : nil , user_id : @random_users [ 0 ] [ :id ] )
338+ expect ( response [ 'channels' ] . length ) . to eq 1
339+ expect ( response [ 'channels' ] [ 0 ] [ 'channel' ] [ 'cid' ] ) . to eq @channel . cid
340+ end
341+
342+ it 'can update channel member partially' do
343+ @channel . add_members ( [ @random_users [ 0 ] [ :id ] ] )
344+
345+ # Test setting a field
346+ response = @channel . update_member_partial ( @random_users [ 0 ] [ :id ] , set : { 'hat' => 'blue' } )
347+ expect ( response [ 'channel_member' ] [ 'hat' ] ) . to eq 'blue'
348+
349+ # Test setting and unsetting fields
350+ response = @channel . update_member_partial ( @random_users [ 0 ] [ :id ] , set : { 'color' => 'red' } , unset : [ 'hat' ] )
351+ expect ( response [ 'channel_member' ] [ 'color' ] ) . to eq 'red'
352+ expect ( response [ 'channel_member' ] ) . not_to have_key ( 'hat' )
353+ end
291354end
0 commit comments