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 describe '#get_alarm_actions' do it 'should return alarm_actions for alarm' do expect{ api_http_client.get_alarm(2).get_alarm_actions}.not_to raise_error expect{ api_http_client.get_alarm(22).get_alarm_actions}.not_to raise_error end end describe '#get_alarm_actions' do it 'should return alarm_action for alarm' do expect{ api_http_client.get_alarm(2).get_alarm_action(2)}.not_to raise_error alarm_action = api_http_client.get_alarm(2).get_alarm_action(2) expect(alarm_action.action_id).to eql(1) expect(alarm_action.rule.attribute).to eql('aggregated_count') expect(alarm_action.rule.operator).to eql('NOT IN') expect(alarm_action.rule.value).to eql('OPEN') end end describe '#post_alarm_action' do it 'should create alarm_action for alarm' do alarm_action = api_http_client.get_alarm(2).get_alarm_action(2) alarm_action_params = {alarm_id: 2, action_id: 1,rule: {:attribute=>"aggregated_count", :operator=>"NOT IN", :value=>"OPEN"}} expect{ api_http_client.get_alarm(2).post_alarm_action(alarm_action_params)}.not_to raise_error expect{ alarm_action.post_alarm_action(alarm_action_params)}.not_to raise_error end end describe '#update_alarm_action' do it 'should update alarm_action' do alarm_action = api_http_client.get_alarm(2).get_alarm_action(2) alarm_action_params = {alarm_id: 2, action_id: 1,rule: {:attribute=>"aggregated_count", :operator=>"IN", :value=>"NEW"}} expect{ api_http_client.get_alarm(2).update_alarm_action(1, alarm_action_params) }.not_to raise_error expect{ alarm_action.update_alarm_action(1, alarm_action_params) }.not_to raise_error end end describe '#set_position' do it 'should update position for alarm_action' do alarm_action = api_http_client.get_alarm(2).get_alarm_action(2) expect{ api_http_client.get_alarm(2).set_position(1, 10) }.not_to raise_error expect{ alarm_action.set_position(1, 10) }.not_to raise_error end end end end