br_nfe 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (495) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +12 -2
  5. data/README.markdown +3 -1
  6. data/Rakefile +20 -1
  7. data/lib/br_nfe/active_model/associations.rb +11 -0
  8. data/lib/br_nfe/active_model/has_many.rb +65 -0
  9. data/lib/br_nfe/active_model/has_one.rb +57 -0
  10. data/lib/br_nfe/active_model_base.rb +38 -1
  11. data/lib/br_nfe/base.rb +9 -0
  12. data/lib/br_nfe/calculos/fatores_de_multiplicacao.rb +67 -0
  13. data/lib/br_nfe/calculos/modulo11.rb +54 -0
  14. data/lib/br_nfe/calculos/modulo11_fator_de2a9.rb +83 -0
  15. data/lib/br_nfe/calculos/modulo11_fator_de2a9_resto_zero.rb +29 -0
  16. data/lib/br_nfe/constants.rb +46 -1
  17. data/lib/br_nfe/endereco.rb +6 -2
  18. data/lib/br_nfe/helper/cpf_cnpj.rb +8 -1
  19. data/lib/br_nfe/person.rb +32 -3
  20. data/lib/br_nfe/product/destinatario.rb +45 -0
  21. data/lib/br_nfe/product/emitente.rb +14 -1
  22. data/lib/br_nfe/product/evento/base.rb +146 -0
  23. data/lib/br_nfe/product/evento/cancelamento.rb +46 -0
  24. data/lib/br_nfe/product/gateway/base.rb +16 -43
  25. data/lib/br_nfe/product/gateway/web_service_am.rb +140 -0
  26. data/lib/br_nfe/product/gateway/web_service_ba.rb +140 -0
  27. data/lib/br_nfe/product/gateway/web_service_ce.rb +162 -0
  28. data/lib/br_nfe/product/gateway/web_service_go.rb +140 -0
  29. data/lib/br_nfe/product/gateway/web_service_mg.rb +140 -0
  30. data/lib/br_nfe/product/gateway/web_service_ms.rb +140 -0
  31. data/lib/br_nfe/product/gateway/web_service_mt.rb +140 -0
  32. data/lib/br_nfe/product/gateway/web_service_pe.rb +140 -0
  33. data/lib/br_nfe/product/gateway/web_service_pr.rb +140 -0
  34. data/lib/br_nfe/product/gateway/web_service_rs.rb +140 -0
  35. data/lib/br_nfe/product/gateway/web_service_sp.rb +140 -0
  36. data/lib/br_nfe/product/gateway/web_service_svan.rb +162 -0
  37. data/lib/br_nfe/product/gateway/web_service_svc_an.rb +131 -0
  38. data/lib/br_nfe/product/gateway/web_service_svc_rs.rb +20 -0
  39. data/lib/br_nfe/product/gateway/web_service_svrs.rb +111 -10
  40. data/lib/br_nfe/product/nf_xml_value.rb +278 -0
  41. data/lib/br_nfe/product/nfe/adicao_importacao.rb +76 -0
  42. data/lib/br_nfe/product/nfe/cobranca/duplicata.rb +44 -0
  43. data/lib/br_nfe/product/nfe/cobranca/fatura.rb +64 -0
  44. data/lib/br_nfe/product/nfe/cobranca/pagamento.rb +99 -0
  45. data/lib/br_nfe/product/nfe/declaracao_importacao.rb +221 -0
  46. data/lib/br_nfe/product/nfe/detalhe_exportacao.rb +89 -0
  47. data/lib/br_nfe/product/nfe/item.rb +678 -0
  48. data/lib/br_nfe/product/nfe/item_tax/cofins.rb +138 -0
  49. data/lib/br_nfe/product/nfe/item_tax/cofins_st.rb +68 -0
  50. data/lib/br_nfe/product/nfe/item_tax/icms.rb +593 -0
  51. data/lib/br_nfe/product/nfe/item_tax/icms_uf_destino.rb +169 -0
  52. data/lib/br_nfe/product/nfe/item_tax/importacao.rb +62 -0
  53. data/lib/br_nfe/product/nfe/item_tax/ipi.rb +179 -0
  54. data/lib/br_nfe/product/nfe/item_tax/issqn.rb +256 -0
  55. data/lib/br_nfe/product/nfe/item_tax/pis.rb +138 -0
  56. data/lib/br_nfe/product/nfe/item_tax/pis_st.rb +68 -0
  57. data/lib/br_nfe/product/nfe/processo_referencia.rb +48 -0
  58. data/lib/br_nfe/product/nfe/transporte/base.rb +264 -0
  59. data/lib/br_nfe/product/nfe/transporte/transportador.rb +15 -0
  60. data/lib/br_nfe/product/nfe/transporte/veiculo.rb +53 -0
  61. data/lib/br_nfe/product/nfe/transporte/volume.rb +89 -0
  62. data/lib/br_nfe/product/nota_fiscal.rb +1173 -0
  63. data/lib/br_nfe/product/operation/base.rb +255 -0
  64. data/lib/br_nfe/product/operation/nfe_autorizacao.rb +118 -0
  65. data/lib/br_nfe/product/operation/nfe_consulta_protocolo.rb +61 -0
  66. data/lib/br_nfe/product/operation/nfe_download_nf.rb +86 -0
  67. data/lib/br_nfe/product/operation/nfe_inutilizacao.rb +168 -0
  68. data/lib/br_nfe/product/operation/nfe_recepcao_evento.rb +70 -0
  69. data/lib/br_nfe/product/operation/nfe_ret_autorizacao.rb +63 -0
  70. data/lib/br_nfe/product/operation/nfe_status_servico.rb +46 -0
  71. data/lib/br_nfe/product/response/base.rb +97 -0
  72. data/lib/br_nfe/product/response/build/base.rb +287 -0
  73. data/lib/br_nfe/product/response/build/nfe_autorizacao.rb +102 -0
  74. data/lib/br_nfe/product/response/build/nfe_consulta_protocolo.rb +133 -0
  75. data/lib/br_nfe/product/response/build/nfe_inutilizacao.rb +53 -0
  76. data/lib/br_nfe/product/response/build/nfe_ret_autorizacao.rb +65 -0
  77. data/lib/br_nfe/product/response/build/nfe_status_servico.rb +43 -0
  78. data/lib/br_nfe/product/response/event.rb +89 -0
  79. data/lib/br_nfe/product/response/nfe_autorizacao.rb +12 -0
  80. data/lib/br_nfe/product/response/nfe_consulta_protocolo.rb +13 -0
  81. data/lib/br_nfe/product/response/nfe_inutilizacao.rb +89 -0
  82. data/lib/br_nfe/product/response/nfe_ret_autorizacao.rb +9 -0
  83. data/lib/br_nfe/product/response/nfe_status_servico.rb +31 -0
  84. data/lib/br_nfe/product/xml/_signed_info_sh1.xml.slim +9 -0
  85. data/lib/br_nfe/product/xml/_tc_cpf_cnpj.xml.slim +7 -0
  86. data/lib/br_nfe/product/xml/signature_sh1.xml.slim +12 -0
  87. data/lib/br_nfe/product/xml/v1_00/evento/infEventoCancelamento.xml.slim +19 -0
  88. data/lib/br_nfe/product/xml/v1_00/root/NfeDownloadNf.xml.slim +5 -0
  89. data/lib/br_nfe/product/xml/v1_00/root/NfeRecepcaoEvento.xml.slim +7 -0
  90. data/lib/br_nfe/product/xml/v2_00/_tc_endereco.xml.slim +19 -0
  91. data/lib/br_nfe/product/xml/v2_00/_tc_infNFe.xml.slim +39 -0
  92. data/lib/br_nfe/product/xml/v2_00/infInut.xml.slim +12 -0
  93. data/lib/br_nfe/product/xml/v2_00/infNFe/NFe.xml.slim +4 -0
  94. data/lib/br_nfe/product/xml/v2_00/infNFe/_tc_cobr.xml.slim +19 -0
  95. data/lib/br_nfe/product/xml/v2_00/infNFe/_tc_dest.xml.slim +14 -0
  96. data/lib/br_nfe/product/xml/v2_00/infNFe/_tc_det.xml.slim +7 -0
  97. data/lib/br_nfe/product/xml/v2_00/infNFe/_tc_emit.xml.slim +19 -0
  98. data/lib/br_nfe/product/xml/v2_00/infNFe/_tc_entrega.xml.slim +11 -0
  99. data/lib/br_nfe/product/xml/v2_00/infNFe/_tc_exporta.xml.slim +2 -0
  100. data/lib/br_nfe/product/xml/v2_00/infNFe/_tc_ide.xml.slim +24 -0
  101. data/lib/br_nfe/product/xml/v2_00/infNFe/_tc_infAdic.xml.slim +13 -0
  102. data/lib/br_nfe/product/xml/v2_00/infNFe/_tc_retirada.xml.slim +11 -0
  103. data/lib/br_nfe/product/xml/v2_00/infNFe/_tc_total.xml.slim +50 -0
  104. data/lib/br_nfe/product/xml/v2_00/infNFe/_tc_transp.xml.slim +35 -0
  105. data/lib/br_nfe/product/xml/v2_00/infNFe/det/_tc_imposto.xml.slim +31 -0
  106. data/lib/br_nfe/product/xml/v2_00/infNFe/det/_tc_prod.xml.slim +37 -0
  107. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS00.xml.slim +6 -0
  108. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS10.xml.slim +16 -0
  109. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS101.xml.slim +4 -0
  110. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS102.xml.slim +3 -0
  111. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS20.xml.slim +6 -0
  112. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS201.xml.slim +15 -0
  113. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS202.xml.slim +14 -0
  114. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS30.xml.slim +12 -0
  115. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS40.xml.slim +7 -0
  116. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS500.xml.slim +6 -0
  117. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS51.xml.slim +13 -0
  118. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS60.xml.slim +5 -0
  119. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS70.xml.slim +18 -0
  120. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS90.xml.slim +21 -0
  121. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/ICMS/_tc_ICMS900.xml.slim +25 -0
  122. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/_tc_COFINS.xml.slim +26 -0
  123. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/_tc_COFINS_ST.xml.slim +7 -0
  124. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/_tc_ICMS.xml.slim +45 -0
  125. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/_tc_II.xml.slim +4 -0
  126. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/_tc_IPI.xml.slim +30 -0
  127. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/_tc_PIS.xml.slim +26 -0
  128. data/lib/br_nfe/product/xml/v2_00/infNFe/det/imposto/_tc_PIS_ST.xml.slim +7 -0
  129. data/lib/br_nfe/product/xml/v2_00/infNFe/det/prod/_tc_di.xml.slim +13 -0
  130. data/lib/br_nfe/product/xml/v2_00/infNFe/transp/_tc_retTransp.xml.slim +6 -0
  131. data/lib/br_nfe/product/xml/v2_00/infNFe/transp/_tc_transporta.xml.slim +17 -0
  132. data/lib/br_nfe/product/xml/v2_00/infNFe/transp/_tc_vol.xml.slim +15 -0
  133. data/lib/br_nfe/product/xml/v2_00/infNFe.xml.slim +3 -0
  134. data/lib/br_nfe/product/xml/v2_00/root/NfeAutorizacao.xml.slim +5 -0
  135. data/lib/br_nfe/product/xml/v2_00/root/NfeInutilizacao.xml.slim +4 -0
  136. data/lib/br_nfe/product/xml/v2_00/root/NfeRetAutorizacao.xml.slim +3 -0
  137. data/lib/br_nfe/product/xml/v2_00/root/NfeStatusServico.xml.slim +4 -0
  138. data/lib/br_nfe/product/xml/v2_01/root/NfeConsultaProtocolo.xml.slim +4 -0
  139. data/lib/br_nfe/product/xml/v3_10/_tc_infNFe.xml.slim +44 -0
  140. data/lib/br_nfe/product/xml/v3_10/infNFe/_tc_dest.xml.slim +25 -0
  141. data/lib/br_nfe/product/xml/v3_10/infNFe/_tc_det.xml.slim +14 -0
  142. data/lib/br_nfe/product/xml/v3_10/infNFe/_tc_exporta.xml.slim +4 -0
  143. data/lib/br_nfe/product/xml/v3_10/infNFe/_tc_ide.xml.slim +26 -0
  144. data/lib/br_nfe/product/xml/v3_10/infNFe/_tc_pag.xml.slim +7 -0
  145. data/lib/br_nfe/product/xml/v3_10/infNFe/_tc_total.xml.slim +78 -0
  146. data/lib/br_nfe/product/xml/v3_10/infNFe/det/_tc_imposto.xml.slim +37 -0
  147. data/lib/br_nfe/product/xml/v3_10/infNFe/det/_tc_prod.xml.slim +48 -0
  148. data/lib/br_nfe/product/xml/v3_10/infNFe/det/imposto/ICMS/_tc_ICMS20.xml.slim +12 -0
  149. data/lib/br_nfe/product/xml/v3_10/infNFe/det/imposto/ICMS/_tc_ICMS30.xml.slim +17 -0
  150. data/lib/br_nfe/product/xml/v3_10/infNFe/det/imposto/ICMS/_tc_ICMS40.xml.slim +7 -0
  151. data/lib/br_nfe/product/xml/v3_10/infNFe/det/imposto/ICMS/_tc_ICMS51.xml.slim +19 -0
  152. data/lib/br_nfe/product/xml/v3_10/infNFe/det/imposto/ICMS/_tc_ICMS70.xml.slim +23 -0
  153. data/lib/br_nfe/product/xml/v3_10/infNFe/det/imposto/ICMS/_tc_ICMS90.xml.slim +26 -0
  154. data/lib/br_nfe/product/xml/v3_10/infNFe/det/imposto/_tc_ICMSUFDest.xml.slim +8 -0
  155. data/lib/br_nfe/product/xml/v3_10/infNFe/det/imposto/_tc_ISSQN.xml.slim +35 -0
  156. data/lib/br_nfe/product/xml/v3_10/infNFe/det/prod/_tc_det_export.xml.slim +8 -0
  157. data/lib/br_nfe/product/xml/v3_10/infNFe/det/prod/_tc_di.xml.slim +28 -0
  158. data/lib/br_nfe/product/xml/v3_10/root/NfeAutorizacao.xml.slim +6 -0
  159. data/lib/br_nfe/service/base.rb +1 -105
  160. data/lib/br_nfe/service/betha/v1/cancela_nfse.rb +1 -1
  161. data/lib/br_nfe/service/response/default.rb +1 -1
  162. data/lib/br_nfe/service/simpliss/v1/base.rb +2 -0
  163. data/lib/br_nfe/version.rb +2 -2
  164. data/lib/br_nfe.rb +180 -22
  165. data/lib/config/locales/br_nfe/en/product/nfe/cobranca/fatura.yml +6 -0
  166. data/lib/config/locales/br_nfe/en/product/nfe/declaracao_importacao.yml +10 -0
  167. data/lib/config/locales/br_nfe/en/product/nfe/item.yml +20 -0
  168. data/lib/config/locales/br_nfe/en/product/nfe/item_tax/icms_uf_destino.yml +8 -0
  169. data/lib/config/locales/br_nfe/en/product/nfe/transporte/base.yml +9 -0
  170. data/lib/config/locales/br_nfe/en/product/nota_fiscal.yml +21 -0
  171. data/lib/config/locales/br_nfe/en/product/operation/nfe_autorizacao.yml +10 -0
  172. data/lib/config/locales/br_nfe/en/product/operation/nfe_recepcao_evento.yml +6 -0
  173. data/lib/config/locales/br_nfe/pt-BR/product/nfe/cobranca/fatura.yml +6 -0
  174. data/lib/config/locales/br_nfe/pt-BR/product/nfe/declaracao_importacao.yml +10 -0
  175. data/lib/config/locales/br_nfe/pt-BR/product/nfe/item.yml +20 -0
  176. data/lib/config/locales/br_nfe/pt-BR/product/nfe/item_tax/icms_uf_destino.yml +8 -0
  177. data/lib/config/locales/br_nfe/pt-BR/product/nfe/transporte/base.yml +9 -0
  178. data/lib/config/locales/br_nfe/pt-BR/product/nota_fiscal.yml +21 -0
  179. data/lib/config/locales/br_nfe/pt-BR/product/operation/nfe_autorizacao.yml +10 -0
  180. data/lib/config/locales/br_nfe/pt-BR/product/operation/nfe_recepcao_evento.yml +6 -0
  181. data/test/br_nfe/association/have_destinatario_test.rb +8 -8
  182. data/test/br_nfe/association/have_emitente_test.rb +6 -6
  183. data/test/br_nfe/base_test.rb +15 -4
  184. data/test/br_nfe/endereco_test.rb +15 -0
  185. data/test/br_nfe/person_test.rb +55 -6
  186. data/test/br_nfe/product/destinatario_test.rb +26 -0
  187. data/test/br_nfe/product/emitente_test.rb +1 -2
  188. data/test/br_nfe/product/evento/base_test.rb +58 -0
  189. data/test/br_nfe/product/evento/cancelamento_test.rb +32 -0
  190. data/test/br_nfe/product/gateway/web_service_am_test.rb +242 -0
  191. data/test/br_nfe/product/gateway/web_service_ba_test.rb +242 -0
  192. data/test/br_nfe/product/gateway/web_service_ce_test.rb +242 -0
  193. data/test/br_nfe/product/gateway/web_service_go_test.rb +242 -0
  194. data/test/br_nfe/product/gateway/web_service_mg_test.rb +242 -0
  195. data/test/br_nfe/product/gateway/web_service_ms_test.rb +242 -0
  196. data/test/br_nfe/product/gateway/web_service_mt_test.rb +408 -0
  197. data/test/br_nfe/product/gateway/web_service_pe_test.rb +408 -0
  198. data/test/br_nfe/product/gateway/web_service_pr_test.rb +408 -0
  199. data/test/br_nfe/product/gateway/web_service_rs_test.rb +407 -0
  200. data/test/br_nfe/product/gateway/web_service_sp_test.rb +408 -0
  201. data/test/br_nfe/product/gateway/web_service_svan_test.rb +242 -0
  202. data/test/br_nfe/product/gateway/web_service_svc_an_test.rb +185 -0
  203. data/test/br_nfe/product/gateway/web_service_svc_rs_test.rb +185 -0
  204. data/test/br_nfe/product/gateway/web_service_svrs_test.rb +208 -2
  205. data/test/br_nfe/product/nfe/adicao_importacao_test.rb +19 -0
  206. data/test/br_nfe/product/nfe/cobranca/duplicata_test.rb +19 -0
  207. data/test/br_nfe/product/nfe/cobranca/fatura_test.rb +32 -0
  208. data/test/br_nfe/product/nfe/cobranca/pagamento_test.rb +105 -0
  209. data/test/br_nfe/product/nfe/declaracao_importacao_test.rb +116 -0
  210. data/test/br_nfe/product/nfe/detalhe_exportacao_test.rb +97 -0
  211. data/test/br_nfe/product/nfe/item_tax/cofins_st_test.rb +22 -0
  212. data/test/br_nfe/product/nfe/item_tax/cofins_test.rb +113 -0
  213. data/test/br_nfe/product/nfe/item_tax/icms_test.rb +1011 -0
  214. data/test/br_nfe/product/nfe/item_tax/icms_uf_destino_test.rb +99 -0
  215. data/test/br_nfe/product/nfe/item_tax/importacao_test.rb +23 -0
  216. data/test/br_nfe/product/nfe/item_tax/ipi_test.rb +160 -0
  217. data/test/br_nfe/product/nfe/item_tax/issqn_test.rb +84 -0
  218. data/test/br_nfe/product/nfe/item_tax/pis_st_test.rb +22 -0
  219. data/test/br_nfe/product/nfe/item_tax/pis_test.rb +113 -0
  220. data/test/br_nfe/product/nfe/item_test.rb +381 -0
  221. data/test/br_nfe/product/nfe/processo_referencia_test.rb +30 -0
  222. data/test/br_nfe/product/nfe/transporte/base_test.rb +182 -0
  223. data/test/br_nfe/product/nfe/transporte/transportador_test.rb +13 -0
  224. data/test/br_nfe/product/nfe/transporte/veiculo_test.rb +13 -0
  225. data/test/br_nfe/product/nfe/transporte/volume_test.rb +42 -0
  226. data/test/br_nfe/product/nota_fiscal_test.rb +662 -0
  227. data/test/br_nfe/product/operation/base_test.rb +538 -0
  228. data/test/br_nfe/product/operation/nfe_autorizacao_test.rb +378 -0
  229. data/test/br_nfe/product/operation/nfe_consulta_protocolo_test.rb +349 -0
  230. data/test/br_nfe/product/operation/nfe_download_nf_test.rb +93 -0
  231. data/test/br_nfe/product/operation/nfe_inutilizacao_test.rb +210 -0
  232. data/test/br_nfe/product/operation/nfe_recepcao_evento_test.rb +84 -0
  233. data/test/br_nfe/product/operation/nfe_ret_autorizacao_test.rb +309 -0
  234. data/test/br_nfe/product/operation/nfe_status_servico_test.rb +122 -0
  235. data/test/br_nfe/product/response/base_test.rb +75 -0
  236. data/test/br_nfe/product/response/build/base_test.rb +34 -0
  237. data/test/br_nfe/product/response/nfe_ret_autorizacao_test.rb +14 -0
  238. data/test/br_nfe/service/association/have_intermediario_test.rb +10 -10
  239. data/test/br_nfe/service/base_test.rb +9 -206
  240. data/test/br_nfe/service/betha/v1/cancela_nfse_test.rb +8 -6
  241. data/test/br_nfe/service/betha/v1/consulta_lote_rps_test.rb +6 -3
  242. data/test/br_nfe/service/betha/v1/consulta_nfs_por_rps_test.rb +6 -3
  243. data/test/br_nfe/service/betha/v1/consulta_nfse_test.rb +7 -4
  244. data/test/br_nfe/service/betha/v1/consulta_situacao_lote_rps_test.rb +12 -9
  245. data/test/br_nfe/service/betha/v1/recepcao_lote_rps_test.rb +6 -3
  246. data/test/br_nfe/service/rps_test.rb +2 -2
  247. data/test/br_nfe/service/simpliss/v1/cancela_nfse_test.rb +6 -3
  248. data/test/br_nfe/service/simpliss/v1/consulta_lote_rps_test.rb +7 -4
  249. data/test/br_nfe/service/simpliss/v1/consulta_nfs_por_rps_test.rb +7 -4
  250. data/test/br_nfe/service/simpliss/v1/consulta_nfse_test.rb +8 -5
  251. data/test/br_nfe/service/simpliss/v1/consulta_situacao_lote_rps_test.rb +9 -6
  252. data/test/br_nfe/service/simpliss/v1/recepcao_lote_rps_test.rb +6 -3
  253. data/test/br_nfe/service/thema/v1/cancela_nfse_test.rb +6 -3
  254. data/test/br_nfe/service/thema/v1/consulta_lote_rps_test.rb +6 -3
  255. data/test/br_nfe/service/thema/v1/consulta_nfs_por_rps_test.rb +6 -3
  256. data/test/br_nfe/service/thema/v1/consulta_nfse_test.rb +8 -5
  257. data/test/br_nfe/service/thema/v1/consulta_situacao_lote_rps_test.rb +9 -6
  258. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_limitado_test.rb +6 -3
  259. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_test.rb +6 -3
  260. data/test/factories/person.rb +1 -1
  261. data/test/factories/product/destinatario.rb +11 -0
  262. data/test/factories/product/emitente.rb +1 -1
  263. data/test/factories/product/evento/base.rb +9 -0
  264. data/test/factories/product/evento/cancelamento.rb +10 -0
  265. data/test/factories/product/gateway/web_service_am.rb +5 -0
  266. data/test/factories/product/gateway/web_service_ba.rb +5 -0
  267. data/test/factories/product/nfe/adicao_importacao.rb +7 -0
  268. data/test/factories/product/nfe/cobranca/duplicata.rb +7 -0
  269. data/test/factories/product/nfe/cobranca/fatura.rb +8 -0
  270. data/test/factories/product/nfe/cobranca/pagamento.rb +9 -0
  271. data/test/factories/product/nfe/declaracao_importacao.rb +10 -0
  272. data/test/factories/product/nfe/detalhe_exportacao.rb +5 -0
  273. data/test/factories/product/nfe/item.rb +24 -0
  274. data/test/factories/product/nfe/item_tax/cofins.rb +5 -0
  275. data/test/factories/product/nfe/item_tax/cofins_st.rb +5 -0
  276. data/test/factories/product/nfe/item_tax/icms.rb +9 -0
  277. data/test/factories/product/nfe/item_tax/icms_uf_destino.rb +11 -0
  278. data/test/factories/product/nfe/item_tax/importacao.rb +8 -0
  279. data/test/factories/product/nfe/item_tax/ipi.rb +6 -0
  280. data/test/factories/product/nfe/item_tax/issqn.rb +9 -0
  281. data/test/factories/product/nfe/item_tax/pis.rb +5 -0
  282. data/test/factories/product/nfe/item_tax/pis_st.rb +5 -0
  283. data/test/factories/product/nfe/processo_referencia.rb +6 -0
  284. data/test/factories/product/nfe/transporte/base.rb +5 -0
  285. data/test/factories/product/nfe/transporte/transportador.rb +7 -0
  286. data/test/factories/product/nfe/transporte/veiculo.rb +7 -0
  287. data/test/factories/product/nfe/transporte/volume.rb +5 -0
  288. data/test/factories/product/nota_fiscal.rb +22 -0
  289. data/test/factories/product/{base.rb → operation/base.rb} +1 -1
  290. data/test/factories/product/operation/nfe_autorizacao.rb +590 -0
  291. data/test/factories/product/operation/nfe_consulta_protocolo.rb +13 -0
  292. data/test/factories/product/operation/nfe_download_nf.rb +15 -0
  293. data/test/factories/product/operation/nfe_inutilizacao.rb +19 -0
  294. data/test/factories/product/operation/nfe_recepcao_evento.rb +14 -0
  295. data/test/factories/product/operation/nfe_ret_autorizacao.rb +13 -0
  296. data/test/factories/product/{consulta_status_servico.rb → operation/nfe_status_servico.rb} +1 -1
  297. data/test/factories/product/response/base.rb +12 -0
  298. data/test/factories/product/response/build/base.rb +6 -0
  299. data/test/factories/product/response/nfe_ret_autorizacao.rb +13 -0
  300. data/test/factories/service/emitente.rb +1 -1
  301. data/test/fixtures/product/operation/nfe_autorizacao/nfe_signed.xml +1 -0
  302. data/test/fixtures/product/response/v3.10/nfe_autorizacao/async_fail.xml +21 -0
  303. data/test/fixtures/product/response/v3.10/nfe_autorizacao/async_success.xml +25 -0
  304. data/test/fixtures/product/response/v3.10/nfe_autorizacao/nfe/with_proc.xml +1 -0
  305. data/test/fixtures/product/response/v3.10/nfe_autorizacao/nfe/without_proc.xml +1 -0
  306. data/test/fixtures/product/response/v3.10/nfe_autorizacao/original_xml.xml +1 -0
  307. data/test/fixtures/product/response/v3.10/nfe_autorizacao/sync_fail.xml +32 -0
  308. data/test/fixtures/product/response/v3.10/nfe_autorizacao/sync_success.xml +33 -0
  309. data/test/fixtures/product/response/v3.10/nfe_consulta_protocolo/event_xml/event_1.xml +1 -0
  310. data/test/fixtures/product/response/v3.10/nfe_consulta_protocolo/event_xml/event_2.xml +1 -0
  311. data/test/fixtures/product/response/v3.10/nfe_consulta_protocolo/event_xml/event_3.xml +1 -0
  312. data/test/fixtures/product/response/v3.10/nfe_consulta_protocolo/event_xml/event_cancel.xml +1 -0
  313. data/test/fixtures/product/response/v3.10/nfe_consulta_protocolo/event_xml/one_event.xml +1 -0
  314. data/test/fixtures/product/response/v3.10/nfe_consulta_protocolo/fail.xml +22 -0
  315. data/test/fixtures/product/response/v3.10/nfe_consulta_protocolo/nfe_original/with_proc.xml +1 -0
  316. data/test/fixtures/product/response/v3.10/nfe_consulta_protocolo/nfe_original/without_proc.xml +1 -0
  317. data/test/fixtures/product/response/v3.10/nfe_consulta_protocolo/success_many_with_cancel.xml +198 -0
  318. data/test/fixtures/product/response/v3.10/nfe_consulta_protocolo/success_many_without_cancel.xml +199 -0
  319. data/test/fixtures/product/response/v3.10/nfe_consulta_protocolo/success_one.xml +89 -0
  320. data/test/fixtures/product/response/v3.10/nfe_consulta_protocolo/success_without.xml +34 -0
  321. data/test/fixtures/product/response/v3.10/nfe_inutilizacao/fail.xml +29 -0
  322. data/test/fixtures/product/response/v3.10/nfe_inutilizacao/success.xml +30 -0
  323. data/test/fixtures/product/response/v3.10/nfe_recepcao_evento/cancelamento/fail.xml +34 -0
  324. data/test/fixtures/product/response/v3.10/nfe_recepcao_evento/cancelamento/success.xml +36 -0
  325. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/lot_fail.xml +22 -0
  326. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/lot_ok_one_invoice_fail.xml +33 -0
  327. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/lot_ok_one_invoice_fail_and_one_ok.xml +46 -0
  328. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/lot_ok_one_invoice_ok.xml +34 -0
  329. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/lot_ok_two_invoice_fail.xml +46 -0
  330. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/lot_ok_two_invoice_ok.xml +46 -0
  331. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/nfe/nf_2_with_protocol.xml +1 -0
  332. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/nfe/nf_2_without_protocol.xml +1 -0
  333. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/nfe/nf_3_with_protocol.xml +1 -0
  334. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/nfe/nf_3_without_protocol.xml +1 -0
  335. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/original_xml/lot.xml +2 -0
  336. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/original_xml/nfe.xml +2 -0
  337. data/test/fixtures/product/response/v3.10/nfe_ret_autorizacao/original_xml/nfeProc.xml +4 -0
  338. data/test/fixtures/product/response/v3.10/nfe_status_servico/fail.xml +23 -0
  339. data/test/fixtures/product/response/v3.10/nfe_status_servico/success.xml +22 -0
  340. data/test/fixtures/product/schemas/CCe_v1.00.xsd +11 -0
  341. data/test/fixtures/product/schemas/EPEC_v1.00.xsd +9 -0
  342. data/test/fixtures/product/schemas/LeiauteCadastroEmissorDFe_v1.01.xsd +234 -0
  343. data/test/fixtures/product/schemas/SuframaInternaliza_v1.00.xsd +9 -0
  344. data/test/fixtures/product/schemas/SuframaVistoria_v1.00.xsd +9 -0
  345. data/test/fixtures/product/schemas/atuCadEmiDFe_v1.01.xsd +9 -0
  346. data/test/fixtures/product/schemas/cabecMsg_v1.02.xsd +29 -0
  347. data/test/fixtures/product/schemas/cadEmiDFe_v1.01.xsd +9 -0
  348. data/test/fixtures/product/schemas/cancNFe_v2.00.xsd +9 -0
  349. data/test/fixtures/product/schemas/confRecebto_v1.00.xsd +9 -0
  350. data/test/fixtures/product/schemas/consCad_v2.00.xsd +9 -0
  351. data/test/fixtures/product/schemas/consDPEC_v1.01.xsd +9 -0
  352. data/test/fixtures/product/schemas/consNFeDest_v1.01.xsd +10 -0
  353. data/test/fixtures/product/schemas/consReciNFe_v2.00.xsd +9 -0
  354. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/consReciNFe_v3.10.xsd +8 -8
  355. data/test/fixtures/product/schemas/consSitNFe_v2.01.xsd +10 -0
  356. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/consSitNFe_v3.10.xsd +8 -8
  357. data/test/fixtures/product/schemas/consStatServ_v2.00.xsd +9 -0
  358. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/consStatServ_v3.10.xsd +8 -8
  359. data/test/fixtures/product/schemas/distDFeInt_v1.00.xsd +71 -0
  360. data/test/fixtures/product/schemas/downloadNFe_v1.00.xsd +10 -0
  361. data/test/fixtures/product/schemas/e110110_v1.00.xsd +58 -0
  362. data/test/fixtures/product/schemas/e110111_v1.00.xsd +42 -0
  363. data/test/fixtures/product/schemas/e110140_v1.00.xsd +124 -0
  364. data/test/fixtures/product/schemas/e111500_v1.00.xsd +69 -0
  365. data/test/fixtures/product/schemas/e111501_v1.00.xsd +69 -0
  366. data/test/fixtures/product/schemas/e111502_v1.00.xsd +50 -0
  367. data/test/fixtures/product/schemas/e111503_v1.00.xsd +50 -0
  368. data/test/fixtures/product/schemas/e210200_v1.00.xsd +32 -0
  369. data/test/fixtures/product/schemas/e210210_v1.00.xsd +32 -0
  370. data/test/fixtures/product/schemas/e210220_v1.00.xsd +45 -0
  371. data/test/fixtures/product/schemas/e210240_v1.00.xsd +44 -0
  372. data/test/fixtures/product/schemas/e411500_v1.00.xsd +134 -0
  373. data/test/fixtures/product/schemas/e411501_v1.00.xsd +134 -0
  374. data/test/fixtures/product/schemas/e411502_v1.00.xsd +95 -0
  375. data/test/fixtures/product/schemas/e411503_v1.00.xsd +95 -0
  376. data/test/fixtures/product/schemas/e990900_v1.00.xsd +87 -0
  377. data/test/fixtures/product/schemas/e990910_v1.00.xsd +81 -0
  378. data/test/fixtures/product/schemas/envCCe_v1.00.xsd +10 -0
  379. data/test/fixtures/product/schemas/envCancelPProrrogNFe_v1.0.xsd +50 -0
  380. data/test/fixtures/product/schemas/envConfRecebto_v1.00.xsd +9 -0
  381. data/test/fixtures/product/schemas/envDPEC_v1.01.xsd +9 -0
  382. data/test/fixtures/product/schemas/envEPEC_v1.00.xsd +9 -0
  383. data/test/fixtures/product/schemas/envEventoCancNFe_v1.00.xsd +9 -0
  384. data/test/fixtures/product/schemas/envEvento_v1.00.xsd +9 -0
  385. data/test/fixtures/product/schemas/envFiscoNfe_v1.0.xsd +179 -0
  386. data/test/fixtures/product/schemas/envPProrrogNFe_v1.0.xsd +65 -0
  387. data/test/fixtures/product/schemas/envRemIndus_v1.00.xsd +9 -0
  388. data/test/fixtures/product/schemas/envSuframaInternaliza_v1.00.xsd +10 -0
  389. data/test/fixtures/product/schemas/envSuframaVistoria_v1.00.xsd +10 -0
  390. data/test/fixtures/product/schemas/enviNFe_v2.00.xsd +9 -0
  391. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/enviNFe_v3.10.xsd +8 -8
  392. data/test/fixtures/product/schemas/eventoCancNFe_v1.00.xsd +9 -0
  393. data/test/fixtures/product/schemas/eventoEPEC_v0.01.xsd +267 -0
  394. data/test/fixtures/product/schemas/eventoEPEC_v1.00.xsd +267 -0
  395. data/test/fixtures/product/schemas/eventoRemIndus_v1.00.xsd +9 -0
  396. data/test/fixtures/product/schemas/inutNFe_v2.00.xsd +9 -0
  397. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/inutNFe_v3.10.xsd +8 -8
  398. data/test/fixtures/product/schemas/leiauteCCe_v1.00.xsd +418 -0
  399. data/test/fixtures/product/schemas/leiauteCancNFe_v2.00.xsd +143 -0
  400. data/test/fixtures/product/schemas/leiauteConfRecebto_v1.00.xsd +406 -0
  401. data/test/fixtures/product/schemas/leiauteConsNFeDest_v1.01.xsd +483 -0
  402. data/test/fixtures/product/schemas/leiauteConsSitNFe_v2.01.xsd +548 -0
  403. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/leiauteConsSitNFe_v3.10.xsd +502 -502
  404. data/test/fixtures/product/schemas/leiauteConsStatServ_v2.00.xsd +98 -0
  405. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/leiauteConsStatServ_v3.10.xsd +97 -97
  406. data/test/fixtures/product/schemas/leiauteConsultaCadastro_v1.01.xsd +355 -0
  407. data/test/fixtures/product/schemas/leiauteConsultaCadastro_v2.00.xsd +404 -0
  408. data/test/fixtures/product/schemas/leiauteDPEC_v1.01.xsd +464 -0
  409. data/test/fixtures/product/schemas/leiauteDownloadNFe_v1.00.xsd +149 -0
  410. data/test/fixtures/product/schemas/leiauteEPEC_v1.00.xsd +459 -0
  411. data/test/fixtures/product/schemas/leiauteEventoCancNFe_v1.00.xsd +394 -0
  412. data/test/fixtures/product/schemas/leiauteEvento_v1.00.xsd +373 -0
  413. data/test/fixtures/product/schemas/leiauteInutNFe_v2.00.xsd +193 -0
  414. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/leiauteInutNFe_v3.10.xsd +192 -192
  415. data/test/fixtures/product/schemas/leiauteNFe_v2.00.xsd +6661 -0
  416. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/leiauteNFe_v3.10.xsd +6060 -6060
  417. data/test/fixtures/product/schemas/leiauteRemIndus_v1.00.xsd +382 -0
  418. data/test/fixtures/product/schemas/leiauteSRE_v1.00.xsd +372 -0
  419. data/test/fixtures/product/schemas/leiauteSuframaInternaliza_v1.00.xsd +642 -0
  420. data/test/fixtures/product/schemas/leiauteSuframaVistoria_v1.00.xsd +648 -0
  421. data/test/fixtures/product/schemas/nfe_v2.00.xsd +9 -0
  422. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/nfe_v3.10.xsd +8 -8
  423. data/test/fixtures/product/schemas/procCCeNFe_v1.00.xsd +10 -0
  424. data/test/fixtures/product/schemas/procCancNFe_v2.00.xsd +9 -0
  425. data/test/fixtures/product/schemas/procConfRecebtoNFe_v1.00.xsd +9 -0
  426. data/test/fixtures/product/schemas/procEPEC_v1.00.xsd +9 -0
  427. data/test/fixtures/product/schemas/procEventoCancNFe_v1.00.xsd +9 -0
  428. data/test/fixtures/product/schemas/procEventoNFe_v1.00.xsd +9 -0
  429. data/test/fixtures/product/schemas/procEventoNFe_v99.99.xsd +37 -0
  430. data/test/fixtures/product/schemas/procInutNFe_v2.00.xsd +9 -0
  431. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/procInutNFe_v3.10.xsd +8 -8
  432. data/test/fixtures/product/schemas/procNFe_v2.00.xsd +9 -0
  433. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/procNFe_v3.10.xsd +8 -8
  434. data/test/fixtures/product/schemas/procRemIndus_v1.00.xsd +9 -0
  435. data/test/fixtures/product/schemas/resEvento_v1.00.xsd +94 -0
  436. data/test/fixtures/product/schemas/resNFe_v1.00.xsd +110 -0
  437. data/test/fixtures/product/schemas/retAtuCadEmiDFe_v1.01.xsd +9 -0
  438. data/test/fixtures/product/schemas/retCancNFe_v2.00.xsd +9 -0
  439. data/test/fixtures/product/schemas/retConsCad_v2.00.xsd +9 -0
  440. data/test/fixtures/product/schemas/retConsDPEC_v1.01.xsd +9 -0
  441. data/test/fixtures/product/schemas/retConsReciNFe_v2.00.xsd +9 -0
  442. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/retConsReciNFe_v3.10.xsd +8 -8
  443. data/test/fixtures/product/schemas/retConsSitNFe_v2.01.xsd +10 -0
  444. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/retConsSitNFe_v3.10.xsd +8 -8
  445. data/test/fixtures/product/schemas/retConsStatServ_v2.00.xsd +9 -0
  446. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/retConsStatServ_v3.10.xsd +8 -8
  447. data/test/fixtures/product/schemas/retDPEC_v1.01.xsd +9 -0
  448. data/test/fixtures/product/schemas/retDistDFeInt_v1.00.xsd +84 -0
  449. data/test/fixtures/product/schemas/retDownloadNFe_v1.00.xsd +9 -0
  450. data/test/fixtures/product/schemas/retEnvCCe_v1.00.xsd +10 -0
  451. data/test/fixtures/product/schemas/retEnvCancelPProrrogNFe_v1.0.xsd +231 -0
  452. data/test/fixtures/product/schemas/retEnvConfRecebto_v1.00.xsd +9 -0
  453. data/test/fixtures/product/schemas/retEnvEPEC_v1.00.xsd +9 -0
  454. data/test/fixtures/product/schemas/retEnvEventoCancNFe_v1.00.xsd +9 -0
  455. data/test/fixtures/product/schemas/retEnvEvento_v1.00.xsd +9 -0
  456. data/test/fixtures/product/schemas/retEnvFiscoNFe_v1.0.xsd +234 -0
  457. data/test/fixtures/product/schemas/retEnvRemIndus_v1.00.xsd +9 -0
  458. data/test/fixtures/product/schemas/retEnvSuframaInternaliza_v1.00.xsd +9 -0
  459. data/test/fixtures/product/schemas/retEnvSuframaVistoria_v1.00.xsd +9 -0
  460. data/test/fixtures/product/schemas/retEnviNFe_v2.00.xsd +9 -0
  461. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/retEnviNFe_v3.10.xsd +8 -8
  462. data/test/fixtures/product/schemas/retEventoEPEC_v0.01.xsd +207 -0
  463. data/test/fixtures/product/schemas/retInutNFe_v2.00.xsd +9 -0
  464. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/retInutNFe_v3.10.xsd +8 -8
  465. data/test/fixtures/product/schemas/retPProrrogNFe_v1.0.xsd +233 -0
  466. data/test/fixtures/product/schemas/retconsNFeDest_v1.01.xsd +9 -0
  467. data/test/fixtures/product/schemas/tiposBasico_v1.03.xsd +816 -0
  468. data/test/fixtures/product/schemas/tiposBasico_v1.03_OPENSSL.xsd +816 -0
  469. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/tiposBasico_v3.10.xsd +571 -571
  470. data/test/fixtures/product/schemas/tiposBasico_v3.10_OPENSSL.xsd +877 -0
  471. data/test/fixtures/product/schemas/tiposDistDFe_v1.00.xsd +217 -0
  472. data/{lib/br_nfe/product/xml/v3_10/XSD → test/fixtures/product/schemas}/xmldsig-core-schema_v1.01.xsd +97 -97
  473. data/test/fixtures/product/wsdl/NFeRetAutorizacao.xml +80 -0
  474. data/test/fixtures/product/wsdl/NfeAutorizacao.xml +107 -0
  475. data/test/fixtures/product/wsdl/NfeConsulta2.xml +80 -0
  476. data/test/fixtures/product/wsdl/NfeStatusServico2.xml +70 -0
  477. data/test/fixtures/product/wsdl/nfeinutilizacao2.xml +80 -0
  478. data/test/fixtures/service/wsdl/betha/v1/cancelar_nfse.xml +178 -0
  479. data/test/fixtures/service/wsdl/betha/v1/consultar_lote_rps.xml +339 -0
  480. data/test/fixtures/service/wsdl/betha/v1/consultar_nfse.xml +348 -0
  481. data/test/fixtures/service/wsdl/betha/v1/consultar_nfse_por_rps.xml +365 -0
  482. data/test/fixtures/service/wsdl/betha/v1/consultar_situacao_lote_rps.xml +74 -0
  483. data/test/fixtures/service/wsdl/betha/v1/recepcionar_lote_rps.xml +299 -0
  484. data/test/fixtures/service/wsdl/simpliss/v1/nfseservice.xml +1 -0
  485. data/test/fixtures/service/wsdl/thema/v1/nfse_cancelamento.xml +82 -0
  486. data/test/fixtures/service/wsdl/thema/v1/nfse_consulta.xml +235 -0
  487. data/test/fixtures/service/wsdl/thema/v1/nfse_remessa.xml +185 -0
  488. data/test/test_helper.rb +369 -1
  489. metadata +711 -33
  490. data/lib/br_nfe/product/base.rb +0 -82
  491. data/lib/br_nfe/product/consulta_status_servico.rb +0 -35
  492. data/lib/br_nfe/product/value_nf.rb +0 -9
  493. data/lib/br_nfe/product/xml/v3_10/consulta_status_servico.xml.slim +0 -4
  494. data/test/br_nfe/product/base_test.rb +0 -150
  495. data/test/br_nfe/product/consulta_status_servico_test.rb +0 -59
@@ -0,0 +1,349 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Product::Operation::NfeConsultaProtocolo do
4
+ subject { FactoryGirl.build(:product_operation_nfe_consulta_protocolo) }
5
+
6
+ let(:gateway) { FactoryGirl.build(:product_gateway_web_service_svrs) }
7
+
8
+ before do
9
+ subject.stubs(:gateway).returns(gateway)
10
+ end
11
+
12
+ describe '#aliases' do
13
+ it { must_have_alias_attribute :chNFe, :chave_nfe }
14
+ end
15
+
16
+ describe 'Validations' do
17
+ it { must validate_presence_of(:chave_nfe) }
18
+ it { must validate_length_of(:chave_nfe).is_equal_to(44) }
19
+ end
20
+
21
+ it 'o método #wsdl deve pegar o valor do método wsdl_consulta_protocolo do gateway ' do
22
+ gateway.expects(:wsdl_consulta_protocolo).returns('http://teste.wsdl_consulta_protocolo.com')
23
+ subject.wsdl.must_equal 'http://teste.wsdl_consulta_protocolo.com'
24
+ end
25
+
26
+ it 'o método #method_wsdl deve pegar o valor do método operation_consulta_protocolo do gateway ' do
27
+ gateway.expects(:operation_consulta_protocolo).returns(:operation_consulta_protocolo)
28
+ subject.method_wsdl.must_equal :operation_consulta_protocolo
29
+ end
30
+
31
+ it 'o método #gateway_xml_version deve pegar o valor do método version_xml_consulta_protocolo do gateway ' do
32
+ gateway.expects(:version_xml_consulta_protocolo).returns(:v3_20)
33
+ subject.gateway_xml_version.must_equal :v3_20
34
+ end
35
+
36
+ it 'o método #url_xmlns deve pegar o valor do método url_xmlns_consulta_protocolo do gateway ' do
37
+ gateway.expects(:url_xmlns_consulta_protocolo).returns('http://teste.url_xmlns_consulta_protocolo.com')
38
+ subject.url_xmlns.must_equal 'http://teste.url_xmlns_consulta_protocolo.com'
39
+ end
40
+
41
+ it 'o método #ssl_version deve pegar o valor do método ssl_version_consulta_protocolo do gateway ' do
42
+ gateway.expects(:ssl_version_consulta_protocolo).returns(:SSLv1)
43
+ subject.ssl_version.must_equal :SSLv1
44
+ end
45
+
46
+ describe '#xml_builder' do
47
+ it "Deve renderizar o XML e setar o valor na variavel @xml_builder" do
48
+ subject.expects(:render_xml).returns('<xml>OK</xml>')
49
+
50
+ subject.xml_builder.must_equal '<xml>OK</xml>'
51
+ subject.instance_variable_get(:@xml_builder).must_equal '<xml>OK</xml>'
52
+ end
53
+ it "Se já houver valor setado na variavel @xml_builder não deve renderizar o xml novamente" do
54
+ subject.instance_variable_set(:@xml_builder, '<xml>OK</xml>')
55
+ subject.expects(:render_xml).never
56
+ subject.xml_builder.must_equal '<xml>OK</xml>'
57
+ end
58
+ end
59
+
60
+ describe "Validação do XML através do XSD" do
61
+ context "for XML Version 2.01" do
62
+ before { subject.stubs(:gateway_xml_version).returns(:v2_01) }
63
+ it "Deve ser válido em ambiente de produção" do
64
+ subject.env = :production
65
+ nfe_must_be_valid_by_schema 'consSitNFe_v2.01.xsd'
66
+ end
67
+ it "Deve ser válido em ambiente de homologação" do
68
+ subject.env = :test
69
+ nfe_must_be_valid_by_schema 'consSitNFe_v2.01.xsd'
70
+ end
71
+ end
72
+ context "for XML Version 3.10" do
73
+ before { subject.stubs(:gateway_xml_version).returns(:v3_10) }
74
+
75
+ it "Deve ser válido em ambiente de produção" do
76
+ subject.env = :production
77
+ nfe_must_be_valid_by_schema 'consSitNFe_v3.10.xsd'
78
+ end
79
+ it "Deve ser válido em ambiente de homologação" do
80
+ subject.env = :test
81
+ nfe_must_be_valid_by_schema 'consSitNFe_v3.10.xsd'
82
+ end
83
+ end
84
+ end
85
+
86
+ describe 'REQUEST MUST BE SET RESPONSE CORRECTLY' do
87
+ let(:response_fail) { read_fixture('product/response/v3.10/nfe_consulta_protocolo/fail.xml') }
88
+ let(:response_success_without_event){ read_fixture('product/response/v3.10/nfe_consulta_protocolo/success_without.xml') }
89
+ let(:response_success_one_event) { read_fixture('product/response/v3.10/nfe_consulta_protocolo/success_one.xml') }
90
+ let(:response_success_many_events_without_cancel) { read_fixture('product/response/v3.10/nfe_consulta_protocolo/success_many_without_cancel.xml') }
91
+ let(:response_success_many_events_with_cancel) { read_fixture('product/response/v3.10/nfe_consulta_protocolo/success_many_with_cancel.xml') }
92
+ let(:xml_nfe_without_proc) { read_fixture('product/response/v3.10/nfe_consulta_protocolo/nfe_original/without_proc.xml') }
93
+ let(:xml_nfe_with_proc) { read_fixture('product/response/v3.10/nfe_consulta_protocolo/nfe_original/with_proc.xml') }
94
+
95
+ before do
96
+ savon.mock!
97
+ stub_request(:get, subject.wsdl).to_return(status: 200, body: read_fixture('product/wsdl/NfeConsulta2.xml') )
98
+ end
99
+ after { savon.unmock! }
100
+
101
+ it "Quando a resposta reotrnar com algum erro não deve instanciar os eventos" do
102
+ subject.original_xml = xml_nfe_with_proc
103
+ savon.expects(subject.method_wsdl).returns( response_fail )
104
+ subject.request
105
+ response = subject.response
106
+
107
+ response.must_be_kind_of BrNfe::Product::Response::NfeConsultaProtocolo
108
+
109
+ response.environment.must_equal :test
110
+ response.app_version.must_equal 'SVRS201610061504'
111
+ response.processed_at.must_equal Time.parse('2017-01-04T15:45:02-02:00')
112
+ response.protocol.must_be_nil
113
+ response.request_status.must_equal :success
114
+ response.processing_status_code.must_equal '226'
115
+ response.processing_status_motive.must_equal 'Rejeicao: Codigo da UF do Emitente diverge da UF autorizadora'
116
+ response.processing_status.must_equal :error
117
+ response.nota_fiscal.must_be_nil
118
+ response.main_event.must_be_nil
119
+ response.events.must_be_empty
120
+ end
121
+
122
+ it "Quando retornar apenas o protocolo da NF-e e não tiver nenhum evento deve apenas setar o protocolo no XML da NF-e" do
123
+ subject.original_xml = xml_nfe_without_proc
124
+ savon.expects(subject.method_wsdl).returns( response_success_without_event )
125
+ subject.request
126
+ response = subject.response
127
+
128
+ response.must_be_kind_of BrNfe::Product::Response::NfeConsultaProtocolo
129
+
130
+ response.environment.must_equal :test
131
+ response.app_version.must_equal 'SVRS201610061504'
132
+ response.processed_at.must_equal Time.parse('2017-01-03T08:56:39-02:00')
133
+ response.protocol.must_be_nil
134
+ response.request_status.must_equal :success
135
+ response.processing_status_code.must_equal '100'
136
+ response.processing_status_motive.must_equal 'Autorizado o uso da NF-e'
137
+ response.processing_status.must_equal :success
138
+ response.main_event.must_be_nil
139
+ response.events.must_be_empty
140
+
141
+ nf = response.nota_fiscal
142
+ nf.wont_be_nil
143
+ nf.processed_at.must_equal Time.parse('2017-01-03T08:53:13-02:00')
144
+ nf.protocol.must_equal '342170000000903'
145
+ nf.digest_value.must_equal '2N5tbfnT9V4oRxiesTyBLP9tAVE='
146
+ nf.status_code.must_equal '100'
147
+ nf.status_motive.must_equal 'Autorizado o uso da NF-e'
148
+ nf.chave_de_acesso.must_equal '42170108897094000155550010000000051201601010'
149
+ nf.situation.must_equal :authorized
150
+ nf.xml.must_equal xml_nfe_with_proc, "Deveria adicionar o protocolo da NF-e e a NF dentro da tag nfeProc"
151
+ end
152
+
153
+ it "Quando retornar apenas 1 evento deve seta-lo como o evento principal e também adicionar na lista de eventos" do
154
+ subject.original_xml = xml_nfe_with_proc
155
+ savon.expects(subject.method_wsdl).returns( response_success_one_event )
156
+ subject.request
157
+ response = subject.response
158
+
159
+ response.environment.must_equal :test
160
+ response.app_version.must_equal 'SVRS201610061504'
161
+ response.processed_at.must_equal Time.parse('2017-01-03T08:56:39-02:00')
162
+ response.protocol.must_be_nil
163
+ response.request_status.must_equal :success
164
+ response.processing_status_code.must_equal '135'
165
+ response.processing_status_motive.must_equal 'Evento registrado e vinculado a NF-e'
166
+ response.processing_status.must_equal :success
167
+ response.main_event.wont_be_nil
168
+ response.events.size.must_equal 1
169
+
170
+ response.main_event.must_equal response.events[0]
171
+
172
+ event = response.main_event
173
+ event.codigo_orgao.must_equal '35'
174
+ event.status_code.must_equal '135'
175
+ event.status_motive.must_equal 'Evento registrado e vinculado a NF-e'
176
+ event.code.must_equal '110110'
177
+ event.sequence.must_equal 1
178
+ event.cpf_cnpj_destino.must_equal '04962355000112'
179
+ event.sent_at.must_equal Time.parse('2014-02-05T16:06:30-02:00')
180
+ event.registred_at.must_equal Time.parse('2014-02-05T16:06:32-02:00')
181
+ event.event_protocol.must_equal ''
182
+ event.ret_event_protocol.must_equal '135140000457555'
183
+ event.xml.must_equal read_fixture('product/response/v3.10/nfe_consulta_protocolo/event_xml/one_event.xml')
184
+
185
+ nf = response.nota_fiscal
186
+ nf.processed_at.must_equal Time.parse('2017-01-03T08:53:13-02:00')
187
+ nf.protocol.must_equal '342170000000903'
188
+ nf.digest_value.must_equal '2N5tbfnT9V4oRxiesTyBLP9tAVE='
189
+ nf.status_code.must_equal '100'
190
+ nf.status_motive.must_equal 'Autorizado o uso da NF-e'
191
+ nf.chave_de_acesso.must_equal '42170108897094000155550010000000051201601010'
192
+ nf.situation.must_equal :adjusted
193
+ nf.xml.must_equal xml_nfe_with_proc, "Não deve duplicar os protocolos se já houver algum protocolo em nfeProc"
194
+ end
195
+
196
+ it "Quando tem mais de um evento e não tiver Cancelamneto deve setar todos os eventos na lista e setar o de maior sequencia no evento principal" do
197
+ subject.original_xml = xml_nfe_with_proc
198
+ savon.expects(subject.method_wsdl).returns( response_success_many_events_without_cancel )
199
+ subject.request
200
+ response = subject.response
201
+
202
+ response.environment.must_equal :production
203
+ response.app_version.must_equal 'SVRS201610061505'
204
+ response.processed_at.must_equal Time.parse('2017-01-03T08:56:39-02:00')
205
+ response.protocol.must_be_nil
206
+ response.request_status.must_equal :success
207
+ response.processing_status_code.must_equal '101'
208
+ response.processing_status_motive.must_equal 'Cancelamento de NF-e homologado'
209
+ response.processing_status.must_equal :success
210
+ response.main_event.wont_be_nil
211
+ response.events.size.must_equal 3
212
+
213
+ events = response.events.sort_by{|e| [e.sequence.to_i, (e.registred_at||Time.current)] }
214
+ response.main_event.must_equal events[2]
215
+
216
+ events[0].codigo_orgao.must_equal '35'
217
+ events[0].status_code.must_equal '135'
218
+ events[0].status_motive.must_equal 'Evento registrado e vinculado a NF-e'
219
+ events[0].code.must_equal '110110'
220
+ events[0].sequence.must_equal 1
221
+ events[0].cpf_cnpj_destino.must_equal '04962355000112'
222
+ events[0].sent_at.must_equal Time.parse('2014-02-05T16:06:30-02:00')
223
+ events[0].registred_at.must_equal Time.parse('2014-02-05T16:06:32-02:00')
224
+ events[0].event_protocol.must_equal ''
225
+ events[0].ret_event_protocol.must_equal '135140000457555'
226
+ events[0].description.must_equal 'Carta de Correcao'
227
+ events[0].justification.must_equal ''
228
+ events[0].correction_text.must_equal 'teste de consulta de nfe corrigida primeira coorecao para consulta de nota'
229
+ events[0].xml.must_equal read_fixture('product/response/v3.10/nfe_consulta_protocolo/event_xml/event_1.xml')
230
+
231
+ events[1].codigo_orgao.must_equal '35'
232
+ events[1].status_code.must_equal '135'
233
+ events[1].status_motive.must_equal 'Evento registrado e vinculado a NF-e'
234
+ events[1].code.must_equal '110110'
235
+ events[1].sequence.must_equal 2
236
+ events[1].cpf_cnpj_destino.must_equal '04962355000112'
237
+ events[1].sent_at.must_equal Time.parse('2014-02-05T16:06:30-02:00')
238
+ events[1].registred_at.must_equal Time.parse('2014-02-05T16:06:32-02:00')
239
+ events[1].event_protocol.must_equal ''
240
+ events[1].ret_event_protocol.must_equal '135140000457416'
241
+ events[1].description.must_equal 'Carta de Correcao'
242
+ events[1].justification.must_equal ''
243
+ events[1].correction_text.must_equal 'teste de consulta de nfe corrigida segunda coorecao para consulta de nota'
244
+ events[1].xml.must_equal read_fixture('product/response/v3.10/nfe_consulta_protocolo/event_xml/event_2.xml')
245
+
246
+ events[2].codigo_orgao.must_equal '35'
247
+ events[2].status_code.must_equal '135'
248
+ events[2].status_motive.must_equal 'Evento registrado e vinculado a NF-e'
249
+ events[2].code.must_equal '110110'
250
+ events[2].sequence.must_equal 3
251
+ events[2].cpf_cnpj_destino.must_equal '04962355000112'
252
+ events[2].sent_at.must_equal Time.parse('2014-02-05T16:06:30-02:00')
253
+ events[2].registred_at.must_equal Time.parse('2014-02-05T16:06:32-02:00')
254
+ events[2].event_protocol.must_equal ''
255
+ events[2].ret_event_protocol.must_equal '135140000457417'
256
+ events[2].description.must_equal 'Carta de Correcao'
257
+ events[2].justification.must_equal ''
258
+ events[2].correction_text.must_equal 'teste de consulta de nfe corrigida terceiro coorecao para consulta de nota'
259
+ events[2].xml.must_equal read_fixture('product/response/v3.10/nfe_consulta_protocolo/event_xml/event_3.xml')
260
+
261
+ nf = response.nota_fiscal
262
+ nf.processed_at.must_equal Time.parse('2017-01-03T08:53:13-02:00')
263
+ nf.protocol.must_equal '342170000000903'
264
+ nf.digest_value.must_equal '2N5tbfnT9V4oRxiesTyBLP9tAVE='
265
+ nf.status_code.must_equal '100'
266
+ nf.status_motive.must_equal 'Autorizado o uso da NF-e'
267
+ nf.chave_de_acesso.must_equal '42170108897094000155550010000000051201601010'
268
+ nf.situation.must_equal :adjusted
269
+ nf.xml.must_equal xml_nfe_with_proc, "Não deve duplicar os protocolos se já houver algum protocolo em nfeProc"
270
+ end
271
+
272
+ it "Quando tem mais de um evento e tem um evento de Cancelamento, sempre deve ser o principal" do
273
+ subject.original_xml = xml_nfe_with_proc
274
+ savon.expects(subject.method_wsdl).returns( response_success_many_events_with_cancel )
275
+ subject.request
276
+ response = subject.response
277
+
278
+ response.environment.must_equal :production
279
+ response.app_version.must_equal 'SVRS201610061505'
280
+ response.processed_at.must_equal Time.parse('2017-01-03T08:56:39-02:00')
281
+ response.protocol.must_be_nil
282
+ response.request_status.must_equal :success
283
+ response.processing_status_code.must_equal '101'
284
+ response.processing_status_motive.must_equal 'Cancelamento de NF-e homologado'
285
+ response.processing_status.must_equal :success
286
+ response.main_event.wont_be_nil
287
+ response.events.size.must_equal 3
288
+
289
+ events = response.events.sort_by{|e| [e.sequence.to_i, (e.registred_at||Time.current)] }
290
+ response.main_event.must_equal events[1]
291
+
292
+ events[0].codigo_orgao.must_equal '35'
293
+ events[0].status_code.must_equal '135'
294
+ events[0].status_motive.must_equal 'Evento registrado e vinculado a NF-e'
295
+ events[0].code.must_equal '110110'
296
+ events[0].sequence.must_equal 1
297
+ events[0].cpf_cnpj_destino.must_equal '04962355000112'
298
+ events[0].sent_at.must_equal Time.parse('2014-02-05T16:06:30-02:00')
299
+ events[0].registred_at.must_equal Time.parse('2014-02-05T16:06:32-02:00')
300
+ events[0].event_protocol.must_equal ''
301
+ events[0].ret_event_protocol.must_equal '135140000457555'
302
+ events[0].description.must_equal 'Carta de Correcao'
303
+ events[0].justification.must_equal ''
304
+ events[0].correction_text.must_equal 'teste de consulta de nfe corrigida primeira coorecao para consulta de nota'
305
+ events[0].xml.must_equal read_fixture('product/response/v3.10/nfe_consulta_protocolo/event_xml/event_1.xml')
306
+
307
+ events[2].codigo_orgao.must_equal '35'
308
+ events[2].status_code.must_equal '135'
309
+ events[2].status_motive.must_equal 'Evento registrado e vinculado a NF-e'
310
+ events[2].code.must_equal '110110'
311
+ events[2].sequence.must_equal 2
312
+ events[2].cpf_cnpj_destino.must_equal '04962355000112'
313
+ events[2].sent_at.must_equal Time.parse('2014-02-05T16:06:30-02:00')
314
+ events[2].registred_at.must_equal Time.parse('2014-02-05T16:06:32-02:00')
315
+ events[2].event_protocol.must_equal ''
316
+ events[2].ret_event_protocol.must_equal '135140000457416'
317
+ events[2].description.must_equal 'Carta de Correcao'
318
+ events[2].justification.must_equal ''
319
+ events[2].correction_text.must_equal 'teste de consulta de nfe corrigida segunda coorecao para consulta de nota'
320
+ events[2].xml.must_equal read_fixture('product/response/v3.10/nfe_consulta_protocolo/event_xml/event_2.xml')
321
+
322
+ events[1] = response.main_event
323
+ events[1].codigo_orgao.must_equal '42'
324
+ events[1].status_code.must_equal '135'
325
+ events[1].status_motive.must_equal 'Evento registrado e vinculado a NF-e'
326
+ events[1].code.must_equal '110111'
327
+ events[1].sequence.must_equal 1
328
+ events[1].cpf_cnpj_destino.must_equal '00090742403050'
329
+ events[1].sent_at.must_equal Time.parse('2017-01-03T08:54:58-02:00')
330
+ events[1].registred_at.must_equal Time.parse('2017-01-03T08:55:05-02:00')
331
+ events[1].event_protocol.must_equal '342170000000903'
332
+ events[1].ret_event_protocol.must_equal '342170000000906'
333
+ events[1].description.must_equal 'Cancelamento'
334
+ events[1].justification.must_equal 'Cancelamento para teste'
335
+ events[1].correction_text.must_equal ''
336
+ events[1].xml.must_equal read_fixture('product/response/v3.10/nfe_consulta_protocolo/event_xml/event_cancel.xml')
337
+
338
+ nf = response.nota_fiscal
339
+ nf.processed_at.must_equal Time.parse('2017-01-03T08:53:13-02:00')
340
+ nf.protocol.must_equal '342170000000903'
341
+ nf.digest_value.must_equal '2N5tbfnT9V4oRxiesTyBLP9tAVE='
342
+ nf.status_code.must_equal '100'
343
+ nf.status_motive.must_equal 'Autorizado o uso da NF-e'
344
+ nf.chave_de_acesso.must_equal '42170108897094000155550010000000051201601010'
345
+ nf.situation.must_equal :canceled
346
+ nf.xml.must_equal xml_nfe_with_proc, "Não deve duplicar os protocolos se já houver algum protocolo em nfeProc"
347
+ end
348
+ end
349
+ end
@@ -0,0 +1,93 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Product::Operation::NfeDownloadNf do
4
+ subject { FactoryGirl.build(:product_operation_nfe_download_nf) }
5
+ let(:gateway) { FactoryGirl.build(:product_gateway_web_service_svrs) }
6
+
7
+ before do
8
+ subject.stubs(:gateway).returns(gateway)
9
+ end
10
+
11
+ describe '#aliases' do
12
+ it { must_have_alias_attribute :chNFe, :chave_nfe }
13
+ end
14
+
15
+ describe 'Validations' do
16
+ describe '#chave_nfe' do
17
+ before { subject.stubs(:generate_key) }
18
+ it { must validate_presence_of(:chave_nfe) }
19
+ it { must validate_length_of(:chave_nfe).is_equal_to(44) }
20
+ end
21
+ end
22
+
23
+ describe '#gateway' do
24
+ before do
25
+ subject.unstub(:gateway)
26
+ subject.ibge_code_of_issuer_uf = 42
27
+ end
28
+ it "Por padrão deve pegar o gateway conforme o estado" do
29
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
30
+ subject.class.new(ibge_code_of_issuer_uf: 23).gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceCE
31
+ end
32
+ it "Deve ser possível forçar a utilizar o gateway do SVAN" do
33
+ subject.force_gateway = :SVAN
34
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVAN
35
+ end
36
+ it "Deve ser possível forçar a utilizar o gateway do AN - Vai pegar o base" do
37
+ subject.force_gateway = 'AN'
38
+ subject.gateway.class.must_equal BrNfe::Product::Gateway::Base
39
+ end
40
+ end
41
+
42
+ describe 'gateway methods' do
43
+ it 'o método #wsdl deve pegar o valor do método wsdl_download_nf do gateway ' do
44
+ gateway.expects(:wsdl_download_nf).returns('http://teste.wsdl_download_nf.com')
45
+ subject.wsdl.must_equal 'http://teste.wsdl_download_nf.com'
46
+ end
47
+
48
+ it 'o método #method_wsdl deve pegar o valor do método operation_download_nf do gateway ' do
49
+ gateway.expects(:operation_download_nf).returns(:operation_download_nf)
50
+ subject.method_wsdl.must_equal :operation_download_nf
51
+ end
52
+
53
+ it 'o método #gateway_xml_version deve pegar o valor do método version_xml_download_nf do gateway ' do
54
+ gateway.expects(:version_xml_download_nf).returns(:v3_20)
55
+ subject.gateway_xml_version.must_equal :v3_20
56
+ end
57
+
58
+ it 'o método #url_xmlns deve pegar o valor do método url_xmlns_download_nf do gateway ' do
59
+ gateway.expects(:url_xmlns_download_nf).returns('http://teste.url_xmlns_download_nf.com')
60
+ subject.url_xmlns.must_equal 'http://teste.url_xmlns_download_nf.com'
61
+ end
62
+
63
+ it 'o método #ssl_version deve pegar o valor do método ssl_version_download_nf do gateway ' do
64
+ gateway.expects(:ssl_version_download_nf).returns(:SSLv1)
65
+ subject.ssl_version.must_equal :SSLv1
66
+ end
67
+ end
68
+
69
+ describe '#xml_builder' do
70
+ it "Deve renderizar o XML e setar o valor na variavel @xml_builder" do
71
+ subject.expects(:render_xml).returns('<xml>OK</xml>')
72
+
73
+ subject.xml_builder.must_equal '<xml>OK</xml>'
74
+ subject.instance_variable_get(:@xml_builder).must_equal '<xml>OK</xml>'
75
+ end
76
+ it "Se já houver valor setado na variavel @xml_builder não deve renderizar o xml novamente" do
77
+ subject.instance_variable_set(:@xml_builder, '<xml>OK</xml>')
78
+ subject.expects(:render_xml).never
79
+ subject.xml_builder.must_equal '<xml>OK</xml>'
80
+ end
81
+ end
82
+
83
+ describe "Validação do XML através do XSD" do
84
+ it "Deve ser válido em ambiente de produção" do
85
+ subject.env = :production
86
+ nfe_must_be_valid_by_schema 'downloadNFe_v1.00.xsd'
87
+ end
88
+ it "Deve ser válido em ambiente de homologação" do
89
+ subject.env = :test
90
+ nfe_must_be_valid_by_schema 'downloadNFe_v1.00.xsd'
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,210 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Product::Operation::NfeInutilizacao do
4
+ subject { FactoryGirl.build(:product_operation_nfe_inutilizacao) }
5
+ let(:gateway) { FactoryGirl.build(:product_gateway_web_service_svrs) }
6
+
7
+ before do
8
+ subject.stubs(:gateway).returns(gateway)
9
+ end
10
+
11
+ describe '#aliases' do
12
+ it { must_have_alias_attribute :Id, :chave }
13
+ it { must_have_alias_attribute :mod, :modelo_nf }
14
+ it { must_have_alias_attribute :nNFIni, :numero_nf_inicial }
15
+ it { must_have_alias_attribute :nNFFin, :numero_nf_final }
16
+ it { must_have_alias_attribute :xJust, :justificativa }
17
+ end
18
+
19
+ describe 'Validations' do
20
+ describe '#chave' do
21
+ before { subject.stubs(:generate_key) }
22
+ it { must validate_presence_of(:chave) }
23
+ it { must validate_length_of(:chave).is_equal_to(43) }
24
+ end
25
+ describe '#ano' do
26
+ it { must validate_presence_of(:ano) }
27
+ it { must validate_length_of(:ano).is_equal_to(2) }
28
+ end
29
+ describe '#modelo_nf' do
30
+ it { must validate_presence_of(:modelo_nf) }
31
+ it { must validate_inclusion_of(:modelo_nf).in_array([55,65,'55','65']) }
32
+ end
33
+ describe '#serie' do
34
+ it { must validate_presence_of(:serie) }
35
+ it { must validate_numericality_of(:serie).only_integer }
36
+ it { must validate_length_of(:serie).is_at_most(3) }
37
+ end
38
+ describe '#numero_nf_inicial' do
39
+ it { must validate_presence_of(:numero_nf_inicial) }
40
+ it { must validate_numericality_of(:numero_nf_inicial).only_integer }
41
+ it { must validate_length_of(:numero_nf_inicial).is_at_most(9) }
42
+ end
43
+ describe '#numero_nf_final' do
44
+ before { subject.numero_nf_inicial = nil }
45
+ it { must validate_presence_of(:numero_nf_final) }
46
+ it { must validate_numericality_of(:numero_nf_final).only_integer }
47
+ it { must validate_length_of(:numero_nf_final).is_at_most(9) }
48
+ end
49
+ describe '#justificativa' do
50
+ it { must validate_length_of(:justificativa).is_at_least(15).is_at_most(255) }
51
+ end
52
+ end
53
+
54
+ it 'o método #wsdl deve pegar o valor do método wsdl_inutilizacao do gateway ' do
55
+ gateway.expects(:wsdl_inutilizacao).returns('http://teste.wsdl_inutilizacao.com')
56
+ subject.wsdl.must_equal 'http://teste.wsdl_inutilizacao.com'
57
+ end
58
+
59
+ it 'o método #method_wsdl deve pegar o valor do método operation_inutilizacao do gateway ' do
60
+ gateway.expects(:operation_inutilizacao).returns(:operation_inutilizacao)
61
+ subject.method_wsdl.must_equal :operation_inutilizacao
62
+ end
63
+
64
+ it 'o método #gateway_xml_version deve pegar o valor do método version_xml_inutilizacao do gateway ' do
65
+ gateway.expects(:version_xml_inutilizacao).returns(:v3_20)
66
+ subject.gateway_xml_version.must_equal :v3_20
67
+ end
68
+
69
+ it 'o método #url_xmlns deve pegar o valor do método url_xmlns_inutilizacao do gateway ' do
70
+ gateway.expects(:url_xmlns_inutilizacao).returns('http://teste.url_xmlns_inutilizacao.com')
71
+ subject.url_xmlns.must_equal 'http://teste.url_xmlns_inutilizacao.com'
72
+ end
73
+
74
+ it 'o método #ssl_version deve pegar o valor do método ssl_version_inutilizacao do gateway ' do
75
+ gateway.expects(:ssl_version_inutilizacao).returns(:SSLv1)
76
+ subject.ssl_version.must_equal :SSLv1
77
+ end
78
+
79
+ describe '#numero_nf_final' do
80
+ it "se não setar um valor deve pegar o valor do :numero_nf_inicial" do
81
+ subject.assign_attributes(numero_nf_inicial: 30, numero_nf_final: nil)
82
+ subject.numero_nf_final.must_equal 30
83
+ end
84
+ it "se setar um valor manualmente não deve pegar o valor do :numero_nf_inicial" do
85
+ subject.assign_attributes(numero_nf_inicial: 30, numero_nf_final: 40)
86
+ subject.numero_nf_final.must_equal 40
87
+ end
88
+ end
89
+
90
+ describe '#chave' do
91
+ it "se não setar um chave manualmente deve gerar a chave da NF-e" do
92
+ subject.assign_attributes(
93
+ ano: 17,
94
+ modelo_nf: 65,
95
+ serie: 2,
96
+ numero_nf_inicial: 7,
97
+ numero_nf_final: 15,
98
+ ibge_code_of_issuer_uf: 43,
99
+ chave: '',
100
+ emitente: {
101
+ cnpj: '1234567890123'
102
+ }
103
+
104
+ )
105
+ subject.chave.must_equal 'ID43170123456789012365002000000007000000015'
106
+ end
107
+ it "se já tiver uma chave setada não deve gerar novamente" do
108
+ subject.chave = 'ID431701'
109
+ subject.chave.must_equal 'ID431701'
110
+ end
111
+ end
112
+
113
+ describe '#xml_builder' do
114
+ it "Deve renderizar o XML e setar o valor na variavel @xml_builder" do
115
+ subject.expects(:render_xml).returns('<xml>OK</xml>')
116
+
117
+ subject.xml_builder.must_equal '<xml>OK</xml>'
118
+ subject.instance_variable_get(:@xml_builder).must_equal '<xml>OK</xml>'
119
+ end
120
+ it "Se já houver valor setado na variavel @xml_builder não deve renderizar o xml novamente" do
121
+ subject.instance_variable_set(:@xml_builder, '<xml>OK</xml>')
122
+ subject.expects(:render_xml).never
123
+ subject.xml_builder.must_equal '<xml>OK</xml>'
124
+ end
125
+ end
126
+
127
+ describe "Validação do XML através do XSD" do
128
+ describe 'for XML version 2.00' do
129
+ before { subject.stubs(:gateway_xml_version).returns(:v2_00) }
130
+ it "Deve ser válido em ambiente de produção" do
131
+ subject.env = :production
132
+ nfe_must_be_valid_by_schema 'inutNFe_v2.00.xsd'
133
+ end
134
+ it "Deve ser válido em ambiente de homologação" do
135
+ subject.env = :test
136
+ nfe_must_be_valid_by_schema 'inutNFe_v2.00.xsd'
137
+ end
138
+ end
139
+ describe 'for XML version 3.10' do
140
+ before { subject.stubs(:gateway_xml_version).returns(:v3_10) }
141
+ it "Deve ser válido em ambiente de produção" do
142
+ subject.env = :production
143
+ nfe_must_be_valid_by_schema 'inutNFe_v3.10.xsd'
144
+ end
145
+ it "Deve ser válido em ambiente de homologação" do
146
+ subject.env = :test
147
+ nfe_must_be_valid_by_schema 'inutNFe_v3.10.xsd'
148
+ end
149
+ end
150
+ end
151
+
152
+ describe 'REQUEST MUST BE SET RESPONSE CORRECTLY' do
153
+ let(:xml_success) { read_fixture('product/response/v3.10/nfe_inutilizacao/success.xml') }
154
+ let(:xml_fail) { read_fixture('product/response/v3.10/nfe_inutilizacao/fail.xml') }
155
+ before do
156
+ savon.mock!
157
+ stub_request(:get, subject.wsdl).to_return(status: 200, body: read_fixture('product/wsdl/nfeinutilizacao2.xml') )
158
+ end
159
+ after { savon.unmock! }
160
+
161
+ it "Quando a inutilização foi homologada" do
162
+ savon.expects(subject.method_wsdl).returns(xml_success)
163
+ subject.request
164
+ response = subject.response
165
+
166
+ response.environment.must_equal :test
167
+ response.app_version.must_equal 'SVRS201601161002'
168
+ response.processed_at.must_equal Time.parse('2017-01-17T14:30:49-02:00')
169
+ response.protocol.must_equal '342170000033755'
170
+ response.request_status.must_equal :success
171
+ response.processing_status_code.must_equal '102'
172
+ response.processing_status_motive.must_equal 'Inutilizacao de numero homologado'
173
+ response.processing_status.must_equal :success
174
+
175
+ response.uf.must_equal '42'
176
+
177
+ response.year.must_equal '17'
178
+ response.cnpj.must_equal '26231073000188'
179
+ response.nf_model.must_equal '55'
180
+ response.nf_series.must_equal '1'
181
+ response.start_invoice_number.must_equal '6'
182
+ response.end_invoice_number.must_equal '8'
183
+ end
184
+
185
+ it "Quando a inutilização não for homologada" do
186
+ savon.expects(subject.method_wsdl).returns(xml_fail)
187
+ subject.request
188
+ response = subject.response
189
+
190
+ response.environment.must_equal :test
191
+ response.app_version.must_equal 'SVRS201601161002'
192
+ response.processed_at.must_equal Time.parse('2017-01-17T14:30:49-02:00')
193
+ response.protocol.must_equal ''
194
+ response.request_status.must_equal :success
195
+ response.processing_status_code.must_equal '256'
196
+ response.processing_status_motive.must_equal 'Rejeicao: Uma NF-e da faixa ja esta inutilizada na Base de dados da SEFAZ'
197
+ response.processing_status.must_equal :error
198
+
199
+ response.uf.must_equal '42'
200
+
201
+ response.year.must_equal '17'
202
+ response.cnpj.must_equal '26231073000188'
203
+ response.nf_model.must_equal '55'
204
+ response.nf_series.must_equal '1'
205
+ response.start_invoice_number.must_equal '6'
206
+ response.end_invoice_number.must_equal '8'
207
+ end
208
+ end
209
+
210
+ end