Sha256: b1e84cca9069978989e08e21c4a5154623c20e3a84ef68b502c4343222848fd7

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

# encoding: utf-8

describe Cieloz::Requisicao do
  let(:_)       { subject.class }
  let(:id)      { "1" }
  let(:versao)  { "1.2.0" }
  let(:opts)    { { root: "requisicao", id: id, versao: versao } }

  let(:dir)     { File.dirname __FILE__ }

  before do
    subject.id = id
    subject.versao = versao
  end

  it "serializes" do
    assert_equal expected_xml(opts), subject.to_xml
  end

  describe "value attributes" do
    before do
      subject.class_eval do
        attr_accessor :foo

        def attributes
          { foo: @foo }
        end
      end
    end

    let(:foo) { "Informações Extras" }

    it "serializes" do
      subject.foo = foo

      xml = expected_xml(opts) { "<foo>#{foo}</foo>" }
      assert_equal xml, subject.to_xml
    end

    it "ignores nils" do
      subject.foo = nil
      assert_equal expected_xml(opts), subject.to_xml
    end
  end

  describe "complex attributes" do
    let(:attributes)  { { numero: 123, chave: "M3str4" } }
    let(:ec)          { _::DadosEc.new attributes }
    let(:xml) { expected_xml(opts) { xml_for :ec, dir, binding } }

    it "serializes" do
      subject.dados_ec = ec
      assert_equal xml, subject.to_xml
    end

    it "ignores nils" do
      attributes.merge! ignore_me: nil
      subject.dados_ec = ec
      assert_equal xml, subject.to_xml
    end
  end

  describe "request posting" do
    let(:err) { "101" }
    let(:msg) { "Invalid" }
    let(:fake_response) { render_template dir, "erro.xml", binding }

    before do
      FakeWeb.register_uri :post, Cieloz::Configuracao.url, body: fake_response
    end

    it "sends to test web service" do
      subject.dados_ec = _::DadosEc.new Cieloz::Homologacao::Credenciais::CIELO
      erro = subject.submit
      assert_equal({}, subject.errors.messages)
      assert_equal err, erro.codigo
      assert_equal "Invalid", erro.mensagem
    end

    after do
      FakeWeb.clean_registry
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cieloz-0.0.4 test/unit/requisicao_test.rb
cieloz-0.0.3 test/unit/requisicao_test.rb
cieloz-0.0.2 test/unit/requisicao_test.rb