br_nfe 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/br_nfe/active_model_base.rb +0 -5
  4. data/lib/br_nfe/base.rb +116 -7
  5. data/lib/br_nfe/helper/values_ts/service_v1.rb +15 -11
  6. data/lib/br_nfe/response/service/build_response.rb +230 -53
  7. data/lib/br_nfe/response/service/nota_fiscal.rb +9 -0
  8. data/lib/br_nfe/response/service/paths/base.rb +93 -59
  9. data/lib/br_nfe/response/service/paths/v1/servico_cancelar_nfse_resposta.rb +2 -2
  10. data/lib/br_nfe/response/service/paths/v1/servico_consultar_lote_rps_resposta.rb +2 -2
  11. data/lib/br_nfe/response/service/paths/v1/servico_consultar_nfse_resposta.rb +2 -2
  12. data/lib/br_nfe/response/service/paths/v1/servico_consultar_nfse_rps_resposta.rb +2 -2
  13. data/lib/br_nfe/response/service/paths/v1/servico_consultar_situacao_lote_rps_resposta.rb +4 -4
  14. data/lib/br_nfe/response/service/paths/v1/servico_enviar_lote_rps_resposta.rb +8 -8
  15. data/lib/br_nfe/response/service/paths/v1/tc_nfse.rb +201 -57
  16. data/lib/br_nfe/service/base.rb +104 -5
  17. data/lib/br_nfe/service/betha/base.rb +5 -0
  18. data/lib/br_nfe/service/betha/v1/cancelamento_nfs.rb +1 -4
  19. data/lib/br_nfe/service/betha/v1/consulta_lote_rps.rb +1 -4
  20. data/lib/br_nfe/service/betha/v1/consulta_nfs_por_rps.rb +1 -4
  21. data/lib/br_nfe/service/betha/v1/consulta_nfse.rb +1 -4
  22. data/lib/br_nfe/service/betha/v1/consulta_situacao_lote_rps.rb +1 -3
  23. data/lib/br_nfe/service/betha/v1/gateway.rb +1 -1
  24. data/lib/br_nfe/service/betha/v1/recepcao_lote_rps.rb +1 -3
  25. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_lote_rps_resposta.rb +5 -1
  26. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_resposta.rb +5 -1
  27. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +5 -1
  28. data/lib/br_nfe/service/concerns/rules/cancelamento_nfs.rb +5 -0
  29. data/lib/br_nfe/service/rps.rb +13 -4
  30. data/lib/br_nfe/service/simpliss/v1/base.rb +79 -0
  31. data/lib/br_nfe/service/simpliss/v1/cancela_nfse.rb +30 -0
  32. data/lib/br_nfe/service/simpliss/v1/consulta_lote_rps.rb +38 -0
  33. data/lib/br_nfe/service/simpliss/v1/consulta_nfs_por_rps.rb +31 -0
  34. data/lib/br_nfe/service/simpliss/v1/consulta_nfse.rb +30 -0
  35. data/lib/br_nfe/service/simpliss/v1/consulta_situacao_lote_rps.rb +29 -0
  36. data/lib/br_nfe/service/simpliss/v1/recepcao_lote_rps.rb +35 -0
  37. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_cancelar_nfse_resposta.rb +22 -0
  38. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_lote_rps_resposta.rb +25 -0
  39. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_nfse_resposta.rb +25 -0
  40. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +25 -0
  41. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_situacao_lote_rps_resposta.rb +31 -0
  42. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_enviar_lote_rps_resposta.rb +36 -0
  43. data/lib/br_nfe/service/simpliss/v1/xml/_login.xml.slim +3 -0
  44. data/lib/br_nfe/service/simpliss/v1/xml/_tc_dados_servico.xml.slim +18 -0
  45. data/lib/br_nfe/service/simpliss/v1/xml/_tc_item_servico.xml.slim +3 -0
  46. data/lib/br_nfe/service/simpliss/v1/xml/servico_cancelar_nfse_envio.xml.slim +11 -0
  47. data/lib/br_nfe/service/simpliss/v1/xml/servico_consultar_lote_rps_envio.xml.slim +7 -0
  48. data/lib/br_nfe/service/simpliss/v1/xml/servico_consultar_nfse_envio.xml.slim +22 -0
  49. data/lib/br_nfe/service/simpliss/v1/xml/servico_consultar_nfse_rps_envio.xml.slim +8 -0
  50. data/lib/br_nfe/service/simpliss/v1/xml/servico_consultar_situacao_lote_rps_envio.xml.slim +7 -0
  51. data/lib/br_nfe/service/simpliss/v1/xml/servico_enviar_lote_rps_envio.xml.slim +11 -0
  52. data/lib/br_nfe/service/thema/v1/base.rb +48 -2
  53. data/lib/br_nfe/service/thema/v1/cancela_nfse.rb +14 -5
  54. data/lib/br_nfe/service/thema/v1/consulta_lote_rps.rb +5 -4
  55. data/lib/br_nfe/service/thema/v1/consulta_nfs_por_rps.rb +5 -4
  56. data/lib/br_nfe/service/thema/v1/consulta_nfse.rb +5 -4
  57. data/lib/br_nfe/service/thema/v1/consulta_situacao_lote_rps.rb +1 -4
  58. data/lib/br_nfe/service/thema/v1/recepcao_lote_rps.rb +19 -5
  59. data/lib/br_nfe/service/thema/v1/recepcao_lote_rps_limitado.rb +1 -1
  60. data/lib/br_nfe/service/thema/v1/response_paths/servico_cancelar_nfse_resposta.rb +17 -0
  61. data/lib/br_nfe/service/thema/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +19 -0
  62. data/lib/br_nfe/service/xml/v1/_tc_contato.xml.slim +2 -2
  63. data/lib/br_nfe/service/xml/v1/_tc_cpf_cnpj.xml.slim +2 -2
  64. data/lib/br_nfe/service/xml/v1/_tc_dados_construcao_civil.xml.slim +2 -2
  65. data/lib/br_nfe/service/xml/v1/_tc_dados_prestador.xml.slim +5 -5
  66. data/lib/br_nfe/service/xml/v1/_tc_dados_servico.xml.slim +6 -6
  67. data/lib/br_nfe/service/xml/v1/_tc_dados_tomador.xml.slim +4 -4
  68. data/lib/br_nfe/service/xml/v1/_tc_endereco.xml.slim +7 -7
  69. data/lib/br_nfe/service/xml/v1/_tc_identificacao_intermediario_servico.xml.slim +3 -3
  70. data/lib/br_nfe/service/xml/v1/_tc_identificacao_nfse.xml.slim +4 -4
  71. data/lib/br_nfe/service/xml/v1/_tc_identificacao_orgao_gerador.xml.slim +2 -2
  72. data/lib/br_nfe/service/xml/v1/_tc_identificacao_prestador.xml.slim +2 -2
  73. data/lib/br_nfe/service/xml/v1/_tc_identificacao_rps.xml.slim +3 -3
  74. data/lib/br_nfe/service/xml/v1/_tc_identificacao_tomador.xml.slim +2 -2
  75. data/lib/br_nfe/service/xml/v1/_tc_inf_pedido_cancelamento.xml.slim +2 -2
  76. data/lib/br_nfe/service/xml/v1/_tc_inf_rps.xml.slim +13 -13
  77. data/lib/br_nfe/service/xml/v1/_tc_lote_rps.xml.slim +6 -6
  78. data/lib/br_nfe/service/xml/v1/_tc_pedido_cancelamento.xml.slim +1 -1
  79. data/lib/br_nfe/service/xml/v1/_tc_rps.xml.slim +2 -2
  80. data/lib/br_nfe/service/xml/v1/_tc_valores.xml.slim +16 -17
  81. data/lib/br_nfe/service/xml/v1/servico_cancelar_nfse_envio.xml.slim +3 -4
  82. data/lib/br_nfe/service/xml/v1/servico_consultar_lote_rps_envio.xml.slim +3 -3
  83. data/lib/br_nfe/service/xml/v1/servico_consultar_nfse_envio.xml.slim +8 -8
  84. data/lib/br_nfe/service/xml/v1/servico_consultar_nfse_rps_envio.xml.slim +3 -3
  85. data/lib/br_nfe/service/xml/v1/servico_consultar_situacao_lote_rps_envio.xml.slim +3 -3
  86. data/lib/br_nfe/service/xml/v1/servico_enviar_lote_rps_envio.xml.slim +3 -3
  87. data/lib/br_nfe/version.rb +1 -1
  88. data/lib/br_nfe/xml/_signed_info_sh1.xml.slim +9 -9
  89. data/lib/br_nfe/xml/signature_sh1.xml.slim +5 -5
  90. data/lib/br_nfe.rb +26 -10
  91. data/test/br_nfe/base_test.rb +5 -5
  92. data/test/br_nfe/helper/values_ts/service_v1_test.rb +376 -0
  93. data/test/br_nfe/response/service/build_response_test.rb +1 -173
  94. data/test/br_nfe/response/service/paths/base_test.rb +61 -64
  95. data/test/br_nfe/response/service/paths/v1/servico_cancelar_nfse_resposta_test.rb +2 -2
  96. data/test/br_nfe/response/service/paths/v1/servico_consultar_lote_rps_resposta_test.rb +2 -2
  97. data/test/br_nfe/response/service/paths/v1/servico_consultar_nfse_resposta_test.rb +2 -2
  98. data/test/br_nfe/response/service/paths/v1/servico_consultar_nfse_rps_resposta_test.rb +2 -2
  99. data/test/br_nfe/response/service/paths/v1/servico_consultar_situacao_lote_rps_resposta_test.rb +3 -3
  100. data/test/br_nfe/response/service/paths/v1/servico_enviar_lote_rps_resposta_test.rb +4 -4
  101. data/test/br_nfe/response/service/paths/v1/tc_nfse_test.rb +27 -31
  102. data/test/br_nfe/service/base_test.rb +206 -11
  103. data/test/br_nfe/service/betha/base_test.rb +9 -0
  104. data/test/br_nfe/service/betha/v1/cancelamento_nfs_test.rb +0 -6
  105. data/test/br_nfe/service/betha/v1/consulta_lote_rps_test.rb +0 -6
  106. data/test/br_nfe/service/betha/v1/consulta_nfs_por_rps_test.rb +0 -4
  107. data/test/br_nfe/service/betha/v1/consulta_nfse_test.rb +0 -4
  108. data/test/br_nfe/service/betha/v1/consulta_situacao_lote_rps_test.rb +1 -5
  109. data/test/br_nfe/service/betha/v1/gateway_test.rb +4 -2
  110. data/test/br_nfe/service/betha/v1/recepcao_lote_rps_test.rb +0 -4
  111. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_lote_rps_resposta_test.rb +1 -1
  112. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_resposta_test.rb +1 -1
  113. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_rps_resposta_test.rb +1 -1
  114. data/test/br_nfe/service/rps_test.rb +39 -6
  115. data/test/br_nfe/service/simpliss/v1/base_test.rb +102 -0
  116. data/test/br_nfe/service/simpliss/v1/cancela_nfse_test.rb +97 -0
  117. data/test/br_nfe/service/simpliss/v1/consulta_lote_rps_test.rb +241 -0
  118. data/test/br_nfe/service/simpliss/v1/consulta_nfs_por_rps_test.rb +239 -0
  119. data/test/br_nfe/service/simpliss/v1/consulta_nfse_test.rb +226 -0
  120. data/test/br_nfe/service/simpliss/v1/consulta_situacao_lote_rps_test.rb +122 -0
  121. data/test/br_nfe/service/simpliss/v1/recepcao_lote_rps_test.rb +105 -0
  122. data/test/br_nfe/service/simpliss/v1/xsd/nfse_3.xsd +735 -0
  123. data/test/br_nfe/service/simpliss/v1/xsd/xmldsig-core-schema20020212.xsd +318 -0
  124. data/test/br_nfe/service/thema/v1/base_test.rb +23 -2
  125. data/test/br_nfe/service/thema/v1/cancela_nfse_test.rb +69 -3
  126. data/test/br_nfe/service/thema/v1/consulta_lote_rps_test.rb +134 -4
  127. data/test/br_nfe/service/thema/v1/consulta_nfs_por_rps_test.rb +131 -4
  128. data/test/br_nfe/service/thema/v1/consulta_nfse_test.rb +214 -4
  129. data/test/br_nfe/service/thema/v1/consulta_situacao_lote_rps_test.rb +97 -4
  130. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_limitado_test.rb +109 -0
  131. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_test.rb +72 -4
  132. data/test/factories/service/rps.rb +17 -16
  133. data/test/factories/service/{sc/gaspar/recepcao_lote_rps_limitado.rb → simpliss/v1/base.rb} +1 -3
  134. data/test/factories/service/{sc/gaspar → simpliss/v1}/cancela_nfse.rb +2 -2
  135. data/test/factories/service/simpliss/v1/consulta_lote_rps.rb +7 -0
  136. data/test/factories/service/{sc/gaspar → simpliss/v1}/consulta_nfs_por_rps.rb +1 -1
  137. data/test/factories/service/{sc/gaspar → simpliss/v1}/consulta_nfse.rb +1 -1
  138. data/test/factories/service/simpliss/v1/consulta_situacao_lote_rps.rb +6 -0
  139. data/test/factories/service/{sc/gaspar → simpliss/v1}/recepcao_lote_rps.rb +1 -1
  140. data/test/fixtures/service/response/simpliss/v1/cancela_nfse/fault.xml +21 -0
  141. data/test/fixtures/service/response/simpliss/v1/cancela_nfse/success.xml +26 -0
  142. data/test/fixtures/service/response/simpliss/v1/consulta_lote_rps/fault.xml +21 -0
  143. data/test/fixtures/service/response/simpliss/v1/consulta_lote_rps/nfse_complete.xml +134 -0
  144. data/test/fixtures/service/response/simpliss/v1/consulta_lote_rps/nfse_simple.xml +100 -0
  145. data/test/fixtures/service/response/simpliss/v1/consulta_nfse/fault.xml +16 -0
  146. data/test/fixtures/service/response/simpliss/v1/consulta_nfse/nfs_empty.xml +10 -0
  147. data/test/fixtures/service/response/simpliss/v1/consulta_nfse/nfse_complete.xml +134 -0
  148. data/test/fixtures/service/response/simpliss/v1/consulta_nfse/nfse_simple.xml +100 -0
  149. data/test/fixtures/service/response/simpliss/v1/consulta_nfse_por_rps/fault.xml +16 -0
  150. data/test/fixtures/service/response/simpliss/v1/consulta_nfse_por_rps/nfse_complete.xml +132 -0
  151. data/test/fixtures/service/response/simpliss/v1/consulta_nfse_por_rps/nfse_simple.xml +98 -0
  152. data/test/fixtures/service/response/simpliss/v1/consulta_situacao_lote_rps/error.xml +11 -0
  153. data/test/fixtures/service/response/simpliss/v1/consulta_situacao_lote_rps/fault.xml +16 -0
  154. data/test/fixtures/service/response/simpliss/v1/consulta_situacao_lote_rps/success.xml +11 -0
  155. data/test/fixtures/service/response/simpliss/v1/consulta_situacao_lote_rps/unprocessed.xml +11 -0
  156. data/test/fixtures/service/response/simpliss/v1/consulta_situacao_lote_rps/unreceived.xml +11 -0
  157. data/test/fixtures/service/response/simpliss/v1/recepcao_lote_rps/error.xml +16 -0
  158. data/test/fixtures/service/response/simpliss/v1/recepcao_lote_rps/success.xml +12 -0
  159. data/test/fixtures/service/response/thema/v1/cancela_nfse/fault.xml +33 -0
  160. data/test/fixtures/service/response/thema/v1/cancela_nfse/success.xml +30 -0
  161. data/test/fixtures/service/response/thema/v1/consulta_lote_rps/fault.xml +19 -0
  162. data/test/fixtures/service/response/thema/v1/consulta_lote_rps/nfse_complete.xml +109 -0
  163. data/test/fixtures/service/response/thema/v1/consulta_nfse/fault.xml +20 -0
  164. data/test/fixtures/service/response/thema/v1/consulta_nfse/nfs_empty.xml +14 -0
  165. data/test/fixtures/service/response/thema/v1/consulta_nfse/nfse_complete.xml +111 -0
  166. data/test/fixtures/service/response/thema/v1/consulta_nfse/nfse_simple.xml +111 -0
  167. data/test/fixtures/service/response/thema/v1/consulta_nfse_por_rps/fault.xml +23 -0
  168. data/test/fixtures/service/response/thema/v1/consulta_nfse_por_rps/nfse_complete.xml +110 -0
  169. data/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/error.xml +14 -0
  170. data/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/fault.xml +15 -0
  171. data/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/success.xml +14 -0
  172. data/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/unprocessed.xml +14 -0
  173. data/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/unreceived.xml +19 -0
  174. data/test/fixtures/service/response/thema/v1/recepcao_lote_rps/error.xml +17 -0
  175. data/test/fixtures/service/response/thema/v1/recepcao_lote_rps/success.xml +15 -0
  176. data/test/fixtures/service/response/thema/v1/recepcao_lote_rps_limitado/error.xml +19 -0
  177. data/test/fixtures/service/response/thema/v1/recepcao_lote_rps_limitado/success.xml +15 -0
  178. data/test/fixtures/service/thema/v1/cancelar_nfse_envio.xml +1 -0
  179. data/test/fixtures/service/thema/v1/cancelar_nfse_envio_signed.xml +2 -0
  180. data/test/fixtures/service/thema/v1/enviar_lote_rps.xml +1 -0
  181. data/test/fixtures/service/thema/v1/enviar_lote_rps_signed.xml +2 -0
  182. data/test/test_helper.rb +5 -0
  183. metadata +146 -37
  184. data/lib/br_nfe/service/sc/gaspar/cancela_nfse.rb +0 -13
  185. data/lib/br_nfe/service/sc/gaspar/consulta_lote_rps.rb +0 -13
  186. data/lib/br_nfe/service/sc/gaspar/consulta_nfs_por_rps.rb +0 -13
  187. data/lib/br_nfe/service/sc/gaspar/consulta_nfse.rb +0 -17
  188. data/lib/br_nfe/service/sc/gaspar/consulta_situacao_lote_rps.rb +0 -13
  189. data/lib/br_nfe/service/sc/gaspar/recepcao_lote_rps.rb +0 -13
  190. data/lib/br_nfe/service/sc/gaspar/recepcao_lote_rps_limitado.rb +0 -13
  191. data/test/br_nfe/service/sc/gaspar/cancela_nfse_test.rb +0 -21
  192. data/test/br_nfe/service/sc/gaspar/consulta_nfs_por_rps_test.rb +0 -21
  193. data/test/br_nfe/service/sc/gaspar/consulta_nfse_test.rb +0 -21
  194. data/test/br_nfe/service/sc/gaspar/consulta_situacao_lote_rps_test.rb +0 -21
  195. data/test/br_nfe/service/sc/gaspar/recepcao_lote_rps_limitado_test.rb +0 -22
  196. data/test/br_nfe/service/sc/gaspar/recepcao_lote_rps_test.rb +0 -22
  197. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_test_limitado.rb +0 -50
  198. data/test/factories/service/sc/gaspar/consulta_lote_rps.rb +0 -7
  199. data/test/factories/service/sc/gaspar/consulta_situacao_lote_rps.rb +0 -6
@@ -17,10 +17,6 @@ describe BrNfe::Service::Thema::V1::ConsultaNfsPorRps do
17
17
  it { subject.method_wsdl.must_equal :consultar_nfse_por_rps }
18
18
  end
19
19
 
20
- it "#response_path_module" do
21
- subject.response_path_module.must_equal BrNfe::Service::Response::Paths::V1::ServicoConsultarNfseRpsResposta
22
- end
23
-
24
20
  it "#response_root_path" do
25
21
  subject.response_root_path.must_equal []
26
22
  end
@@ -32,6 +28,27 @@ describe BrNfe::Service::Thema::V1::ConsultaNfsPorRps do
32
28
  subject.soap_body_root_tag.must_equal 'consultarNfsePorRps'
33
29
  end
34
30
 
31
+ describe "#wsdl" do
32
+ it "default" do
33
+ subject.ibge_code_of_issuer_city = '111'
34
+ subject.env = :production
35
+ subject.wsdl.must_equal 'http://nfsehml.gaspar.sc.gov.br/nfse/services/NFSEconsulta?wsdl'
36
+ subject.env = :test
37
+ subject.wsdl.must_equal 'http://nfsehml.gaspar.sc.gov.br/nfse/services/NFSEconsulta?wsdl'
38
+ end
39
+ describe 'Para a cidade 4205902 - Gaspar-SC' do
40
+ before { subject.ibge_code_of_issuer_city = '4205902' }
41
+ it "ambiente de produção" do
42
+ subject.env = :production
43
+ subject.wsdl.must_equal 'http://nfse.gaspar.sc.gov.br/nfse/services/NFSEconsulta?wsdl'
44
+ end
45
+ it "ambiente de testes" do
46
+ subject.env = :test
47
+ subject.wsdl.must_equal 'http://nfsehml.gaspar.sc.gov.br/nfse/services/NFSEconsulta?wsdl'
48
+ end
49
+ end
50
+ end
51
+
35
52
  describe "Validação do XML através do XSD" do
36
53
  let(:schemas_dir) { BrNfe.root+'/test/br_nfe/service/thema/v1/xsd' }
37
54
 
@@ -47,4 +64,114 @@ describe BrNfe::Service::Thema::V1::ConsultaNfsPorRps do
47
64
  end
48
65
  end
49
66
 
67
+ describe "#request and set response" do
68
+ before { savon.mock! }
69
+ after { savon.unmock! }
70
+
71
+ it "Quando a requisição voltar com erro deve setar os erros corretamente" do
72
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/consulta_nfse_por_rps/fault.xml')
73
+
74
+ savon.expects(:consultar_nfse_por_rps).returns(fixture)
75
+ subject.request
76
+ response = subject.response
77
+
78
+ response.status.must_equal :falied
79
+ response.error_messages.size.must_equal 1
80
+ response.error_messages[0][:code].must_equal 'E89'
81
+ response.error_messages[0][:message].must_equal 'Não existe na base de dados uma NFS-e emitida para o número de RPS informado.'
82
+ response.error_messages[0][:solution].must_equal 'Informe o número correto do RPS. '
83
+ response.successful_request?.must_equal true
84
+ end
85
+
86
+ it "Quando encontrar uma nota fiscal" do
87
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/consulta_nfse_por_rps/nfse_complete.xml')
88
+ savon.expects(:consultar_nfse_por_rps).returns(fixture)
89
+ subject.request
90
+ response = subject.response
91
+
92
+ nf = response.notas_fiscais[0]
93
+ nf.numero_nf.must_equal '201600000000003'
94
+ nf.codigo_verificacao.must_equal '1004156850'
95
+ nf.data_emissao.must_equal DateTime.parse('2016-08-12T20:02:36.000Z')
96
+ nf.url_nf.must_be_nil
97
+ nf.xml_nf[0..89].must_equal '<ConsultarNfseRpsResposta xmlns="http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd"><Lista'
98
+ nf.rps_numero.must_equal '15'
99
+ nf.rps_serie.must_equal 'SN'
100
+ nf.rps_tipo.must_equal '1'
101
+ nf.rps_situacao.must_be_nil
102
+ nf.rps_substituido_numero.must_be_nil
103
+ nf.rps_substituido_serie.must_be_nil
104
+ nf.rps_substituido_tipo.must_be_nil
105
+ nf.data_emissao_rps.must_equal Date.parse('2016-08-12Z')
106
+ nf.competencia.must_equal DateTime.parse('2016-08-12T00:00:00.000Z')
107
+ nf.natureza_operacao.must_equal '59'
108
+ nf.regime_especial_tributacao.must_equal '1'
109
+ nf.optante_simples_nacional.must_equal '1'
110
+ nf.incentivador_cultural.must_equal '0'
111
+ nf.outras_informacoes.must_be_nil
112
+ nf.item_lista_servico.must_equal '107'
113
+ nf.cnae_code.must_equal '6202300'
114
+ nf.description.must_equal '1 TESTE WEBSERVICE: R$ 5,00'
115
+ nf.codigo_municipio.must_equal '4204202'
116
+ nf.total_services.must_equal '1700'
117
+ nf.iss_retained.must_equal '2'
118
+ nf.total_iss.must_equal '33.72'
119
+ nf.base_calculation.must_equal '1685.88'
120
+ nf.iss_tax_rate.must_equal '0.02'
121
+ nf.valor_liquido.must_equal '1663.02'
122
+ nf.deductions.must_equal '7'
123
+ nf.valor_pis.must_equal '1.12'
124
+ nf.valor_cofins.must_equal '2.12'
125
+ nf.valor_inss.must_equal '3.12'
126
+ nf.valor_ir.must_equal '4.12'
127
+ nf.valor_csll.must_equal '5.12'
128
+ nf.outras_retencoes.must_equal '6.12'
129
+ nf.desconto_condicionado.must_equal '8.12'
130
+ nf.desconto_incondicionado.must_equal '7.12'
131
+ nf.responsavel_retencao.must_be_nil
132
+ nf.numero_processo.must_be_nil
133
+ nf.orgao_gerador_municipio.must_equal '4205902'
134
+ nf.orgao_gerador_uf.must_equal 'SC'
135
+ nf.cancelamento_codigo.must_be_nil
136
+ nf.cancelamento_numero_nf.must_be_nil
137
+ nf.cancelamento_cnpj.must_be_nil
138
+ nf.cancelamento_inscricao_municipal.must_be_nil
139
+ nf.cancelamento_municipio.must_be_nil
140
+ nf.cancelamento_data_hora.must_be_nil
141
+ nf.cancelamento_sucesso.must_equal false
142
+ nf.nfe_substituidora.must_be_nil
143
+
144
+ nf.emitente.cnpj.must_equal '65978078000120'
145
+ nf.emitente.inscricao_municipal.must_equal '11849'
146
+ nf.emitente.razao_social.must_equal 'EMPRESA EMITENTE LTDA'
147
+ nf.emitente.nome_fantasia.must_equal 'EMITENTE'
148
+ nf.emitente.telefone.must_equal '3326891'
149
+ nf.emitente.email.must_equal 'emitente@gmail.com'
150
+
151
+ nf.emitente.endereco.logradouro.must_equal 'DOUGLAS ALEXANDRE'
152
+ nf.emitente.endereco.numero.must_equal '50'
153
+ nf.emitente.endereco.complemento.must_equal ''
154
+ nf.emitente.endereco.bairro.must_equal 'CENTRO'
155
+ nf.emitente.endereco.codigo_municipio.must_equal '4205902'
156
+ nf.emitente.endereco.uf.must_equal 'SC'
157
+ nf.emitente.endereco.cep.must_equal '89110000'
158
+
159
+ nf.destinatario.cpf_cnpj.must_equal '08670364000'
160
+ nf.destinatario.inscricao_municipal.must_be_nil
161
+ nf.destinatario.inscricao_estadual.must_be_nil
162
+ nf.destinatario.inscricao_suframa.must_be_nil
163
+ nf.destinatario.razao_social.must_equal 'BRUNO MUCELINI MERGEN'
164
+ nf.destinatario.telefone.must_equal '4920493900'
165
+ nf.destinatario.email.must_equal 'brunomergen@gmail.com'
166
+
167
+ nf.destinatario.endereco.logradouro.must_equal 'RUA IGUACU E'
168
+ nf.destinatario.endereco.numero.must_equal '587'
169
+ nf.destinatario.endereco.complemento.must_equal ''
170
+ nf.destinatario.endereco.bairro.must_equal 'SAIC'
171
+ nf.destinatario.endereco.codigo_municipio.must_equal '4204202'
172
+ nf.destinatario.endereco.uf.must_equal 'SC'
173
+ nf.destinatario.endereco.cep.must_equal '89802171'
174
+ end
175
+ end
176
+
50
177
  end
@@ -17,10 +17,6 @@ describe BrNfe::Service::Thema::V1::ConsultaNfse do
17
17
  it { subject.method_wsdl.must_equal :consultar_nfse }
18
18
  end
19
19
 
20
- it "#response_path_module" do
21
- subject.response_path_module.must_equal BrNfe::Service::Response::Paths::V1::ServicoConsultarNfseResposta
22
- end
23
-
24
20
  it "#response_root_path" do
25
21
  subject.response_root_path.must_equal []
26
22
  end
@@ -32,6 +28,27 @@ describe BrNfe::Service::Thema::V1::ConsultaNfse do
32
28
  subject.soap_body_root_tag.must_equal 'consultarNfse'
33
29
  end
34
30
 
31
+ describe "#wsdl" do
32
+ it "default" do
33
+ subject.ibge_code_of_issuer_city = '111'
34
+ subject.env = :production
35
+ subject.wsdl.must_equal 'http://nfsehml.gaspar.sc.gov.br/nfse/services/NFSEconsulta?wsdl'
36
+ subject.env = :test
37
+ subject.wsdl.must_equal 'http://nfsehml.gaspar.sc.gov.br/nfse/services/NFSEconsulta?wsdl'
38
+ end
39
+ describe 'Para a cidade 4205902 - Gaspar-SC' do
40
+ before { subject.ibge_code_of_issuer_city = '4205902' }
41
+ it "ambiente de produção" do
42
+ subject.env = :production
43
+ subject.wsdl.must_equal 'http://nfse.gaspar.sc.gov.br/nfse/services/NFSEconsulta?wsdl'
44
+ end
45
+ it "ambiente de testes" do
46
+ subject.env = :test
47
+ subject.wsdl.must_equal 'http://nfsehml.gaspar.sc.gov.br/nfse/services/NFSEconsulta?wsdl'
48
+ end
49
+ end
50
+ end
51
+
35
52
  describe "Validação do XML através do XSD" do
36
53
  let(:schemas_dir) { BrNfe.root+'/test/br_nfe/service/thema/v1/xsd' }
37
54
 
@@ -47,4 +64,197 @@ describe BrNfe::Service::Thema::V1::ConsultaNfse do
47
64
  end
48
65
  end
49
66
 
67
+ describe "#request and set response" do
68
+ before { savon.mock! }
69
+ after { savon.unmock! }
70
+
71
+ it "Se não encontrar nenhuma NFe" do
72
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/consulta_nfse/nfs_empty.xml')
73
+ savon.expects(:consultar_nfse).returns(fixture)
74
+ subject.request
75
+ response = subject.response
76
+
77
+ response.notas_fiscais.must_be_empty
78
+ response.status.must_equal :success
79
+ response.successful_request?.must_equal true
80
+ end
81
+
82
+ it "Quando a requisição voltar com erro deve setar os erros corretamente" do
83
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/consulta_nfse/fault.xml')
84
+
85
+ savon.expects(:consultar_nfse).returns(fixture)
86
+ subject.request
87
+ response = subject.response
88
+
89
+ response.status.must_equal :falied
90
+ response.error_messages.size.must_equal 1, "#{response.error_messages}"
91
+ response.error_messages[0][:code].must_equal 'E46'
92
+ response.error_messages[0][:message].must_equal 'CNPJ do prestador não informado'
93
+ response.error_messages[0][:solution].must_equal 'Informe o CNPJ do prestador.'
94
+ response.successful_request?.must_equal true
95
+ end
96
+
97
+ it "Quando encontrar uma nota fiscal com as informações básicas preenchidas" do
98
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/consulta_nfse/nfse_simple.xml')
99
+ savon.expects(:consultar_nfse).returns(fixture)
100
+ subject.request
101
+ response = subject.response
102
+
103
+ response.notas_fiscais.size.must_equal 1
104
+ response.status.must_equal :success
105
+ response.successful_request?.must_equal true
106
+
107
+ nf = response.notas_fiscais[0]
108
+ nf.numero_nf.must_equal '201600000000002'
109
+ nf.codigo_verificacao.must_equal '1004156842'
110
+ nf.data_emissao.must_equal DateTime.parse('2016-08-12T20:02:36.000Z')
111
+ nf.url_nf.must_be_nil
112
+ nf.xml_nf[0..102].must_equal '<ConsultarNfseResposta xmlns="http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd"><ListaNfse><CompNfse><'
113
+ nf.rps_numero.must_equal '9'
114
+ nf.rps_serie.must_equal 'SN'
115
+ nf.rps_tipo.must_equal '1'
116
+ nf.rps_situacao.must_be_nil
117
+ nf.rps_substituido_numero.must_be_nil
118
+ nf.rps_substituido_serie.must_be_nil
119
+ nf.rps_substituido_tipo.must_be_nil
120
+ nf.data_emissao_rps.must_equal Date.parse('2016-08-12Z')
121
+ nf.competencia.must_equal DateTime.parse('2016-08-12T00:00:00.000Z')
122
+ nf.natureza_operacao.must_equal '59'
123
+ nf.regime_especial_tributacao.must_equal '1'
124
+ nf.optante_simples_nacional.must_equal '1'
125
+ nf.incentivador_cultural.must_equal '0'
126
+ nf.outras_informacoes.must_be_nil
127
+ nf.item_lista_servico.must_equal '107'
128
+ nf.cnae_code.must_equal '6202300'
129
+ nf.description.must_equal 'SERVICO DE COMINICACAO WEB DIGITAL 1.700,00'
130
+ nf.codigo_municipio.must_equal '4204202'
131
+ nf.total_services.must_equal '10'
132
+ nf.iss_retained.must_equal '2'
133
+ nf.total_iss.must_equal '0.2'
134
+ nf.base_calculation.must_equal '10'
135
+ nf.iss_tax_rate.must_equal '0.035'
136
+ nf.valor_liquido.must_equal '10'
137
+ nf.deductions.must_equal '0'
138
+ nf.valor_pis.must_equal '0'
139
+ nf.valor_cofins.must_equal '0'
140
+ nf.valor_inss.must_equal '0'
141
+ nf.valor_ir.must_equal '0'
142
+ nf.valor_csll.must_equal '0'
143
+ nf.outras_retencoes.must_equal '0'
144
+ nf.desconto_condicionado.must_equal '0'
145
+ nf.desconto_incondicionado.must_equal '0'
146
+ nf.responsavel_retencao.must_be_nil
147
+ nf.numero_processo.must_be_nil
148
+ nf.municipio_incidencia.must_be_nil
149
+ nf.orgao_gerador_municipio.must_equal '4205902'
150
+ nf.orgao_gerador_uf.must_equal 'SC'
151
+ nf.cancelamento_codigo.must_be_nil
152
+ nf.cancelamento_numero_nf.must_be_nil
153
+ nf.cancelamento_cnpj.must_be_nil
154
+ nf.cancelamento_inscricao_municipal.must_be_nil
155
+ nf.cancelamento_municipio.must_be_nil
156
+ nf.cancelamento_sucesso.must_equal false
157
+ nf.cancelamento_data_hora.must_be_nil
158
+ nf.nfe_substituidora.must_be_nil
159
+ nf.codigo_obra.must_be_nil
160
+ nf.codigo_art.must_be_nil
161
+
162
+ nf.destinatario.cpf_cnpj.must_equal '08670364000'
163
+ end
164
+
165
+ it "Quando encontrar uma nota fiscal com as informações completas" do
166
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/consulta_nfse/nfse_complete.xml')
167
+ savon.expects(:consultar_nfse).returns(fixture)
168
+ subject.request
169
+ response = subject.response
170
+
171
+ response.notas_fiscais.size.must_equal 1
172
+ response.status.must_equal :success
173
+ response.successful_request?.must_equal true
174
+
175
+ nf = response.notas_fiscais[0]
176
+ nf.numero_nf.must_equal '201600000000003'
177
+ nf.codigo_verificacao.must_equal '1004156850'
178
+ nf.data_emissao.must_equal DateTime.parse('2016-08-12T20:02:36.000Z')
179
+ nf.url_nf.must_be_nil
180
+ nf.xml_nf[0..89].must_equal '<ConsultarNfseResposta xmlns="http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd"><ListaNfs'
181
+ nf.rps_numero.must_equal '15'
182
+ nf.rps_serie.must_equal 'SN'
183
+ nf.rps_tipo.must_equal '1'
184
+ nf.rps_situacao.must_be_nil
185
+ nf.rps_substituido_numero.must_be_nil
186
+ nf.rps_substituido_serie.must_be_nil
187
+ nf.rps_substituido_tipo.must_be_nil
188
+ nf.data_emissao_rps.must_equal Date.parse('2016-08-12Z')
189
+ nf.competencia.must_equal DateTime.parse('2016-08-12T00:00:00.000Z')
190
+ nf.natureza_operacao.must_equal '59'
191
+ nf.regime_especial_tributacao.must_equal '1'
192
+ nf.optante_simples_nacional.must_equal '1'
193
+ nf.incentivador_cultural.must_equal '0'
194
+ nf.outras_informacoes.must_be_nil
195
+ nf.item_lista_servico.must_equal '107'
196
+ nf.cnae_code.must_equal '6202300'
197
+ nf.description.must_equal '1 TESTE WEBSERVICE: R$ 5,00'
198
+ nf.codigo_municipio.must_equal '4204202'
199
+ nf.total_services.must_equal '1700'
200
+ nf.iss_retained.must_equal '2'
201
+ nf.total_iss.must_equal '33.72'
202
+ nf.base_calculation.must_equal '1685.88'
203
+ nf.iss_tax_rate.must_equal '0.02'
204
+ nf.valor_liquido.must_equal '1663.02'
205
+ nf.deductions.must_equal '7'
206
+ nf.valor_pis.must_equal '1.12'
207
+ nf.valor_cofins.must_equal '2.12'
208
+ nf.valor_inss.must_equal '3.12'
209
+ nf.valor_ir.must_equal '4.12'
210
+ nf.valor_csll.must_equal '5.12'
211
+ nf.outras_retencoes.must_equal '6.12'
212
+ nf.desconto_condicionado.must_equal '8.12'
213
+ nf.desconto_incondicionado.must_equal '7.12'
214
+ nf.responsavel_retencao.must_be_nil
215
+ nf.numero_processo.must_be_nil
216
+ nf.orgao_gerador_municipio.must_equal '4205902'
217
+ nf.orgao_gerador_uf.must_equal 'SC'
218
+ nf.cancelamento_codigo.must_be_nil
219
+ nf.cancelamento_numero_nf.must_be_nil
220
+ nf.cancelamento_cnpj.must_be_nil
221
+ nf.cancelamento_inscricao_municipal.must_be_nil
222
+ nf.cancelamento_municipio.must_be_nil
223
+ nf.cancelamento_data_hora.must_be_nil
224
+ nf.cancelamento_sucesso.must_equal false
225
+ nf.nfe_substituidora.must_be_nil
226
+
227
+ nf.emitente.cnpj.must_equal '65978078000120'
228
+ nf.emitente.inscricao_municipal.must_equal '11849'
229
+ nf.emitente.razao_social.must_equal 'EMPRESA EMITENTE LTDA'
230
+ nf.emitente.nome_fantasia.must_equal 'EMITENTE'
231
+ nf.emitente.telefone.must_equal '3326891'
232
+ nf.emitente.email.must_equal 'emitente@gmail.com'
233
+
234
+ nf.emitente.endereco.logradouro.must_equal 'DOUGLAS ALEXANDRE'
235
+ nf.emitente.endereco.numero.must_equal '50'
236
+ nf.emitente.endereco.complemento.must_equal ''
237
+ nf.emitente.endereco.bairro.must_equal 'CENTRO'
238
+ nf.emitente.endereco.codigo_municipio.must_equal '4205902'
239
+ nf.emitente.endereco.uf.must_equal 'SC'
240
+ nf.emitente.endereco.cep.must_equal '89110000'
241
+
242
+ nf.destinatario.cpf_cnpj.must_equal '08670364000'
243
+ nf.destinatario.inscricao_municipal.must_be_nil
244
+ nf.destinatario.inscricao_estadual.must_be_nil
245
+ nf.destinatario.inscricao_suframa.must_be_nil
246
+ nf.destinatario.razao_social.must_equal 'BRUNO MUCELINI MERGEN'
247
+ nf.destinatario.telefone.must_equal '4920493900'
248
+ nf.destinatario.email.must_equal 'brunomergen@gmail.com'
249
+
250
+ nf.destinatario.endereco.logradouro.must_equal 'RUA IGUACU E'
251
+ nf.destinatario.endereco.numero.must_equal '587'
252
+ nf.destinatario.endereco.complemento.must_equal ''
253
+ nf.destinatario.endereco.bairro.must_equal 'SAIC'
254
+ nf.destinatario.endereco.codigo_municipio.must_equal '4204202'
255
+ nf.destinatario.endereco.uf.must_equal 'SC'
256
+ nf.destinatario.endereco.cep.must_equal '89802171'
257
+ end
258
+ end
259
+
50
260
  end
@@ -14,10 +14,6 @@ describe BrNfe::Service::Thema::V1::ConsultaSituacaoLoteRps do
14
14
  it { subject.method_wsdl.must_equal :consultar_situacao_lote_rps }
15
15
  end
16
16
 
17
- it "#response_path_module" do
18
- subject.response_path_module.must_equal BrNfe::Service::Response::Paths::V1::ServicoConsultarSituacaoLoteRpsResposta
19
- end
20
-
21
17
  it "#response_root_path" do
22
18
  subject.response_root_path.must_equal []
23
19
  end
@@ -29,6 +25,27 @@ describe BrNfe::Service::Thema::V1::ConsultaSituacaoLoteRps do
29
25
  it "#soap_body_root_tag" do
30
26
  subject.soap_body_root_tag.must_equal 'consultarSituacaoLoteRps'
31
27
  end
28
+
29
+ describe "#wsdl" do
30
+ it "default" do
31
+ subject.ibge_code_of_issuer_city = '111'
32
+ subject.env = :production
33
+ subject.wsdl.must_equal 'http://nfsehml.gaspar.sc.gov.br/nfse/services/NFSEconsulta?wsdl'
34
+ subject.env = :test
35
+ subject.wsdl.must_equal 'http://nfsehml.gaspar.sc.gov.br/nfse/services/NFSEconsulta?wsdl'
36
+ end
37
+ describe 'Para a cidade 4205902 - Gaspar-SC' do
38
+ before { subject.ibge_code_of_issuer_city = '4205902' }
39
+ it "ambiente de produção" do
40
+ subject.env = :production
41
+ subject.wsdl.must_equal 'http://nfse.gaspar.sc.gov.br/nfse/services/NFSEconsulta?wsdl'
42
+ end
43
+ it "ambiente de testes" do
44
+ subject.env = :test
45
+ subject.wsdl.must_equal 'http://nfsehml.gaspar.sc.gov.br/nfse/services/NFSEconsulta?wsdl'
46
+ end
47
+ end
48
+ end
32
49
 
33
50
  describe "Validação do XML através do XSD" do
34
51
  let(:schemas_dir) { BrNfe.root+'/test/br_nfe/service/thema/v1/xsd' }
@@ -44,4 +61,80 @@ describe BrNfe::Service::Thema::V1::ConsultaSituacaoLoteRps do
44
61
  end
45
62
  end
46
63
  end
64
+
65
+ describe "#request and set response" do
66
+ before { savon.mock! }
67
+ after { savon.unmock! }
68
+
69
+ it "Quando processou o RPS com sucesso deve setar a situation com :success" do
70
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/success.xml')
71
+ savon.expects(:consultar_situacao_lote_rps).returns(fixture)
72
+ subject.request
73
+ response = subject.response
74
+
75
+ response.situation.must_equal :success, "#{response.inspect}"
76
+ response.numero_lote.must_equal '11'
77
+ response.status.must_equal :success
78
+ response.successful_request?.must_equal true
79
+ end
80
+
81
+ it "Quando processou o RPS com erros deve setar a situation com :error" do
82
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/error.xml')
83
+ savon.expects(:consultar_situacao_lote_rps).returns(fixture)
84
+ subject.request
85
+ response = subject.response
86
+
87
+ response.situation.must_equal :error
88
+ response.numero_lote.must_equal '11'
89
+ response.status.must_equal :success
90
+ response.successful_request?.must_equal true
91
+ end
92
+
93
+ it "Quando não processou o RPS deve setar a situation com :unprocessed" do
94
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/unprocessed.xml')
95
+ savon.expects(:consultar_situacao_lote_rps).returns(fixture)
96
+ subject.request
97
+ response = subject.response
98
+
99
+ response.situation.must_equal :unprocessed
100
+ response.numero_lote.must_equal '11'
101
+ response.status.must_equal :success
102
+ response.successful_request?.must_equal true
103
+ end
104
+
105
+ it "Quando não encontrar o RPS deve setar a situation com :unreceived" do
106
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/unreceived.xml')
107
+ savon.expects(:consultar_situacao_lote_rps).returns(fixture)
108
+ subject.request
109
+ response = subject.response
110
+
111
+ response.situation.must_equal :unreceived
112
+ response.numero_lote.must_equal '0'
113
+ response.status.must_equal :falied
114
+ response.successful_request?.must_equal true
115
+
116
+ response.error_messages.size.must_equal 1
117
+ response.error_messages[0][:code].must_equal 'E86'
118
+ response.error_messages[0][:message].must_equal 'Número do protocolo de recebimento do lote inexistente na base de dados'
119
+ response.error_messages[0][:solution].must_equal 'Confira se o lote foi enviado e informe o número correto do protocolo de recebimento.'
120
+ end
121
+
122
+ it "Quando a requisição voltar com erro deve setar os erros corretamente" do
123
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/consulta_situacao_lote_rps/fault.xml')
124
+
125
+ savon.expects(:consultar_situacao_lote_rps).returns(fixture)
126
+ subject.request
127
+ response = subject.response
128
+
129
+ response.protocolo.must_be_nil
130
+ response.data_recebimento.must_be_nil
131
+ response.numero_lote.must_be_nil
132
+ response.status.must_equal :falied
133
+ response.error_messages.size.must_equal 1
134
+ response.error_messages[0][:code].must_equal 'E515'
135
+ response.error_messages[0][:message].must_equal 'Erro ao validar assinatura. - Certificado usado para assinar a remessa não é do prestador e nem de empresa autorizada.'
136
+ response.error_messages[0][:solution].must_be_nil
137
+ response.successful_request?.must_equal true
138
+ end
139
+ end
47
140
  end
@@ -0,0 +1,109 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Service::Thema::V1::RecepcaoLoteRpsLimitado do
4
+ subject { FactoryGirl.build(:service_thema_v1_recepcao_lote_rps_limitado, emitente: emitente) }
5
+ let(:emitente) { FactoryGirl.build(:emitente, natureza_operacao: '50') }
6
+
7
+ describe "superclass" do
8
+ it { subject.class.superclass.must_equal BrNfe::Service::Thema::V1::RecepcaoLoteRps }
9
+ end
10
+
11
+ describe "#method_wsdl" do
12
+ it { subject.method_wsdl.must_equal :recepcionar_lote_rps_limitado }
13
+ end
14
+
15
+ it "#body_xml_path" do
16
+ subject.body_xml_path.must_equal [:recepcionar_lote_rps_limitado_response, :return]
17
+ end
18
+
19
+ it "#soap_body_root_tag" do
20
+ subject.soap_body_root_tag.must_equal 'recepcionarLoteRpsLimitado'
21
+ end
22
+
23
+ describe "#wsdl" do
24
+ it "default" do
25
+ subject.ibge_code_of_issuer_city = '111'
26
+ subject.env = :production
27
+ subject.wsdl.must_equal 'http://nfsehml.gaspar.sc.gov.br/nfse/services/NFSEremessa?wsdl'
28
+ subject.env = :test
29
+ subject.wsdl.must_equal 'http://nfsehml.gaspar.sc.gov.br/nfse/services/NFSEremessa?wsdl'
30
+ end
31
+ describe 'Para a cidade 4205902 - Gaspar-SC' do
32
+ before { subject.ibge_code_of_issuer_city = '4205902' }
33
+ it "ambiente de produção" do
34
+ subject.env = :production
35
+ subject.wsdl.must_equal 'http://nfse.gaspar.sc.gov.br/nfse/services/NFSEremessa?wsdl'
36
+ end
37
+ it "ambiente de testes" do
38
+ subject.env = :test
39
+ subject.wsdl.must_equal 'http://nfsehml.gaspar.sc.gov.br/nfse/services/NFSEremessa?wsdl'
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "Validação do XML através do XSD" do
45
+ let(:rps_basico) { FactoryGirl.build(:br_nfe_rps) }
46
+ let(:rps_completo) { FactoryGirl.build(:br_nfe_rps, :completo) }
47
+
48
+ let(:schemas_dir) { BrNfe.root+'/test/br_nfe/service/thema/v1/xsd' }
49
+
50
+ def validate_schema
51
+ subject.stubs(:certificate).returns(nil)
52
+ Dir.chdir(schemas_dir) do
53
+ schema = Nokogiri::XML::Schema(IO.read('nfse.xsd'))
54
+ document = Nokogiri::XML(subject.xml_builder)
55
+ errors = schema.validate(document)
56
+ errors.must_be_empty
57
+ end
58
+ end
59
+ it "Deve ser válido com 1 RPS com todas as informações preenchidas" do
60
+ subject.lote_rps = [rps_completo]
61
+ validate_schema
62
+ end
63
+ it "Deve ser válido com 1 RPS com apenas as informações obrigatórias preenchidas" do
64
+ subject.lote_rps = [rps_basico]
65
+ validate_schema
66
+ end
67
+ it "Deve ser válido com vários RPS's - 1 rps completo e 1 parcial" do
68
+ subject.lote_rps = [rps_completo, rps_basico]
69
+ validate_schema
70
+ end
71
+ end
72
+
73
+ describe "#request and set response" do
74
+ before { savon.mock! }
75
+ after { savon.unmock! }
76
+
77
+ it "Quando gravou o RPS com sucesso deve setar seus valores corretamente na resposta" do
78
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/recepcao_lote_rps_limitado/success.xml')
79
+
80
+ savon.expects(:recepcionar_lote_rps_limitado).returns(fixture)
81
+ subject.request
82
+ response = subject.response
83
+
84
+ response.status.must_equal :success
85
+ response.protocolo.must_equal '2916417'
86
+ response.data_recebimento.must_equal Time.parse('2016-08-15T17:21:35.725Z')
87
+ response.numero_lote.must_equal '14'
88
+ response.successful_request?.must_equal true
89
+ end
90
+
91
+ it "Quando a requisição voltar com erro deve setar os erros corretamente" do
92
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/thema/v1/recepcao_lote_rps_limitado/error.xml')
93
+
94
+ savon.expects(:recepcionar_lote_rps_limitado).returns(fixture)
95
+ subject.request
96
+ response = subject.response
97
+
98
+ response.protocolo.must_equal '2916418'
99
+ response.data_recebimento.must_equal Time.parse('2016-08-15T17:22:32.796Z')
100
+ response.numero_lote.must_equal '14'
101
+ response.status.must_equal :falied
102
+ response.error_messages.size.must_equal 1
103
+ response.error_messages[0][:code].must_equal 'E500'
104
+ response.error_messages[0][:message].must_equal 'E500-Número de Lote já informado em outras remessas'
105
+ response.error_messages[0][:solution].must_be_nil
106
+ response.successful_request?.must_equal true
107
+ end
108
+ end
109
+ end