spec/lib/xcal/parktronic/routes/metrics_routes_spec.rb in xcal-parktronic-0.0.1 vs spec/lib/xcal/parktronic/routes/metrics_routes_spec.rb in xcal-parktronic-1.0.0

- old
+ new

@@ -1,49 +1,92 @@ -#require 'spec_helper' -# -#describe Xcal::Parktronic::ApiClient do -# -# let(:api_http_client){ Xcal::Parktronic::ApiClient.new(endpoint: 'http://api.mock', access_token: 'fake_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 -# response = api_invalid_client.get_paged_alarms(page: 1, per_page: 10) -# -# expect(response.code).to eql('403') -# expect{ JSON.load(response.body) }.not_to raise_error -# end -# -# it 'should respond with the correct set of alarms' do -# response = api_http_client.get_paged_alarms(page: 1, per_page: 10) -# -# expect(response.code).to eql('200') -# expect{ JSON.load(response.body) }.not_to raise_error -# 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 -# response = api_http_client.post_alarm({ :alarm => alarm, :events => [event] }) -# -# expect(response.code).to eql('201') -# expect{ JSON.load(response.body) }.not_to raise_error -# end -# end -# -# -# end -#end +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 'metrics route' do + + it 'should not be allowed without access_token' do + expect{ api_invalid_client.get_paged_metrics(page: 1, per_page: 10) }.not_to raise_error + expect{ api_invalid_client.get_metric(1) }.not_to raise_error + expect{ api_invalid_client.post_metric({}) }.not_to raise_error + end + + context 'getting' do + it 'should respond with the correct set of metrics' do + metrics = nil + expect{ metrics = api_http_client.get_paged_metrics(page: 1, per_page: 10) }.not_to raise_error + expect(metrics.first.id.to_s).to eql('7') + expect(metrics.first.name).to eql('Metric 1') + + expect(metrics.last.id.to_s).to eql('16') + expect(metrics.last.name).to eql('Metric 10') + end + + it 'should respond with single metric' do + metric = nil + expect{ metric = api_http_client.get_metric(2) }.not_to raise_error + + expect(metric.id.to_s).to eql('7') + end + end + + context 'posting' do + let(:metric) do + { :name => 'metric name', :originating_system => 'Source System', :impact_level => 'low', :tag_list => %w(taga tagb) } + end + let(:metric_value) do + { + value: 22, + created_at: '2013-07-24T13:21:16Z', + custom_timestamp: nil, + } + end + let(:device_error) do + { + value: 5, + created_at: '2013-07-24T13:21:16Z', + custom_timestamp: nil, + value_groups: [ + { + group_type: 'Code', + group_value: 33 + }, + { + group_type: 'software_stack', + group_value: 'stack' + } + ] + } + end + + it 'should post metrics successfully' do + send_data = { :metric => metric, :metric_values => [metric_value], :device_error => device_error } + expect{ api_http_client.post_metric(send_data) }.not_to raise_error + expect{ api_invalid_client.post_metric(send_data) }.not_to raise_error + end + end + + context 'metric metric_values' do + it 'should give an appropriate list of alarms' do + metric = api_http_client.get_metric(2) + + expect{metric.get_metric_values.first.value}.not_to raise_error + expect(metric.get_metric_values.first.value).to eql('5.339') + expect(metric.get_metric_values.last.value).to eql('4.880') + end + end + + context 'metric device_errors' do + it 'should give an appropriate list of alarms' do + metric = api_http_client.get_metric(2) + + expect{metric.get_device_errors.first.value}.not_to raise_error + expect(metric.get_device_errors.first.value).to eql(53) + expect(metric.get_device_errors.last.value).to eql(32) + end + end + + end +end \ No newline at end of file