Sha256: 29511c8b6532365c54229b526068d6c52806d2fc771d647088fe42997e883a6d

Contents?: true

Size: 1.78 KB

Versions: 8

Compression:

Stored size: 1.78 KB

Contents

# encoding: utf-8
require "spec_helper"

describe FastshopCatalog::ProductService do

  include Savon::SpecHelper
  before(:all) { savon.mock! }
  after(:all)  { savon.unmock! }

  let(:contract_number) do
    "1234567890"
  end
  
  let(:service) do
    service = FastshopCatalog::ProductService.new
  end
  
  let(:sku) do
    'A5IMT237'
  end

  let(:fixture) do
    File.read("spec/fixtures/product_service_successful_response.xml")
  end

  let(:fixture_wrong_contract) do
    File.read("spec/fixtures/product_service_wrong_contract_response.xml")
  end

  let(:fixture_wrong_sku) do
    File.read("spec/fixtures/product_service_wrong_sku_response.xml")
  end

  describe "search" do

    it "should return the list with the expected size" do
      savon.expects(:busca_produto).with(:message => {'tns:contrato' => contract_number, 'tns:sku' => sku }).returns(fixture)
      result = service.search(contract_number, sku)
      expect(result['Nome']).to eq("Alto Falante Ultra Portátil Prata - Altec Lansing - IMT237  ")
    end

    it "should return wrong contract exception" do
      savon.expects(:busca_produto).with(:message => {'tns:contrato' => 'lixo', 'tns:sku' => sku}).returns(fixture_wrong_contract)
      expect{service.search('lixo', sku)}.to raise_error(FastshopCatalog::ServiceException) do |e|
        expect(e.code).to eq(2)
        expect(e.description).to eq('Contrato invalido')
      end
    end
    
    it "should return wrong sku exception" do
      savon.expects(:busca_produto).with(:message => {'tns:contrato' => 'lixo', 'tns:sku' => sku}).returns(fixture_wrong_sku)
      expect{service.search('lixo', sku)}.to raise_error(FastshopCatalog::ServiceException) do |e|
        expect(e.code).to eq(43)
        expect(e.description).to eq('Produto invalido')
      end
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fastshop_catalog-0.0.8 spec/fastshop_catalog/product_service_spec.rb
fastshop_catalog-0.0.7 spec/fastshop_catalog/product_service_spec.rb
fastshop_catalog-0.0.6 spec/fastshop_catalog/product_service_spec.rb
fastshop_catalog-0.0.5 spec/fastshop_catalog/product_service_spec.rb
fastshop_catalog-0.0.4 spec/fastshop_catalog/product_service_spec.rb
fastshop_catalog-0.0.3 spec/fastshop_catalog/product_service_spec.rb
fastshop_catalog-0.0.2 spec/fastshop_catalog/product_service_spec.rb
fastshop_catalog-0.0.1 spec/fastshop_catalog/product_service_spec.rb