Sha256: c6b5b21544f5f0bd719365f4856304d6e34fd8ed0cf0a610cc12c35f4f5ce5df

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")

describe TokyoApi::ExternalImage do
  subject { TokyoApi.new(host: 'test.com') }

  describe '#track_download' do
    let(:photo_id) { 'abcde-123456' }
    let(:request_path) { "/external_image/#{photo_id}/download" }

    before(:each) do
      stub_post(request_path).to_return(body: body, status: status,
                                       headers: { content_type: 'application/json; charset=utf-8' })
    end

    context 'error on tokyo' do
      let(:status) { 500 }
      let(:body) { {status: :error}.to_json }

      it 'should raise error' do
        expect { subject.external_image.track_download(photo_id) }.to raise_error(Vertebrae::ResponseError)
      end
    end

    context 'successful call to tokyo' do
      let(:status) { 204 }
      let(:body) { nil }

      it 'should return true' do
        result = subject.external_image.track_download(photo_id)

        expect(result).to be_truthy
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tokyo_api-1.9.0 spec/external_image_spec.rb
tokyo_api-1.8.0 spec/external_image_spec.rb