Sha256: 908f93c9b17dbb8bb2c6355c62788f391e8a602a76c510baf6721a2bfe20ccf8

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../helpers/resource_test_helper')

class SourcesGetOneResourceTest < ResourceTestCase

  def app; DataCatalog::Sources end
  
  before do
    @source = create_source
  end

  after do
    @source.destroy
  end

  context "get /:id" do
    context "anonymous" do
      before do
        get "/#{@source.id}"
      end
    
      use "return 401 because the API key is missing"
    end

    context "incorrect API key" do
      before do
        get "/#{@source.id}", :api_key => BAD_API_KEY
      end
  
      use "return 401 because the API key is invalid"
    end
  end

  %w(basic curator admin).each do |role|
    context "#{role} : get /:fake_id" do
      before do
        get "/#{FAKE_ID}", :api_key => api_key_for(role)
      end
    
      use "return 404 Not Found"
      use "return an empty response body"
    end

    context "#{role} : get /:id" do
      before do
        @category = create_category
        @categorization = create_categorization(
          :source_id   => @source.id,
          :category_id => @category.id
        )
        get "/#{@source.id}", :api_key => api_key_for(role)
      end

      after do
        @category.destroy
        @categorization.destroy
      end

      use "return 200 Ok"
      doc_properties %w(title url raw categories id created_at updated_at)

      test "body should have correct categories" do
        expected = [
          {
            "id"   => @category.id,
            "href" => "/categories/#{@category.id}",
            "name" => @category.name,
          }
        ]
        assert_equal expected, parsed_response_body["categories"]
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sinatra_resource-0.1.0 examples/datacatalog/test/resources/sources/sources_get_one_test.rb