Sha256: 2e733bf766f8766a13088d3c97d0325221a4a0d47c84b6a6e37d21c681e18111

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

require 'spec_helper'
require 'rakuten_web_service'

describe RWS::Kobo::Genre do
  let(:endpoint) { 'https://app.rakuten.co.jp/services/api/Kobo/GenreSearch/20131010' }
  let(:affiliate_id) { 'dummy_affiliate_id' }
  let(:application_id) { 'dummy_application_id' }
  let(:genre_id) { '101' }
  let(:expected_query) do
    {
      :affiliateId => affiliate_id,
      :applicationId => application_id,
      :koboGenreId => genre_id
    }
  end
  let(:expected_json) do
    JSON.parse(fixture('kobo/genre_search.json'))
  end

  before do
    @expected_request = stub_request(:get, endpoint).
      with(:query => expected_query).
      to_return(:body => expected_json.to_json)

    RakutenWebService.configuration do |c|
      c.affiliate_id = affiliate_id
      c.application_id = application_id
    end
  end

  describe '.search' do
    before do
      @genre = RWS::Kobo::Genre.search(:koboGenreId => genre_id).first
    end

    specify 'call the endpoint once' do
      expect(@expected_request).to have_been_made.once
    end
  end

  describe '#search' do
    before do
      stub_request(:get, endpoint).with(:query => expected_query).
        to_return(:body => expected_json.to_json)
    end

    context 'Without arguments' do
      specify 'should call RWS::Kobo::Ebook.search with specifying genre id' do
        expect(RWS::Kobo::Ebook).to receive(:search).with(RWS::Kobo::Genre.genre_id_key => genre_id)

        RWS::Kobo::Genre.root.search
      end
    end
    context 'With arguments' do
      specify 'should call RWS::Kobo::Ebook.search with given arguments and genre id' do
        options = { title: 'Ruby' }
        expect(RWS::Kobo::Ebook).to receive(:search).with(:title => 'Ruby', RWS::Kobo::Genre.genre_id_key => genre_id)

        RWS::Kobo::Genre.root.search(options)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rakuten_web_service-0.6.3 spec/rakuten_web_service/kobo/genre_spec.rb