@@ -288,4 +288,37 @@ 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 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 (
304+ { 'pinned' => true , 'cid' => @channel . cid } ,
305+ nil ,
306+ { 'user_id' => @random_users [ 0 ] [ :id ] }
307+ )
308+ expect ( response [ 'channels' ] . length ) . to eq 1
309+ expect ( response [ 'channels' ] [ 0 ] [ 'channel' ] [ 'cid' ] ) . to eq @channel . cid
310+
311+ # Unpin the channel
312+ response = @channel . unpin ( @random_users [ 0 ] [ :id ] )
313+ expect ( response [ 'channel_member' ] ) . not_to have_key ( 'pinned_at' )
314+
315+ # Query for unpinned channel
316+ response = @client . query_channels (
317+ { 'pinned' => false , 'cid' => @channel . cid } ,
318+ nil ,
319+ { 'user_id' => @random_users [ 0 ] [ :id ] }
320+ )
321+ expect ( response [ 'channels' ] . length ) . to eq 1
322+ expect ( response [ 'channels' ] [ 0 ] [ 'channel' ] [ 'cid' ] ) . to eq @channel . cid
323+ end
291324end
0 commit comments