Skip to content

Commit

Permalink
Merge branch 'atipugin:master' into verify-data-from-web-app
Browse files Browse the repository at this point in the history
  • Loading branch information
valovm authored Nov 8, 2024
2 parents 81367dc + 64a092a commit d15b98d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/telegram/bot/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def fetch_updates
yield handle_update(update)
end
rescue Faraday::TimeoutError, Faraday::ConnectionFailed
retry
retry if @running
end

def handle_update(update)
Expand Down
45 changes: 36 additions & 9 deletions spec/lib/telegram/bot/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,48 @@
end

describe '#stop' do
before do
allow(client.api).to receive(:getUpdates).and_return [Telegram::Bot::Types::Update.new(update_id: 111_111)]
context 'when bot receives messages' do
before do
allow(client.api).to receive(:getUpdates).and_return [Telegram::Bot::Types::Update.new(update_id: 111_111)]

current_times = 0
current_times = 0

client.listen do |_message|
current_times += 1
client.stop if current_times == expected_times
client.listen do |_message|
current_times += 1
client.stop if current_times == expected_times
end
end

let(:expected_times) { 3 }

specify do
expect(client.api).to have_received(:getUpdates).exactly(expected_times).times
end
end

let(:expected_times) { 3 }
context 'when bot does not receive any messages' do
before do
current_times = 0

allow(client.api).to receive(:getUpdates) do
if current_times >= expected_times - 1
client.stop
raise Faraday::TimeoutError
end

specify do
expect(client.api).to have_received(:getUpdates).exactly(expected_times).times
[Telegram::Bot::Types::Update.new(update_id: 111_111)]
end

client.listen do |_message|
current_times += 1
end
end

let(:expected_times) { 3 }

specify do
expect(client.api).to have_received(:getUpdates).exactly(expected_times).times
end
end
end

Expand Down

0 comments on commit d15b98d

Please sign in to comment.