require 'spec_helper' describe Xcal::Parktronic::ApiClient do let(:api_http_client){ Xcal::Parktronic::ApiClient.new(endpoint: 'http://api.mock', access_token: 'access_token') } let(:api_invalid_client){ Xcal::Parktronic::ApiClient.new(endpoint: 'http://api.mock') } context 'alarms route' do it 'should not be allowed without access_token' do expect{ api_invalid_client.get_paged_alarms(page: 1, per_page: 10) }.not_to raise_error expect{ api_invalid_client.get_alarm(1) }.not_to raise_error expect{ api_invalid_client.post_alarm({}) }.not_to raise_error end context 'getting' do it 'should respond with the correct set of alarms' do alarms = nil expect{ alarms = api_http_client.get_paged_alarms(page: 1, per_page: 10) }.not_to raise_error expect(alarms.first.id.to_s).to eql('1') expect(alarms.first.name).to eql('ALARM NAME 1') expect(alarms.last.id.to_s).to eql('10') expect(alarms.last.name).to eql('ALARM NAME 10') end it 'should respond with single alarm' do alarm = nil expect{ alarm = api_http_client.get_alarm(2) }.not_to raise_error expect(alarm.id.to_s).to eql('2') end end context 'posting' do let(:alarm) do { :name => 'alarm name', :originating_system => 'Source System', :impact_level => 'low', :tag_list => %w(taga tagb) } end let(:event) do { :subject => 'EventSubj', :description => 'EventDesc', :host_impacted => 'host', :initiated_at => '2013-11-22T01:00:24Z', :service_impacted => 'EventSvc', :incident_status => 'CRITICAL' } end it 'should post alarms successfully' do expect{ api_http_client.post_alarm({ :alarm => alarm, :events => [event] }) }.not_to raise_error expect{ api_invalid_client.post_alarm({ :alarm => alarm, :events => [event] }) }.not_to raise_error end end context 'alarm events' do it 'should give an appropriate list of alarms' do alarm = api_http_client.get_alarm(2) expect{alarm.get_events.first.id}.not_to raise_error expect(alarm.get_events.first.id).to eql(73) expect(alarm.get_events.last.id).to eql(370) end end describe '#get_event_tags' do it 'should get tags of alarm' do expect{ api_http_client.get_alarm_tags(1) }.not_to raise_error end end end end