Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.42 KB | None | 0 0
  1. # require the helper module
  2. require "savon/mock/spec_helper"
  3.  
  4. module Agillitas    
  5.     Models = Moneto::Core::Models  
  6.     Agillitas = Models::Agillitas::AgillitasIntegration
  7.  
  8.     RSpec.describe Agillitas do
  9.         # include the helper module
  10.         include Savon::SpecHelper
  11.  
  12.         # set Savon in and out of mock mode
  13.         before(:all) { savon.mock!   }
  14.         after(:all)  { savon.unmock! }
  15.  
  16.         describe "AgillitasIntegration" do
  17.            
  18.             describe 'check_has_balance' do
  19.                
  20.                 it 'simple test' do
  21.  
  22.                     agillitas_mocked_response =
  23.                     '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  24.                        <s:Body>
  25.                            <IntegrarResponse xmlns="http://tempuri.org/">
  26.                                 <IntegrarResult          
  27.                                 xmlns:a="http://schemas.datacontract.org/2004/07/Agillitas.Servico.ContratosDeServico"
  28.                                 xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  29.                                    <a:Cabecalho>
  30.                                        <a:Metodo>54</a:Metodo>
  31.                                        <a:Status>Sucesso</a:Status>
  32.                                    </a:Cabecalho>
  33.                                    <a:Corpo>
  34.                                        <![CDATA[
  35.                                            <SaldoCartaoVirtual>
  36.                                                <Saldo>500</Saldo>
  37.                                                <ValorPendente>0</ValorPendente>
  38.                                            </SaldoCartaoVirtual>
  39.                                        ]]>
  40.                                    </a:Corpo>
  41.                                </IntegrarResult>
  42.                            </IntegrarResponse>
  43.                        </s:Body>
  44.                    </s:Envelope>'
  45.  
  46.                     body_of_xml = {
  47.                         ConsultarSaldoCartaoVirtual:{
  48.                             Empresa: '3596',
  49.                             Moeda: '790'
  50.                         }
  51.                    
  52.                     }
  53.  
  54.                     xml = Agillitas.new.to_xml(body_of_xml)
  55.                     message = {
  56.                         request: {
  57.                           'agil:Cabecalho':
  58.                             {
  59.                               'agil:Metodo': 54,
  60.                               'agil:PublicKey': 'integr@moneto',
  61.                               'agil:Senha': '27958950',
  62.                               'agil:Usuario': 'ws.integramoneto'
  63.                              
  64.                               #'agil:Metodo': method_id,
  65.                               #'agil:PublicKey': config[:public_key],
  66.                               #'agil:Senha': config[:senha],
  67.                               #'agil:Usuario': config[:usuario]
  68.  
  69.                             },
  70.                           'agil:Corpo!': "<![CDATA[#{xml}]]>"
  71.                         }
  72.                       }
  73.  
  74.                     savon.expects(:integrar).with(message: message).returns (agillitas_mocked_response)
  75.  
  76.                     result = Agillitas.new.check_has_balance()
  77.  
  78.                     expect(result[:balance].to_f).to eq 500
  79.                     expect(result[:pendent_balance].to_f).to eq 0  
  80.  
  81.    
  82.                 end
  83.        
  84.             end
  85.  
  86.         end
  87.  
  88.     end
  89.  
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement