Sha256: fa05119f17ea43997b3476907593809d27c2841c0ac60f4a0d066b786fc99d66

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

require "spec_helper"

describe FastshopCatalog::OrderPlacementService do

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

  let(:contract_number) do
    "1234567890"
  end
  
  let(:order) do
    order = FastshopCatalog::Entity::Order.new
    order.contract_code = '1234567890'
    order.zip_code = '02029001'
    order.document = '73978898160'
    order.number = '1560'
    order.total_amount = "69.00"
    order.delivery_type = "P"
    order.partner_order_number = "1234568119"
    order_item = FastshopCatalog::Entity::OrderItem.new
    order_item.sku = 'IVIEP314RED'
    order_item.quantity = 1
    order_item.price = "69.00"
    order.items = [order_item]
    order
  end

  let(:service) do
    service = FastshopCatalog::OrderPlacementService.new
  end

  let(:order_attr) do
    File.read("spec/fixtures/order_placement_successful_payload.json")
  end

  let(:fixture_cart_not_identified) do
    File.read("spec/fixtures/order_placement_cart_not_identified.xml")
  end

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

  describe "place_order" do

    it "should raise cart not identified" do
      encrypted_payload = service.encrypt(order_attr)
      savon.expects(:incluir_pedido).with(:message => {'tns:contrato' => contract_number,
        'tns:entrada' => encrypted_payload, 'tns:salt' => ''}).returns(fixture_cart_not_identified)
      expect{service.place_order(order)}.to raise_error(FastshopCatalog::ServiceException) do |e|
        expect(e.code).to eq(37)
        expect(e.description).to eq('Carrinho nao identificado no sistema')
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fastshop_catalog-0.0.2 spec/fastshop_catalog/order_placement_service_spec.rb
fastshop_catalog-0.0.1 spec/fastshop_catalog/order_placement_service_spec.rb