Skip to content

Commit cc59fa6

Browse files
committed
Add keyword args, update spec, and bug
Changing get_paged_chanels to take keyword args. Updating the loads_slack_channels spec for testing pagination to include the pagination cursor. Including types when calling get_paged_channels (bug fix)
1 parent 19d21f4 commit cc59fa6

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

app/services/slack/loads_slack_channels.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def call(types:)
1414
ClientWrapper.client.conversations_list(types: approved_types(types), limit: 1000, exclude_archived: true)
1515
end
1616

17-
get_paged_channels(response&.response_metadata&.next_cursor, response&.channels || [])
17+
get_paged_channels(cursor: response&.response_metadata&.next_cursor, channels: response&.channels || [], types: types)
1818
end
1919

2020
private
@@ -23,11 +23,11 @@ def approved_types(types)
2323
types.split(",").select { |t| SLACK_CHANNEL_TYPES.include?(t) }.join(",")
2424
end
2525

26-
def get_paged_channels(cursor, channels)
26+
def get_paged_channels(cursor:, channels:, types:)
2727
while cursor.present?
2828
response = ClientWrapper.client.conversations_list(cursor: cursor, types: approved_types(types), limit: 1000, exclude_archived: true)
2929
channels.append(response.channels)
30-
cursor = response.response_metadata.next_cursor
30+
cursor = response.response_metadata&.next_cursor
3131
end
3232

3333
channels.flatten

spec/lib/slack/loads_slack_channels_spec.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,19 @@
3737
end
3838

3939
it "loads all active channels when requiring pagination" do
40-
archived_slack_public_channel = Slack::Messages::Message.new(
41-
id: "PUBLIC_CHANNEL_ID_2",
42-
is_channel: true,
43-
is_archived: true
44-
)
4540
slack_public_channels = (0..1010).map do |ch|
4641
Slack::Messages::Message.new(
4742
id: "PUBLIC_CHANNEL_ID_#{ch}",
4843
is_channel: true
4944
)
5045
end
51-
all_channels = slack_public_channels << archived_slack_public_channel
5246

47+
response_metadata = Slack::Messages::Message.new(next_cursor: "cursor")
5348
expect(@slack_client).to receive(:conversations_list).with(types: "public_channel", limit: 1000, exclude_archived: true) {
54-
Slack::Messages::Message.new(ok: true, channels: all_channels)
49+
Slack::Messages::Message.new(ok: true, response_metadata: response_metadata, channels: slack_public_channels[0..999])
50+
}
51+
expect(@slack_client).to receive(:conversations_list).with(types: "public_channel", limit: 1000, exclude_archived: true, cursor: response_metadata.next_cursor) {
52+
Slack::Messages::Message.new(ok: true, channels: slack_public_channels[1000..])
5553
}
5654

5755
channels = subject.call(types: "public_channel")

0 commit comments

Comments
 (0)