Sha256: 0e1f98f6eb5b16ded20fb559fedaeb038b5f9ca5e2444339926de0595a05eacb

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'
require 'td/client/spec_resources'

describe 'Result API' do
  include_context 'spec symbols'
  include_context 'common helper'

  let :api do
    API.new(nil)
  end

  describe 'create_result' do
    it 'should create a new result' do
      params = {'url' => result_url}
      stub_api_request(:post, "/v3/result/create/#{e(result_name)}").with(:body => params).to_return(:body => {'result' => result_name})

      api.create_result(result_name, result_url).should be_true
    end

    it 'should return 422 error with invalid name' do
      name = '1'
      params = {'url' => result_url}
      err_msg = "Validation failed: Name is too short" # " (minimum is 3 characters)"
      stub_api_request(:post, "/v3/result/create/#{e(name)}").with(:body => params)
        .to_return(:status => 422, :body => {'message' => err_msg}.to_json)

      expect {
        api.create_result(name, result_url)
      }.to raise_error(TreasureData::APIError, /#{err_msg}/)
    end

    it 'should return 422 error without url' do
      params = {'url' => 'false'} # I want to use nil, but nil doesn't work on WebMock...
      err_msg = "'url' parameter is required"
      stub_api_request(:post, "/v3/result/create/#{e(result_name)}").with(:body => params)
        .to_return(:status => 422, :body => {'message' => err_msg}.to_json)

      expect {
        api.create_result(result_name, false)
      }.to raise_error(TreasureData::APIError, /#{err_msg}/)
    end

    it 'should return 409 error with duplicated name' do
      params = {'url' => result_url}
      err_msg = "Result must be unique"
      stub_api_request(:post, "/v3/result/create/#{e(result_name)}").with(:body => params)
        .to_return(:status => 409, :body => {'message' => err_msg}.to_json)

      expect {
        api.create_result(result_name, result_url)
      }.to raise_error(TreasureData::APIError, /#{err_msg}/)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
td-client-0.8.65 spec/td/client/result_api_spec.rb
td-client-0.8.64 spec/td/client/result_api_spec.rb
td-client-0.8.63 spec/td/client/result_api_spec.rb