Skip to content

Commit f617546

Browse files
committed
test Trello response with payload
1 parent d89b87b commit f617546

1 file changed

Lines changed: 32 additions & 9 deletions

File tree

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
1+
require 'json'
12
require 'webmock/rspec'
23

34
require_relative './plugin_stub.rb'
45
require_relative '../bin/check-trello-incidents.rb'
56

67
describe CheckTrelloIncidents do
7-
it 'should run' do
8-
stub_request(
8+
before(:each) do
9+
@api = stub_request(
910
:get,
1011
'https://api.trello.com//1/lists/abcde/cards/?key=12345&token=12345'
11-
).to_return(body: '[]', status: 200)
12+
)
13+
14+
@check = CheckTrelloIncidents.new
15+
@check.config[:api_key] = '12345'
16+
@check.config[:api_token] = '12345'
17+
@check.config[:list] = 'abcde'
18+
19+
allow(@check).to receive(:output)
20+
end
21+
22+
it 'should run' do
23+
@api.to_return(body: '[]', status: 200)
24+
25+
expect { @check.run }.to raise_error do |error|
26+
expect(error).to be_a SystemExit
27+
expect(error.status).to eq 0
28+
end
29+
expect(@check).to have_received(:output).with('No new incidents')
30+
expect(@api).to have_been_requested
31+
end
1232

13-
check = CheckTrelloIncidents.new
14-
check.config[:api_key] = '12345'
15-
check.config[:api_token] = '12345'
16-
check.config[:list] = 'abcde'
33+
it 'should be critical if trello cards' do
34+
cards = [{ id: '1a2b3c', name: 'foo' }, { id: '1x2y3z', name: 'bar' }]
35+
@api.to_return(body: JSON.generate(cards), status: 200)
1736

18-
expect(check).to receive(:output).with('No new incidents')
19-
expect(-> { check.run }).to raise_error SystemExit
37+
expect { @check.run }.to raise_error do |error|
38+
expect(error).to be_a SystemExit
39+
expect(error.status).to eq 2
40+
end
41+
expect(@check).to have_received(:output).with('foo; bar')
42+
expect(@api).to have_been_requested
2043
end
2144
end

0 commit comments

Comments
 (0)