Sha256: c410476ed92f8a9d775125835cebb3e5a53f565577e66f05a2048f0f84755bb3

Contents?: true

Size: 1.73 KB

Versions: 13

Compression:

Stored size: 1.73 KB

Contents

require File.expand_path("../helper", __FILE__)

class TestService < CC::Service::TestCase
  def test_validates_events
    assert_raises(ArgumentError) do
      CC::Service.new(:foo, {}, {}, {})
    end
  end

  def test_default_path_to_ca_file
    s = CC::Service.new({}, {name: "test"})
    assert_equal(File.expand_path("../../config/cacert.pem", __FILE__), s.ca_file)
    assert File.exist?(s.ca_file)
  end

  def test_custom_path_to_ca_file
    ENV["CODECLIMATE_CA_FILE"] = "/tmp/cacert.pem"
    s = CC::Service.new({}, {name: "test"})
    assert_equal("/tmp/cacert.pem", s.ca_file)
  ensure
    ENV.delete("CODECLIMATE_CA_FILE")
  end

  def test_nothing_has_a_handler
    service = CC::Service.new({}, {name: "test"})

    result = service.receive

    assert_equal false, result[:ok]
    assert_true true, result[:ignored]
    assert_equal "No service handler found", result[:message]
  end

  def test_post_success
    stub_http("/my/test/url", [200, {}, '{"ok": true, "thing": "123"}'])

    response = service_post("/my/test/url", {token: "1234"}.to_json, {}) do |response|
      body = JSON.parse(response.body)
      { thing: body["thing"] }
    end

    assert_true response[:ok]
    assert_equal '{"token":"1234"}', response[:params]
    assert_equal "/my/test/url", response[:endpoint_url]
    assert_equal 200, response[:status]
  end

  def test_post_http_failure
    stub_http("/my/wrong/url", [404, {}, ""])

    assert_raises(CC::Service::HTTPError) do
      service_post("/my/wrong/url", {token: "1234"}.to_json, {})
    end
  end

  def test_post_some_other_failure
    stub_http("/my/wrong/url"){ raise ArgumentError.new("lol") }

    assert_raises(ArgumentError) do
      service_post("/my/wrong/url", {token: "1234"}.to_json, {})
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
codeclimate-services-1.1.0 test/service_test.rb
codeclimate-services-1.0.1 test/service_test.rb
codeclimate-services-1.0.0 test/service_test.rb
codeclimate-services-0.6.2 test/service_test.rb
codeclimate-services-0.6.1 test/service_test.rb
codeclimate-services-0.6.0 test/service_test.rb
codeclimate-services-0.5.3 test/service_test.rb
codeclimate-services-0.5.2 test/service_test.rb
codeclimate-services-0.5.1 test/service_test.rb
codeclimate-services-0.5.0 test/service_test.rb
codeclimate-services-0.4.1 test/service_test.rb
codeclimate-services-0.4.0 test/service_test.rb
codeclimate-services-0.3.0 test/service_test.rb