spec/lib/flapjack/api_spec.rb in flapjack-0.6.39 vs spec/lib/flapjack/api_spec.rb in flapjack-0.6.40

- old
+ new

@@ -8,21 +8,22 @@ end let(:entity) { mock(Flapjack::Data::Entity) } let(:entity_check) { mock(Flapjack::Data::EntityCheck) } - let(:entity_name) { 'example.com'} + let(:entity_name) { 'www.example.net'} let(:entity_name_esc) { URI.escape(entity_name) } let(:check) { 'ping' } let(:entity_presenter) { mock(Flapjack::API::EntityPresenter) } let(:entity_check_presenter) { mock(Flapjack::API::EntityCheckPresenter) } let(:redis) { mock(::Redis) } before(:each) do - Flapjack::API.class_variable_set('@@redis', redis) + Flapjack::RedisPool.should_receive(:new).and_return(redis) + Flapjack::API.bootstrap(:config => {}) end it "returns a list of checks for an entity" do check_list = ['ping'] entity.should_receive(:check_list).and_return(check_list) @@ -47,10 +48,21 @@ get "/scheduled_maintenances/#{entity_name_esc}" last_response.should be_ok last_response.body.should == result_json end + it "creates an acknowledgement for an entity check" do + Flapjack::Data::Entity.should_receive(:find_by_name). + with(entity_name, :redis => redis).and_return(entity) + Flapjack::Data::EntityCheck.should_receive(:for_entity). + with(entity, check, :redis => redis).and_return(entity_check) + entity_check.should_receive(:create_acknowledgement).with('summary' => nil, 'duration' => (4 * 60 * 60)) + + post "/acknowledgements/#{entity_name_esc}/#{check}" + last_response.status.should == 204 + end + it "returns a list of scheduled maintenance periods within a time window for an entity" it "returns a list of scheduled maintenance periods for a check on an entity" do result = mock('result') result_json = %q{"result"} @@ -165,10 +177,23 @@ get "/downtime/#{entity_name_esc}/#{check}" last_response.should be_ok last_response.body.should == result_json end + it "creates a test notification event for check on an entity" do + + Flapjack::Data::Entity.should_receive(:find_by_name). + with(entity_name, :redis => redis).and_return(entity) + entity.should_receive(:name).and_return(entity_name) + Flapjack::Data::EntityCheck.should_receive(:for_entity). + with(entity, 'foo', :redis => redis).and_return(entity_check) + entity_check.should_receive(:test_notifications) + + post "/test_notifications/#{entity_name_esc}/foo" + last_response.status.should == 204 + end + it "creates entities from a submitted list" do entities = {'entities' => [ {"id" => "10001", "name" => "clientx-app-01", @@ -264,6 +289,6 @@ post "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'} last_response.status.should == 200 end -end \ No newline at end of file +end