Sha256: 0160d3a20f9fb2e59f25297150264376197277d5afb79d6198307999b377f634

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'

describe Apress::YandexMarket::Readers::ModelByCategory do
  let(:categories) { 'Товары для красоты' } # id: 90509
  let(:reader) { described_class.new(token: 'secret_token', categories: categories) }

  describe '.allowed_options' do
    it { expect(described_class.allowed_options).to eq %i(token region_id categories) }
  end

  describe '#each_row' do
    before do
      allow(reader.category_reader.client).to receive(:get).and_call_original
      allow(reader.category_reader.client).to receive(:get).with('categories/90509/children', anything).
        and_return(categories: [{id: 8_476_099, childCount: 0}])
    end

    context 'valid models' do
      let(:rows) { [] }

      before do
        VCR.use_cassette 'read_models_from_category' do
          reader.each_row { |row| rows << row }
        end
      end

      it 'reads models of specified categories and their subcategories' do
        expect(rows).to have(31).items
        expect(rows.uniq).to have(31).items
        expect(rows.select { |r| r[:price].nil? }).to be_empty
      end
    end

    context 'when some models do not have category' do
      let(:rows) { [] }

      before do
        VCR.use_cassette 'read_models_without_category' do
          reader.each_row { |row| rows << row }
        end
      end

      it 'reads models of specified categories and their subcategories' do
        expect(rows).to have(29).items
        expect(rows.uniq).to have(29).items
        expect(rows.select { |r| r[:price].nil? }).to be_empty
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
apress-yandex_market-0.2.1 spec/apress/yandex_market/readers/model_by_category_spec.rb
apress-yandex_market-0.2.0 spec/apress/yandex_market/readers/model_by_category_spec.rb