br_nfe 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +16 -0
  5. data/Gemfile.lock +27 -3
  6. data/LICENSE +1 -1
  7. data/README.markdown +10 -12
  8. data/Rakefile +13 -0
  9. data/br_nfe.gemspec +18 -21
  10. data/lib/br_nfe/active_model_base.rb +7 -1
  11. data/lib/br_nfe/base.rb +175 -37
  12. data/lib/br_nfe/endereco.rb +7 -1
  13. data/lib/br_nfe/helper/have_rps.rb +1 -1
  14. data/lib/br_nfe/helper/values_ts/service_v1.rb +313 -0
  15. data/lib/br_nfe/response/service/build_response.rb +286 -0
  16. data/lib/br_nfe/response/service/default.rb +185 -0
  17. data/lib/br_nfe/{servico/response → response/service}/nota_fiscal.rb +11 -10
  18. data/lib/br_nfe/response/service/paths/base.rb +93 -0
  19. data/lib/br_nfe/response/service/paths/v1/servico_cancelar_nfse_resposta.rb +22 -0
  20. data/lib/br_nfe/response/service/paths/v1/servico_consultar_lote_rps_resposta.rb +25 -0
  21. data/lib/br_nfe/response/service/paths/v1/servico_consultar_nfse_resposta.rb +25 -0
  22. data/lib/br_nfe/response/service/paths/v1/servico_consultar_nfse_rps_resposta.rb +25 -0
  23. data/lib/br_nfe/response/service/paths/v1/servico_consultar_situacao_lote_rps_resposta.rb +31 -0
  24. data/lib/br_nfe/response/service/paths/v1/servico_enviar_lote_rps_resposta.rb +36 -0
  25. data/lib/br_nfe/response/service/paths/v1/tc_nfse.rb +127 -0
  26. data/lib/br_nfe/service/base.rb +59 -0
  27. data/lib/br_nfe/service/betha/base.rb +8 -0
  28. data/lib/br_nfe/service/betha/v1/cancelamento_nfs.rb +39 -0
  29. data/lib/br_nfe/service/betha/v1/consulta_lote_rps.rb +34 -0
  30. data/lib/br_nfe/service/betha/v1/consulta_nfs_por_rps.rb +32 -0
  31. data/lib/br_nfe/service/betha/v1/consulta_nfse.rb +32 -0
  32. data/lib/br_nfe/service/betha/v1/consulta_situacao_lote_rps.rb +30 -0
  33. data/lib/br_nfe/service/betha/v1/gateway.rb +21 -0
  34. data/lib/br_nfe/service/betha/v1/recepcao_lote_rps.rb +37 -0
  35. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_lote_rps_resposta.rb +19 -0
  36. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_resposta.rb +17 -0
  37. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +17 -0
  38. data/lib/br_nfe/service/concerns/rules/cancelamento_nfs.rb +20 -0
  39. data/lib/br_nfe/service/concerns/rules/consulta_nfs_por_rps.rb +18 -0
  40. data/lib/br_nfe/service/concerns/rules/consulta_nfse.rb +29 -0
  41. data/lib/br_nfe/service/concerns/rules/recepcao_lote_rps.rb +50 -0
  42. data/lib/br_nfe/{servico → service}/intermediario.rb +1 -1
  43. data/lib/br_nfe/service/item.rb +70 -0
  44. data/lib/br_nfe/service/rps.rb +231 -0
  45. data/lib/br_nfe/service/sc/florianopolis/base.rb +25 -0
  46. data/lib/br_nfe/service/sc/florianopolis/cancellation.rb +30 -0
  47. data/lib/br_nfe/service/sc/florianopolis/emission_rps.rb +19 -0
  48. data/lib/br_nfe/service/sc/florianopolis/xml/_address.xml.slim +21 -0
  49. data/lib/br_nfe/service/sc/florianopolis/xml/_contact.xml.slim +3 -0
  50. data/lib/br_nfe/service/sc/florianopolis/xml/_service_item.xml.slim +9 -0
  51. data/lib/br_nfe/service/sc/florianopolis/xml/cancellation.xml.slim +6 -0
  52. data/lib/br_nfe/service/sc/florianopolis/xml/inf_requisicao.xml.slim +55 -0
  53. data/lib/br_nfe/service/sc/gaspar/cancela_nfse.rb +13 -0
  54. data/lib/br_nfe/service/sc/gaspar/consulta_lote_rps.rb +13 -0
  55. data/lib/br_nfe/service/sc/gaspar/consulta_nfs_por_rps.rb +13 -0
  56. data/lib/br_nfe/service/sc/gaspar/consulta_nfse.rb +17 -0
  57. data/lib/br_nfe/service/sc/gaspar/consulta_situacao_lote_rps.rb +13 -0
  58. data/lib/br_nfe/service/sc/gaspar/recepcao_lote_rps.rb +13 -0
  59. data/lib/br_nfe/service/sc/gaspar/recepcao_lote_rps_limitado.rb +13 -0
  60. data/lib/br_nfe/service/thema/v1/base.rb +55 -0
  61. data/lib/br_nfe/service/thema/v1/cancela_nfse.rb +48 -0
  62. data/lib/br_nfe/service/thema/v1/consulta_lote_rps.rb +49 -0
  63. data/lib/br_nfe/service/thema/v1/consulta_nfs_por_rps.rb +48 -0
  64. data/lib/br_nfe/service/thema/v1/consulta_nfse.rb +47 -0
  65. data/lib/br_nfe/service/thema/v1/consulta_situacao_lote_rps.rb +46 -0
  66. data/lib/br_nfe/service/thema/v1/recepcao_lote_rps.rb +51 -0
  67. data/lib/br_nfe/service/thema/v1/recepcao_lote_rps_limitado.rb +30 -0
  68. data/lib/br_nfe/service/xml/v1/_tc_contato.xml.slim +7 -0
  69. data/lib/br_nfe/service/xml/v1/_tc_cpf_cnpj.xml.slim +5 -0
  70. data/lib/br_nfe/service/xml/v1/_tc_dados_construcao_civil.xml.slim +2 -0
  71. data/lib/br_nfe/service/xml/v1/_tc_dados_prestador.xml.slim +15 -0
  72. data/lib/br_nfe/service/xml/v1/_tc_dados_servico.xml.slim +14 -0
  73. data/lib/br_nfe/service/xml/v1/_tc_dados_tomador.xml.slim +15 -0
  74. data/lib/br_nfe/service/xml/v1/_tc_endereco.xml.slim +13 -0
  75. data/lib/br_nfe/service/xml/v1/_tc_identificacao_intermediario_servico.xml.slim +7 -0
  76. data/lib/br_nfe/service/xml/v1/_tc_identificacao_nfse.xml.slim +7 -0
  77. data/lib/br_nfe/service/xml/v1/_tc_identificacao_orgao_gerador.xml.slim +8 -0
  78. data/lib/br_nfe/service/xml/v1/_tc_identificacao_prestador.xml.slim +3 -0
  79. data/lib/br_nfe/service/xml/v1/_tc_identificacao_rps.xml.slim +16 -0
  80. data/lib/br_nfe/service/xml/v1/_tc_identificacao_tomador.xml.slim +4 -0
  81. data/lib/br_nfe/service/xml/v1/_tc_inf_pedido_cancelamento.xml.slim +4 -0
  82. data/lib/br_nfe/service/xml/v1/_tc_inf_rps.xml.slim +47 -0
  83. data/lib/br_nfe/service/xml/v1/_tc_lote_rps.xml.slim +9 -0
  84. data/lib/br_nfe/service/xml/v1/_tc_pedido_cancelamento.xml.slim +4 -0
  85. data/lib/br_nfe/service/xml/v1/_tc_rps.xml.slim +8 -0
  86. data/lib/br_nfe/service/xml/v1/_tc_valores.xml.slim +48 -0
  87. data/lib/br_nfe/service/xml/v1/servico_cancelar_nfse_envio.xml.slim +9 -0
  88. data/lib/br_nfe/service/xml/v1/servico_consultar_lote_rps_envio.xml.slim +4 -0
  89. data/lib/br_nfe/service/xml/v1/servico_consultar_nfse_envio.xml.slim +19 -0
  90. data/lib/br_nfe/service/xml/v1/servico_consultar_nfse_rps_envio.xml.slim +5 -0
  91. data/lib/br_nfe/service/xml/v1/servico_consultar_situacao_lote_rps_envio.xml.slim +4 -0
  92. data/lib/br_nfe/service/xml/v1/servico_enviar_lote_rps_envio.xml.slim +9 -0
  93. data/lib/br_nfe/version.rb +2 -2
  94. data/lib/br_nfe/xml/_signed_info_sh1.xml.slim +9 -0
  95. data/lib/br_nfe/xml/signature_sh1.xml.slim +12 -0
  96. data/lib/br_nfe/xml/soap_env.xml.slim +3 -0
  97. data/lib/br_nfe.rb +72 -20
  98. data/test/br_nfe/base_test.rb +257 -108
  99. data/test/br_nfe/helper/have_intermediario_test.rb +2 -2
  100. data/test/br_nfe/helper/have_rps_test.rb +4 -4
  101. data/test/br_nfe/response/service/build_response_test.rb +377 -0
  102. data/test/br_nfe/response/service/default_test.rb +218 -0
  103. data/test/br_nfe/{servico/response → response/service}/nota_fiscal_test.rb +2 -2
  104. data/test/br_nfe/response/service/paths/base_test.rb +199 -0
  105. data/test/br_nfe/response/service/paths/v1/servico_cancelar_nfse_resposta_test.rb +25 -0
  106. data/test/br_nfe/response/service/paths/v1/servico_consultar_lote_rps_resposta_test.rb +30 -0
  107. data/test/br_nfe/response/service/paths/v1/servico_consultar_nfse_resposta_test.rb +30 -0
  108. data/test/br_nfe/response/service/paths/v1/servico_consultar_nfse_rps_resposta_test.rb +30 -0
  109. data/test/br_nfe/response/service/paths/v1/servico_consultar_situacao_lote_rps_resposta_test.rb +30 -0
  110. data/test/br_nfe/response/service/paths/v1/servico_enviar_lote_rps_resposta_test.rb +34 -0
  111. data/test/br_nfe/response/service/paths/v1/tc_nfse_test.rb +122 -0
  112. data/test/br_nfe/service/base_test.rb +138 -0
  113. data/test/br_nfe/service/betha/base_test.rb +9 -0
  114. data/test/br_nfe/service/betha/v1/cancelamento_nfs_test.rb +60 -0
  115. data/test/br_nfe/service/betha/v1/consulta_lote_rps_test.rb +55 -0
  116. data/test/br_nfe/service/betha/v1/consulta_nfs_por_rps_test.rb +55 -0
  117. data/test/br_nfe/service/betha/v1/consulta_nfse_test.rb +53 -0
  118. data/test/br_nfe/service/betha/v1/consulta_situacao_lote_rps_test.rb +49 -0
  119. data/test/br_nfe/service/betha/v1/gateway_test.rb +35 -0
  120. data/test/br_nfe/service/betha/v1/recepcao_lote_rps_test.rb +84 -0
  121. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_lote_rps_resposta_test.rb +16 -0
  122. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_resposta_test.rb +16 -0
  123. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_rps_resposta_test.rb +16 -0
  124. data/test/br_nfe/service/betha/v1/xsd/TiposNFe_v01.xsd +583 -0
  125. data/test/br_nfe/service/betha/v1/xsd/nfse_v01.xsd +652 -0
  126. data/test/br_nfe/service/betha/v1/xsd/servico_cancelar_nfse_envio_v01.xsd +17 -0
  127. data/test/br_nfe/service/betha/v1/xsd/servico_consultar_lote_rps_envio_v01.xsd +16 -0
  128. data/test/br_nfe/service/betha/v1/xsd/servico_consultar_nfse_envio_v01.xsd +28 -0
  129. data/test/br_nfe/service/betha/v1/xsd/servico_consultar_nfse_rps_envio_v01.xsd +16 -0
  130. data/test/br_nfe/service/betha/v1/xsd/servico_consultar_situacao_lote_rps_envio_v01.xsd +16 -0
  131. data/test/br_nfe/service/betha/v1/xsd/servico_enviar_lote_rps_envio_v01.xsd +17 -0
  132. data/test/br_nfe/service/betha/v1/xsd/xmldsig-core-schema.xsd +308 -0
  133. data/test/br_nfe/service/betha/v1/xsd/xmldsig-core-schema_v01.xsd +95 -0
  134. data/test/br_nfe/service/concerns/rules/cancelamento_nfs_test.rb +15 -0
  135. data/test/br_nfe/service/concerns/rules/consulta_nfs_por_rps_test.rb +36 -0
  136. data/test/br_nfe/service/concerns/rules/consulta_nfse_test.rb +42 -0
  137. data/test/br_nfe/{servico/base_test.rb → service/concerns/rules/recepcao_lote_rps_test.rb} +12 -4
  138. data/test/br_nfe/{servico → service}/intermediario_test.rb +1 -1
  139. data/test/br_nfe/service/item_test.rb +34 -0
  140. data/test/br_nfe/{servico → service}/rps_test.rb +191 -43
  141. data/test/br_nfe/service/sc/florianopolis/XSD/TiposNFSe_v2.0.xsd +863 -0
  142. data/test/br_nfe/service/sc/florianopolis/XSD/xmldsig-core-schema.xsd +309 -0
  143. data/test/br_nfe/service/sc/florianopolis/base_test.rb +20 -0
  144. data/test/br_nfe/service/sc/florianopolis/cancellation_test.rb +36 -0
  145. data/test/br_nfe/service/sc/florianopolis/emission_rps_test.rb +145 -0
  146. data/test/br_nfe/service/sc/gaspar/cancela_nfse_test.rb +21 -0
  147. data/test/br_nfe/service/sc/gaspar/consulta_nfs_por_rps_test.rb +21 -0
  148. data/test/br_nfe/service/sc/gaspar/consulta_nfse_test.rb +21 -0
  149. data/test/br_nfe/service/sc/gaspar/consulta_situacao_lote_rps_test.rb +21 -0
  150. data/test/br_nfe/service/sc/gaspar/recepcao_lote_rps_limitado_test.rb +22 -0
  151. data/test/br_nfe/service/sc/gaspar/recepcao_lote_rps_test.rb +22 -0
  152. data/test/br_nfe/service/thema/v1/base_test.rb +65 -0
  153. data/test/br_nfe/service/thema/v1/cancela_nfse_test.rb +56 -0
  154. data/test/br_nfe/service/thema/v1/consulta_lote_rps_test.rb +47 -0
  155. data/test/br_nfe/service/thema/v1/consulta_nfs_por_rps_test.rb +50 -0
  156. data/test/br_nfe/service/thema/v1/consulta_nfse_test.rb +50 -0
  157. data/test/br_nfe/service/thema/v1/consulta_situacao_lote_rps_test.rb +47 -0
  158. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_test.rb +62 -0
  159. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_test_limitado.rb +50 -0
  160. data/test/br_nfe/service/thema/v1/xsd/nfse.xsd +656 -0
  161. data/test/br_nfe/service/thema/v1/xsd/xmldsig-core-schema20020212.xsd +318 -0
  162. data/test/br_nfe/service/xsd/v1/nfse.xsd +779 -0
  163. data/test/br_nfe/service/xsd/v1/xmldsig-core-schema20020212.xsd +316 -0
  164. data/test/cert.pfx +0 -0
  165. data/test/factories/base.rb +2 -0
  166. data/test/factories/destinatario.rb +3 -3
  167. data/test/factories/response/service/build_response.rb +5 -0
  168. data/test/factories/response/service/default.rb +10 -0
  169. data/test/factories/{servico/response → response/service}/nota_fiscal.rb +9 -9
  170. data/test/factories/service/base.rb +6 -0
  171. data/test/factories/service/betha/base.rb +4 -0
  172. data/test/factories/service/betha/v1/cancelamento_nfs.rb +9 -0
  173. data/test/factories/{servico → service}/betha/v1/consulta_lote_rps.rb +2 -2
  174. data/test/factories/{servico → service}/betha/v1/consulta_nfs_por_rps.rb +1 -1
  175. data/test/factories/service/betha/v1/consulta_nfse.rb +8 -0
  176. data/test/factories/{servico → service}/betha/v1/consulta_situacao_lote_rps.rb +2 -2
  177. data/test/factories/{servico → service}/betha/v1/gateway.rb +1 -1
  178. data/test/factories/service/betha/v1/recepcao_lote_rps.rb +8 -0
  179. data/test/factories/{servico → service}/intermediario.rb +2 -2
  180. data/test/factories/service/item.rb +12 -0
  181. data/test/factories/service/rps.rb +50 -0
  182. data/test/factories/service/sc/florianopolis/base.rb +5 -0
  183. data/test/factories/service/sc/florianopolis/cancellation.rb +7 -0
  184. data/test/factories/service/sc/florianopolis/emission_rps.rb +7 -0
  185. data/test/factories/service/sc/gaspar/cancela_nfse.rb +9 -0
  186. data/test/factories/service/sc/gaspar/consulta_lote_rps.rb +7 -0
  187. data/test/factories/service/sc/gaspar/consulta_nfs_por_rps.rb +6 -0
  188. data/test/factories/service/sc/gaspar/consulta_nfse.rb +8 -0
  189. data/test/factories/service/sc/gaspar/consulta_situacao_lote_rps.rb +6 -0
  190. data/test/factories/service/sc/gaspar/recepcao_lote_rps.rb +9 -0
  191. data/test/factories/service/sc/gaspar/recepcao_lote_rps_limitado.rb +9 -0
  192. data/test/factories/service/thema/v1/base.rb +7 -0
  193. data/test/factories/service/thema/v1/cancela_nfse.rb +9 -0
  194. data/test/factories/service/thema/v1/consulta_lote_rps.rb +7 -0
  195. data/test/factories/service/thema/v1/consulta_nfs_por_rps.rb +6 -0
  196. data/test/factories/service/thema/v1/consulta_nfse.rb +8 -0
  197. data/test/factories/service/thema/v1/consulta_situacao_lote_rps.rb +6 -0
  198. data/test/factories/service/thema/v1/recepcao_lote_rps.rb +9 -0
  199. data/test/factories/service/thema/v1/recepcao_lote_rps_limitado.rb +8 -0
  200. data/test/test_helper.rb +42 -0
  201. metadata +338 -121
  202. data/lib/br_nfe/servico/base.rb +0 -35
  203. data/lib/br_nfe/servico/betha/base.rb +0 -85
  204. data/lib/br_nfe/servico/betha/build_response.rb +0 -141
  205. data/lib/br_nfe/servico/betha/v1/build_response.rb +0 -121
  206. data/lib/br_nfe/servico/betha/v1/cancelamento_nfs.rb +0 -52
  207. data/lib/br_nfe/servico/betha/v1/consulta_lote_rps.rb +0 -33
  208. data/lib/br_nfe/servico/betha/v1/consulta_nfs_por_rps.rb +0 -37
  209. data/lib/br_nfe/servico/betha/v1/consulta_nfse.rb +0 -51
  210. data/lib/br_nfe/servico/betha/v1/consulta_situacao_lote_rps.rb +0 -18
  211. data/lib/br_nfe/servico/betha/v1/gateway.rb +0 -125
  212. data/lib/br_nfe/servico/betha/v1/recepcao_lote_rps.rb +0 -97
  213. data/lib/br_nfe/servico/betha/v2/build_response.rb +0 -159
  214. data/lib/br_nfe/servico/betha/v2/cancelamento_nfs.rb +0 -30
  215. data/lib/br_nfe/servico/betha/v2/consulta_lote_rps.rb +0 -30
  216. data/lib/br_nfe/servico/betha/v2/consulta_nfse_por_rps.rb +0 -27
  217. data/lib/br_nfe/servico/betha/v2/envio_lote_rps_sincrono.rb +0 -30
  218. data/lib/br_nfe/servico/betha/v2/gateway.rb +0 -230
  219. data/lib/br_nfe/servico/betha/v2/gera_nfse.rb +0 -30
  220. data/lib/br_nfe/servico/betha/v2/recepcao_lote_rps.rb +0 -52
  221. data/lib/br_nfe/servico/betha/v2/substituicao_nfse.rb +0 -43
  222. data/lib/br_nfe/servico/response/default.rb +0 -34
  223. data/lib/br_nfe/servico/rps.rb +0 -108
  224. data/test/br_nfe/servico/betha/base_test.rb +0 -135
  225. data/test/br_nfe/servico/betha/v1/build_response_test.rb +0 -557
  226. data/test/br_nfe/servico/betha/v1/cancelamento_nfs_test.rb +0 -72
  227. data/test/br_nfe/servico/betha/v1/consulta_lote_rps_test.rb +0 -46
  228. data/test/br_nfe/servico/betha/v1/consulta_nfs_por_rps_test.rb +0 -68
  229. data/test/br_nfe/servico/betha/v1/consulta_nfse_test.rb +0 -74
  230. data/test/br_nfe/servico/betha/v1/consulta_situacao_lote_rps_test.rb +0 -27
  231. data/test/br_nfe/servico/betha/v1/gateway_test.rb +0 -151
  232. data/test/br_nfe/servico/betha/v1/recepcao_lote_rps_test.rb +0 -249
  233. data/test/br_nfe/servico/betha/v2/cancelamento_nfs_test.rb +0 -44
  234. data/test/br_nfe/servico/betha/v2/consulta_lote_rps_test.rb +0 -38
  235. data/test/br_nfe/servico/betha/v2/consulta_nfse_por_rps_test.rb +0 -36
  236. data/test/br_nfe/servico/betha/v2/envio_lote_rps_sincrono_test.rb +0 -51
  237. data/test/br_nfe/servico/betha/v2/gateway_test.rb +0 -372
  238. data/test/br_nfe/servico/betha/v2/gera_nfse_test.rb +0 -62
  239. data/test/br_nfe/servico/betha/v2/recepcao_lote_rps_test.rb +0 -108
  240. data/test/br_nfe/servico/betha/v2/substituicao_nfse_test.rb +0 -84
  241. data/test/br_nfe/servico/response/default_test.rb +0 -54
  242. data/test/factories/servico/base.rb +0 -5
  243. data/test/factories/servico/betha/base.rb +0 -5
  244. data/test/factories/servico/betha/v1/build_response.rb +0 -6
  245. data/test/factories/servico/betha/v1/cancelamento_nfs.rb +0 -7
  246. data/test/factories/servico/betha/v1/consulta_nfse.rb +0 -8
  247. data/test/factories/servico/betha/v1/recepcao_lote_rps.rb +0 -6
  248. data/test/factories/servico/betha/v2/cancelamento_nfs.rb +0 -7
  249. data/test/factories/servico/betha/v2/consulta_lote_rps.rb +0 -6
  250. data/test/factories/servico/betha/v2/consulta_nfse_por_rps.rb +0 -6
  251. data/test/factories/servico/betha/v2/envio_lote_rps_sincrono.rb +0 -5
  252. data/test/factories/servico/betha/v2/gateway.rb +0 -5
  253. data/test/factories/servico/betha/v2/gera_nfse.rb +0 -6
  254. data/test/factories/servico/betha/v2/recepcao_lote_rps.rb +0 -5
  255. data/test/factories/servico/betha/v2/substituicao_nfse.rb +0 -8
  256. data/test/factories/servico/response/default.rb +0 -10
  257. data/test/factories/servico/rps.rb +0 -44
@@ -2,7 +2,7 @@
2
2
  module BrNfeTest
3
3
  module HelperTest
4
4
  module HaveIntermediarioTest
5
- class NewClassIntermediario < BrNfe::Servico::Intermediario
5
+ class NewClassIntermediario < BrNfe::Service::Intermediario
6
6
  end
7
7
 
8
8
  def test_HaveIntermediarioTest_deve_iniciar_o_intermediario_com_nil
@@ -70,7 +70,7 @@ module BrNfeTest
70
70
  BrNfe.intermediario_class = NewClassIntermediario
71
71
  novo_objeto = subject.class.new(intermediario: {cpf_cnpj: '123'})
72
72
  novo_objeto.intermediario.class.must_equal NewClassIntermediario
73
- BrNfe.intermediario_class = BrNfe::Servico::Intermediario
73
+ BrNfe.intermediario_class = BrNfe::Service::Intermediario
74
74
  end
75
75
  end
76
76
  end
@@ -2,16 +2,16 @@
2
2
  module BrNfeTest
3
3
  module HelperTest
4
4
  module HaveRpsTest
5
- class NewRps < BrNfe::Servico::Rps
5
+ class NewRps < BrNfe::Service::Rps
6
6
  end
7
7
 
8
8
  def test_HaveRpsTest_Já_inicia_com_um_rps
9
- subject.class.new.rps.class.must_equal BrNfe::Servico::Rps
9
+ subject.class.new.rps.class.must_equal BrNfe::Service::Rps
10
10
  end
11
11
 
12
12
  def test_HaveRpsTest_Mesmo_setando_o_endereço_como_nil_retorna_um_novo_rps
13
13
  subject.rps = nil
14
- subject.rps.class.must_equal BrNfe::Servico::Rps
14
+ subject.rps.class.must_equal BrNfe::Service::Rps
15
15
  subject.rps.class.wont_equal rps
16
16
  end
17
17
 
@@ -52,7 +52,7 @@ module BrNfeTest
52
52
  def test_HaveRpsTest_posso_modificar_a_class_do_rps
53
53
  BrNfe.rps_class = NewRps
54
54
  subject.rps.class.must_equal NewRps
55
- BrNfe.rps_class = BrNfe::Servico::Rps
55
+ BrNfe.rps_class = BrNfe::Service::Rps
56
56
  end
57
57
  end
58
58
  end
@@ -0,0 +1,377 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Response::Service::BuildResponse do
4
+ subject { FactoryGirl.build(:service_build_response) }
5
+ let(:response) { FactoryGirl.build(:response_service_default) }
6
+
7
+ describe "#initialize" do
8
+ it "ao inicializar deve chamar o metodo include_module! depois de setar os atributos" do
9
+ BrNfe::Response::Service::BuildResponse.any_instance.expects(:assign_attributes).in_sequence(sequence_1)
10
+ BrNfe::Response::Service::BuildResponse.any_instance.expects(:include_module!).in_sequence(sequence_1)
11
+ BrNfe::Response::Service::BuildResponse.new(nfe_xml_path: 'path')
12
+ end
13
+ end
14
+
15
+ describe "include_module!" do
16
+ module RackModuleTest; end
17
+
18
+ it "se tiver valor em module_methods deve incluir o module na classe" do
19
+ subject.module_methods = RackModuleTest
20
+ subject.class.expects(:send).with(:include, RackModuleTest)
21
+ subject.send(:include_module!)
22
+ end
23
+ it "se não tiver valor em module_methods não deve tenatar incluir module na classe" do
24
+ subject.module_methods = nil
25
+ subject.class.expects(:send).never
26
+ subject.send(:include_module!)
27
+ end
28
+ end
29
+
30
+ describe "#response" do
31
+ it "Deve instanciar se setar na variavel @response um objeto da classe BrNfe::Response::Service::Default" do
32
+ response
33
+ subject.stubs(:message_errors_path).returns('message_errors_path')
34
+ subject.stubs(:get_message_for_path).with('message_errors_path').returns('get_message_for_path')
35
+ subject.stubs(:get_invoices).returns('get_invoices')
36
+ subject.stubs(:get_protocol).returns('get_protocol')
37
+ subject.stubs(:get_received_date).returns('get_received_date')
38
+ subject.stubs(:get_lot_number).returns('get_lot_number')
39
+ subject.stubs(:get_situation).returns('get_situation')
40
+ subject.stubs(:savon_response).returns(stub(xml: 'savon_response'))
41
+ subject.stubs(:get_cancelation_date_time).returns('get_cancelation_date_time')
42
+ BrNfe::Response::Service::Default.expects(:new).with({
43
+ error_messages: 'get_message_for_path',
44
+ notas_fiscais: 'get_invoices',
45
+ protocolo: 'get_protocol',
46
+ data_recebimento: 'get_received_date',
47
+ numero_lote: 'get_lot_number',
48
+ situation: 'get_situation',
49
+ original_xml: 'savon_response',
50
+ cancelation_date_time: 'get_cancelation_date_time'
51
+ }).returns(response)
52
+ subject.response.must_equal response
53
+ subject.instance_variable_get(:@response).must_equal response
54
+ end
55
+ it "se já tem valor setado em @response não deve instanciar um novo" do
56
+ subject.instance_variable_set(:@response, response)
57
+ BrNfe::Response::Service::Default.expects(:new).never
58
+ subject.response.must_equal response
59
+ end
60
+ end
61
+
62
+ describe "#find_value_for_keys" do
63
+ let(:var_hash) { {lvl1: {lvl2: {lvl3: 'value' } } } }
64
+
65
+ it "deve retornar o valor do hash quando encontra-lo" do
66
+ subject.find_value_for_keys(var_hash, [:lvl1, :lvl2, :lvl3]).must_equal 'value'
67
+ end
68
+ it "Se as chaves não exisitrem deve retornar nil" do
69
+ subject.find_value_for_keys(var_hash, [:lvl1, :noexist, :lvl4]).must_be_nil
70
+ end
71
+ it "o valor da chave não for um hash e ainda não terminar o loop não deve dar erro" do
72
+ subject.find_value_for_keys(var_hash, [:lvl1, :lvl2, :lvl3, :lvl4]).must_be_nil
73
+ end
74
+ it "pode retornar um hash se o ultimo valor for Hash" do
75
+ subject.find_value_for_keys(var_hash, [:lvl1, :lvl2]).must_equal({lvl3: 'value'})
76
+ end
77
+ it "se não passar apenas uma chave sem array deve retorar o valor da chave" do
78
+ subject.find_value_for_keys(var_hash, :lvl1).must_equal({lvl2: {lvl3: 'value'}})
79
+ end
80
+ end
81
+
82
+ describe "#path_with_root" do
83
+ it "deve concatenar o array do parametro com o Array do root path" do
84
+ subject.keys_root_path = [:root_path]
85
+ subject.path_with_root([:child, :child2]).must_equal([:root_path, :child, :child2])
86
+ end
87
+ it "se o path do params estiver em branco deve retornar nil" do
88
+ subject.keys_root_path = [:root_path]
89
+ subject.path_with_root([]).must_be_nil
90
+ end
91
+ end
92
+
93
+ describe "#get_message_for_path" do
94
+ before do
95
+ subject.stubs(:savon_body).returns(:savon_body)
96
+ subject.stubs(:path_with_root).with(:msg_path).returns([:msg, :path])
97
+ end
98
+ it "Quando ao procurar a mensagem retornar um Hash deve buscar a msg pelo metodo get_message_for_hash" do
99
+ subject.expects(:find_value_for_keys).with(:savon_body, [:msg, :path]).returns({message: 'ok'}).in_sequence(sequence_1)
100
+ subject.expects(:get_message_for_hash).with({message: 'ok'}).returns("MSG")
101
+
102
+ subject.get_message_for_path(:msg_path).must_equal ['MSG']
103
+ end
104
+ it "Quando ao procurar a mensagem retornar um Array deve buscar as msgs do array pelo metodo get_message_for_hash" do
105
+ subject.expects(:find_value_for_keys).with(:savon_body, [:msg, :path]).returns([{msg: 1},{msg: 2}]).in_sequence(sequence_1)
106
+ subject.expects(:get_message_for_hash).with({msg: 1}).returns("MSG1").in_sequence(sequence_1)
107
+ subject.expects(:get_message_for_hash).with({msg: 2}).returns("MSG2").in_sequence(sequence_1)
108
+
109
+ subject.get_message_for_path(:msg_path).must_equal ['MSG1','MSG2']
110
+ end
111
+ it "Quando ao procurar a mensagem retornar uma String deve add a string na msg" do
112
+ subject.expects(:find_value_for_keys).with(:savon_body, [:msg, :path]).returns('MESSAGE').in_sequence(sequence_1)
113
+ subject.expects(:get_message_for_hash).never
114
+
115
+ subject.get_message_for_path(:msg_path).must_equal ['MESSAGE']
116
+ end
117
+ end
118
+
119
+ describe "#get_message_for_hash" do
120
+ it "deve retornar um Hash com :code, :message e :solution que devem ser encontradas no has do parametro" do
121
+ subject.stubs(:message_code_key).returns(:codigo)
122
+ subject.stubs(:message_msg_key).returns(:mensagem)
123
+ subject.stubs(:message_solution_key).returns(:solucao)
124
+ result = subject.get_message_for_hash({codigo: 'CODE', mensagem: 'Mensagem de erro', solucao: "Solução"})
125
+ result.must_equal({
126
+ code: 'CODE',
127
+ message: 'Mensagem de erro',
128
+ solution: 'Solução'
129
+ })
130
+ end
131
+ end
132
+
133
+ describe "#get_invoices" do
134
+ before do
135
+ subject.stubs(:savon_body).returns(:savon_body)
136
+ subject.stubs(:invoices_path).returns([:invoice, :path])
137
+ subject.stubs(:path_with_root).with([:invoice, :path]).returns([:inv, :path])
138
+ end
139
+ it "Quando ao procurar a nota fiscal retornar um Hash deve instanciar a nf pelo metodo instance_invoice" do
140
+ subject.expects(:find_value_for_keys).with(:savon_body, [:inv, :path]).returns({invoice: 123})
141
+ subject.expects(:instance_invoice).with({invoice: 123}).returns(:invoice)
142
+
143
+ subject.get_invoices.must_equal [:invoice]
144
+ end
145
+
146
+ it "Quando ao procurar a nota fiscal retornar um Array deve instanciar as nfs pelo metodo instance_invoice" do
147
+ subject.expects(:find_value_for_keys).with(:savon_body, [:inv, :path]).returns([{invoice: 1}, {invoice: 2}]).in_sequence(sequence_1)
148
+ subject.expects(:instance_invoice).with({invoice: 1}).returns(:invoice1).in_sequence(sequence_1)
149
+ subject.expects(:instance_invoice).with({invoice: 2}).returns(:invoice2).in_sequence(sequence_1)
150
+ subject.get_invoices.must_equal [:invoice1, :invoice2]
151
+ end
152
+
153
+ describe "#get_protocol" do
154
+ it "deve buscar o numero do protocolo a partir do caminho em protocol_path" do
155
+ subject.stubs(:savon_body).returns(:savon_body)
156
+ subject.stubs(:protocol_path).returns(:protocol_path)
157
+ subject.stubs(:path_with_root).with(:protocol_path).returns([:path, :root])
158
+ subject.expects(:find_value_for_keys).with(:savon_body, [:path, :root]).returns('13546')
159
+
160
+ subject.send(:get_protocol).must_equal '13546'
161
+ end
162
+ end
163
+
164
+ describe "#get_situation" do
165
+ context "deve buscar a situação a partir do caminho em situation_path" do
166
+ it "se encontrar a situação deve buscar formatar seu valor através do método #situation_key_values" do
167
+ subject.stubs(:savon_body).returns(:savon_body)
168
+ subject.stubs(:situation_path).returns(:situation_path)
169
+ subject.stubs(:path_with_root).with(:situation_path).returns([:path, :root])
170
+ subject.expects(:find_value_for_keys).with(:savon_body, [:path, :root]).returns('1').in_sequence(sequence_1)
171
+ subject.expects(:situation_key_values).returns({'1'=> :v1, '2'=> :v2}).in_sequence(sequence_1)
172
+ subject.send(:get_situation).must_equal :v1
173
+ end
174
+ it "se não encontrar a situação não deve buscar seu valor através do método #situation_key_values" do
175
+ subject.stubs(:savon_body).returns(:savon_body)
176
+ subject.stubs(:situation_path).returns(:situation_path)
177
+ subject.stubs(:path_with_root).with(:situation_path).returns([:path, :root])
178
+ subject.expects(:find_value_for_keys).with(:savon_body, [:path, :root]).returns('')
179
+ subject.expects(:situation_key_values).never
180
+ subject.send(:get_situation).must_equal ''
181
+ end
182
+ end
183
+ end
184
+
185
+ describe "#get_received_date" do
186
+ it "deve buscar a data de recebimento a partir do caminho em received_date_path" do
187
+ subject.stubs(:savon_body).returns(:savon_body)
188
+ subject.stubs(:received_date_path).returns(:received_date_path)
189
+ subject.stubs(:path_with_root).with(:received_date_path).returns([:path, :root])
190
+ subject.expects(:find_value_for_keys).with(:savon_body, [:path, :root]).returns('1')
191
+
192
+ subject.send(:get_received_date).must_equal '1'
193
+ end
194
+ end
195
+
196
+ describe "#get_lot_number" do
197
+ it "deve buscar o numero do lote a partir do caminho em lot_number_path" do
198
+ subject.stubs(:savon_body).returns(:savon_body)
199
+ subject.stubs(:lot_number_path).returns(:lot_number_path)
200
+ subject.stubs(:path_with_root).with(:lot_number_path).returns([:path, :root])
201
+ subject.expects(:find_value_for_keys).with(:savon_body, [:path, :root]).returns('777')
202
+
203
+ subject.send(:get_lot_number).must_equal '777'
204
+ end
205
+ end
206
+
207
+ describe "#get_cancelation_date_time" do
208
+ it "deve buscar o numero do lote a partir do caminho em cancelation_date_time_path" do
209
+ subject.stubs(:savon_body).returns(:savon_body)
210
+ subject.stubs(:cancelation_date_time_path).returns(:cancelation_date_time_path)
211
+ subject.stubs(:path_with_root).with(:cancelation_date_time_path).returns([:path, :root])
212
+ subject.expects(:find_value_for_keys).with(:savon_body, [:path, :root]).returns('777')
213
+
214
+ subject.send(:get_cancelation_date_time).must_equal '777'
215
+ end
216
+ end
217
+
218
+ describe "#instance_invoice" do
219
+ # Sim, sinto vergonha por ter feito um teste dessse ='(
220
+ it "deve simplesmente instanciar um NF a partir dos métodos e busca por atrubutos via hash e XML" do
221
+ invoice = BrNfe::Response::Service::NotaFiscal.new
222
+ subject.stubs(:get_xml_nf).returns('get_xml_nf')
223
+ subject.stubs(:invoice_numero_nf_path).returns(:invoice_numero_nf_path)
224
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_numero_nf_path).returns(:invoice_numero_nf_value)
225
+ subject.stubs(:invoice_codigo_verificacao_path).returns(:invoice_codigo_verificacao_path)
226
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_codigo_verificacao_path).returns(:invoice_codigo_verificacao_value)
227
+ subject.stubs(:invoice_data_emissao_path).returns(:invoice_data_emissao_path)
228
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_data_emissao_path).returns(:invoice_data_emissao_value)
229
+ subject.stubs(:invoice_url_nf_path).returns(:invoice_url_nf_path)
230
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_url_nf_path).returns(:invoice_url_nf_value)
231
+ subject.stubs(:invoice_rps_numero_path).returns(:invoice_rps_numero_path)
232
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_rps_numero_path).returns(:invoice_rps_numero_value)
233
+ subject.stubs(:invoice_rps_serie_path).returns(:invoice_rps_serie_path)
234
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_rps_serie_path).returns(:invoice_rps_serie_value)
235
+ subject.stubs(:invoice_rps_tipo_path).returns(:invoice_rps_tipo_path)
236
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_rps_tipo_path).returns(:invoice_rps_tipo_value)
237
+ subject.stubs(:invoice_rps_situacao_path).returns(:invoice_rps_situacao_path)
238
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_rps_situacao_path).returns(:invoice_rps_situacao_value)
239
+ subject.stubs(:invoice_rps_substituido_numero_path).returns(:invoice_rps_substituido_numero_path)
240
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_rps_substituido_numero_path).returns(:invoice_rps_substituido_numero_value)
241
+ subject.stubs(:invoice_rps_substituido_serie_path).returns(:invoice_rps_substituido_serie_path)
242
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_rps_substituido_serie_path).returns(:invoice_rps_substituido_serie_value)
243
+ subject.stubs(:invoice_rps_substituido_tipo_path).returns(:invoice_rps_substituido_tipo_path)
244
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_rps_substituido_tipo_path).returns(:invoice_rps_substituido_tipo_value)
245
+ subject.stubs(:invoice_data_emissao_rps_path).returns(:invoice_data_emissao_rps_path)
246
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_data_emissao_rps_path).returns(:invoice_data_emissao_rps_value)
247
+ subject.stubs(:invoice_competencia_path).returns(:invoice_competencia_path)
248
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_competencia_path).returns(:invoice_competencia_value)
249
+ subject.stubs(:invoice_outras_informacoes_path).returns(:invoice_outras_informacoes_path)
250
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_outras_informacoes_path).returns(:invoice_outras_informacoes_value)
251
+ subject.stubs(:invoice_item_lista_servico_path).returns(:invoice_item_lista_servico_path)
252
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_item_lista_servico_path).returns(:invoice_item_lista_servico_value)
253
+ subject.stubs(:invoice_cnae_code_path).returns(:invoice_cnae_code_path)
254
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_cnae_code_path).returns(:invoice_cnae_code_value)
255
+ subject.stubs(:invoice_description_path).returns(:invoice_description_path)
256
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_description_path).returns(:invoice_description_value)
257
+ subject.stubs(:invoice_codigo_municipio_path).returns(:invoice_codigo_municipio_path)
258
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_codigo_municipio_path).returns(:invoice_codigo_municipio_value)
259
+ subject.stubs(:invoice_total_services_path).returns(:invoice_total_services_path)
260
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_total_services_path).returns(:invoice_total_services_value)
261
+ subject.stubs(:invoice_deductions_path).returns(:invoice_deductions_path)
262
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_deductions_path).returns(:invoice_deductions_value)
263
+ subject.stubs(:invoice_valor_pis_path).returns(:invoice_valor_pis_path)
264
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_valor_pis_path).returns(:invoice_valor_pis_value)
265
+ subject.stubs(:invoice_valor_cofins_path).returns(:invoice_valor_cofins_path)
266
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_valor_cofins_path).returns(:invoice_valor_cofins_value)
267
+ subject.stubs(:invoice_valor_inss_path).returns(:invoice_valor_inss_path)
268
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_valor_inss_path).returns(:invoice_valor_inss_value)
269
+ subject.stubs(:invoice_valor_ir_path).returns(:invoice_valor_ir_path)
270
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_valor_ir_path).returns(:invoice_valor_ir_value)
271
+ subject.stubs(:invoice_valor_csll_path).returns(:invoice_valor_csll_path)
272
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_valor_csll_path).returns(:invoice_valor_csll_value)
273
+ subject.stubs(:invoice_iss_retained_path).returns(:invoice_iss_retained_path)
274
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_iss_retained_path).returns(:invoice_iss_retained_value)
275
+ subject.stubs(:invoice_outras_retencoes_path).returns(:invoice_outras_retencoes_path)
276
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_outras_retencoes_path).returns(:invoice_outras_retencoes_value)
277
+ subject.stubs(:invoice_total_iss_path).returns(:invoice_total_iss_path)
278
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_total_iss_path).returns(:invoice_total_iss_value)
279
+ subject.stubs(:invoice_base_calculation_path).returns(:invoice_base_calculation_path)
280
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_base_calculation_path).returns(:invoice_base_calculation_value)
281
+ subject.stubs(:invoice_iss_tax_rate_path).returns(:invoice_iss_tax_rate_path)
282
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_iss_tax_rate_path).returns(:invoice_iss_tax_rate_value)
283
+ subject.stubs(:invoice_valor_liquido_path).returns(:invoice_valor_liquido_path)
284
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_valor_liquido_path).returns(:invoice_valor_liquido_value)
285
+ subject.stubs(:invoice_desconto_condicionado_path).returns(:invoice_desconto_condicionado_path)
286
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_desconto_condicionado_path).returns(:invoice_desconto_condicionado_value)
287
+ subject.stubs(:invoice_desconto_incondicionado_path).returns(:invoice_desconto_incondicionado_path)
288
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_desconto_incondicionado_path).returns(:invoice_desconto_incondicionado_value)
289
+ subject.stubs(:invoice_responsavel_retencao_path).returns(:invoice_responsavel_retencao_path)
290
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_responsavel_retencao_path).returns(:invoice_responsavel_retencao_value)
291
+ subject.stubs(:invoice_numero_processo_path).returns(:invoice_numero_processo_path)
292
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_numero_processo_path).returns(:invoice_numero_processo_value)
293
+ subject.stubs(:invoice_municipio_incidencia_path).returns(:invoice_municipio_incidencia_path)
294
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_municipio_incidencia_path).returns(:invoice_municipio_incidencia_value)
295
+ subject.stubs(:invoice_orgao_gerador_municipio_path).returns(:invoice_orgao_gerador_municipio_path)
296
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_orgao_gerador_municipio_path).returns(:invoice_orgao_gerador_municipio_value)
297
+ subject.stubs(:invoice_orgao_gerador_uf_path).returns(:invoice_orgao_gerador_uf_path)
298
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_orgao_gerador_uf_path).returns(:invoice_orgao_gerador_uf_value)
299
+ subject.stubs(:invoice_cancelamento_codigo_path).returns(:invoice_cancelamento_codigo_path)
300
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_cancelamento_codigo_path).returns(:invoice_cancelamento_codigo_value)
301
+ subject.stubs(:invoice_cancelamento_numero_nf_path).returns(:invoice_cancelamento_numero_nf_path)
302
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_cancelamento_numero_nf_path).returns(:invoice_cancelamento_numero_nf_value)
303
+ subject.stubs(:invoice_cancelamento_cnpj_path).returns(:invoice_cancelamento_cnpj_path)
304
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_cancelamento_cnpj_path).returns(:invoice_cancelamento_cnpj_value)
305
+ subject.stubs(:invoice_cancelamento_inscricao_municipal_path).returns(:invoice_cancelamento_inscricao_municipal_path)
306
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_cancelamento_inscricao_municipal_path).returns(:invoice_cancelamento_inscricao_municipal_value)
307
+ subject.stubs(:invoice_cancelamento_municipio_path).returns(:invoice_cancelamento_municipio_path)
308
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_cancelamento_municipio_path).returns(:invoice_cancelamento_municipio_value)
309
+ subject.stubs(:invoice_cancelamento_sucesso_path).returns(:invoice_cancelamento_sucesso_path)
310
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_cancelamento_sucesso_path).returns(:invoice_cancelamento_sucesso_value)
311
+ subject.stubs(:invoice_cancelamento_data_hora_path).returns(:invoice_cancelamento_data_hora_path)
312
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_cancelamento_data_hora_path).returns(:invoice_cancelamento_data_hora_value)
313
+ subject.stubs(:invoice_nfe_substituidora_path).returns(:invoice_nfe_substituidora_path)
314
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_nfe_substituidora_path).returns(:invoice_nfe_substituidora_value)
315
+ subject.stubs(:invoice_codigo_obra_path).returns(:invoice_codigo_obra_path)
316
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_codigo_obra_path).returns(:invoice_codigo_obra_value)
317
+ subject.stubs(:invoice_codigo_art_path).returns(:invoice_codigo_art_path)
318
+ subject.stubs(:find_value_for_keys).with(:hash_nf, :invoice_codigo_art_path).returns(:invoice_codigo_art_value)
319
+
320
+ BrNfe::Response::Service::NotaFiscal.expects(:new).with({
321
+ xml_nf: 'get_xml_nf',
322
+ numero_nf: :invoice_numero_nf_value,
323
+ codigo_verificacao: :invoice_codigo_verificacao_value,
324
+ data_emissao: :invoice_data_emissao_value,
325
+ url_nf: :invoice_url_nf_value,
326
+ rps_numero: :invoice_rps_numero_value,
327
+ rps_serie: :invoice_rps_serie_value,
328
+ rps_tipo: :invoice_rps_tipo_value,
329
+ rps_situacao: :invoice_rps_situacao_value,
330
+ rps_substituido_numero: :invoice_rps_substituido_numero_value,
331
+ rps_substituido_serie: :invoice_rps_substituido_serie_value,
332
+ rps_substituido_tipo: :invoice_rps_substituido_tipo_value,
333
+ data_emissao_rps: :invoice_data_emissao_rps_value,
334
+ competencia: :invoice_competencia_value,
335
+ outras_informacoes: :invoice_outras_informacoes_value,
336
+ item_lista_servico: :invoice_item_lista_servico_value,
337
+ cnae_code: :invoice_cnae_code_value,
338
+ description: :invoice_description_value,
339
+ codigo_municipio: :invoice_codigo_municipio_value,
340
+ total_services: :invoice_total_services_value,
341
+ deductions: :invoice_deductions_value,
342
+ valor_pis: :invoice_valor_pis_value,
343
+ valor_cofins: :invoice_valor_cofins_value,
344
+ valor_inss: :invoice_valor_inss_value,
345
+ valor_ir: :invoice_valor_ir_value,
346
+ valor_csll: :invoice_valor_csll_value,
347
+ iss_retained: :invoice_iss_retained_value,
348
+ outras_retencoes: :invoice_outras_retencoes_value,
349
+ total_iss: :invoice_total_iss_value,
350
+ base_calculation: :invoice_base_calculation_value,
351
+ iss_tax_rate: :invoice_iss_tax_rate_value,
352
+ valor_liquido: :invoice_valor_liquido_value,
353
+ desconto_condicionado: :invoice_desconto_condicionado_value,
354
+ desconto_incondicionado: :invoice_desconto_incondicionado_value,
355
+ responsavel_retencao: :invoice_responsavel_retencao_value,
356
+ numero_processo: :invoice_numero_processo_value,
357
+ municipio_incidencia: :invoice_municipio_incidencia_value,
358
+ orgao_gerador_municipio: :invoice_orgao_gerador_municipio_value,
359
+ orgao_gerador_uf: :invoice_orgao_gerador_uf_value,
360
+ cancelamento_codigo: :invoice_cancelamento_codigo_value,
361
+ cancelamento_numero_nf: :invoice_cancelamento_numero_nf_value,
362
+ cancelamento_cnpj: :invoice_cancelamento_cnpj_value,
363
+ cancelamento_inscricao_municipal: :invoice_cancelamento_inscricao_municipal_value,
364
+ cancelamento_municipio: :invoice_cancelamento_municipio_value,
365
+ cancelamento_sucesso: :invoice_cancelamento_sucesso_value,
366
+ cancelamento_data_hora: :invoice_cancelamento_data_hora_value,
367
+ nfe_substituidora: :invoice_nfe_substituidora_value,
368
+ codigo_obra: :invoice_codigo_obra_value,
369
+ codigo_art: :invoice_codigo_art_value
370
+ }).returns(invoice)
371
+
372
+ subject.instance_invoice(:hash_nf).must_equal invoice
373
+ end
374
+ end
375
+ end
376
+
377
+ end
@@ -0,0 +1,218 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Response::Service::Default do
4
+ subject { FactoryGirl.build(:response_service_default) }
5
+
6
+
7
+ describe "#notas_fiscais" do
8
+ it "deve inicializar como um vetor vazio" do
9
+ subject.class.new.notas_fiscais.must_equal []
10
+ end
11
+
12
+ it "posso utilizar o << para adicionar valores" do
13
+ new_object = subject.class.new
14
+ new_object.notas_fiscais << 'x'
15
+ new_object.notas_fiscais << 'y'
16
+ new_object.notas_fiscais.must_equal ['x','y']
17
+ end
18
+
19
+ it "sempre retorna um array" do
20
+ subject.notas_fiscais = {valor: '2'}
21
+ subject.notas_fiscais.must_equal [{valor: '2'}]
22
+ end
23
+ end
24
+
25
+ describe "#error_messages" do
26
+ it "deve inicializar como um vetor vazio" do
27
+ subject.class.new.error_messages.must_equal []
28
+ end
29
+
30
+ it "posso utilizar o << para adicionar valores" do
31
+ new_object = subject.class.new
32
+ new_object.error_messages << 'aaa'
33
+ new_object.error_messages << 'bbbbb'
34
+ new_object.error_messages.must_equal ['aaa','bbbbb']
35
+ end
36
+
37
+ it "sempre retorna um array" do
38
+ subject.error_messages = {valor: '2'}
39
+ subject.error_messages.must_equal [{valor: '2'}]
40
+ end
41
+ end
42
+
43
+ describe "#success?" do
44
+ it "quando o status for igual a success deve retornar true" do
45
+ subject.status = :success
46
+ subject.success?.must_equal true
47
+ end
48
+
49
+ it "quando o status for diferente a success deve retornar false" do
50
+ subject.status = :other
51
+ subject.success?.must_equal false
52
+ end
53
+ end
54
+
55
+ describe "#status" do
56
+ it "se não houver valor na variável @status deve buscar e setar o valor em get_status" do
57
+ subject.status = nil
58
+ subject.expects(:get_status).returns(:new_status)
59
+
60
+ subject.status.must_equal :new_status
61
+ subject.instance_variable_get(:@status).must_equal :new_status
62
+ end
63
+ it "se houver valor na variável @status não deve buscar o valor em get_status" do
64
+ subject.status = :other_status
65
+ subject.expects(:get_status).never
66
+
67
+ subject.status.must_equal :other_status
68
+ subject.instance_variable_get(:@status).must_equal :other_status
69
+ end
70
+ end
71
+
72
+ describe "#get_status" do
73
+ it "se tiver alguma mensagem de erro deve retornar o status :falied" do
74
+ subject.error_messages << 'Message'
75
+ subject.get_status.must_equal :falied
76
+ end
77
+ it "se não tiver nenhuma mensagem de erro deve retornar o status :success" do
78
+ subject.error_messages = []
79
+ subject.get_status.must_equal :success
80
+ end
81
+ end
82
+
83
+ describe "#unsuccessful_request?" do
84
+ it "deve retornar true se o status for :soap_error" do
85
+ subject.status = :soap_error
86
+ subject.unsuccessful_request?.must_equal true
87
+ end
88
+ it "deve retornar true se o status for :http_error" do
89
+ subject.status = :http_error
90
+ subject.unsuccessful_request?.must_equal true
91
+ end
92
+ it "deve retornar true se o status for :unknown_error" do
93
+ subject.status = :unknown_error
94
+ subject.unsuccessful_request?.must_equal true
95
+ end
96
+ it "deve retornar false se o status for :success" do
97
+ subject.status = :success
98
+ subject.unsuccessful_request?.must_equal false
99
+ end
100
+ it "deve retornar false se o status for :falied" do
101
+ subject.status = :falied
102
+ subject.unsuccessful_request?.must_equal false
103
+ end
104
+ end
105
+
106
+ describe "#successful_request?" do
107
+ it "se unsuccessful_request? for false então deve retornar true" do
108
+ subject.expects(:unsuccessful_request?).returns(false)
109
+ subject.successful_request?.must_equal true
110
+ end
111
+ it "se unsuccessful_request? for true então deve retornar false" do
112
+ subject.expects(:unsuccessful_request?).returns(true)
113
+ subject.successful_request?.must_equal false
114
+ end
115
+ end
116
+
117
+ describe "#message_codes" do
118
+ it "deve retornar os códigos das mensagens de erro no formato de string" do
119
+ subject.expects(:error_messages).returns([
120
+ {code: 'CODE1', message: 'msg', solution: :solut},
121
+ {code: :CODE2, message: 'msg', solution: :solut},
122
+ {code: 3, message: 'msg', solution: :solut},
123
+ 'Mensage string'
124
+ ])
125
+ subject.message_codes.must_equal(['CODE1', 'CODE2', '3'])
126
+ end
127
+ it "se não houver mensagem de erro retorna um array vazio" do
128
+ subject.message_codes.must_equal([])
129
+ end
130
+ it "se a mensagem de erro for apenas strings deve retornar um array vazio" do
131
+ subject.expects(:error_messages).returns(['str1','str2'])
132
+ subject.message_codes.must_equal([])
133
+ end
134
+ end
135
+
136
+ describe 'array de erros que correspondem a determinadas situações do estado do RPS' do
137
+ describe '#situation_unreceived_code_errors' do
138
+ let(:default_codes) { ['E4'] }
139
+ it 'por padrão deve retornar os codigos padrões correspondente a sutiação unreceived' do
140
+ subject.situation_unreceived_code_errors.must_equal( default_codes )
141
+ end
142
+ it 'ao setar um valor deve acrescentar o valor padrão e não sobrescrever' do
143
+ subject.situation_unreceived_code_errors = [['code2','code3'],'code4']
144
+ subject.situation_unreceived_code_errors.must_equal( ['code2','code3','code4']+default_codes )
145
+ end
146
+ end
147
+
148
+ describe '#situation_unprocessed_code_errors' do
149
+ let(:default_codes) { ['E92'] }
150
+ it 'por padrão deve retornar os codigos padrões correspondente a sutiação unprocessed' do
151
+ subject.situation_unprocessed_code_errors.must_equal( default_codes )
152
+ end
153
+ it 'ao setar um valor deve acrescentar o valor padrão e não sobrescrever' do
154
+ subject.situation_unprocessed_code_errors = [['code2','code3'],'code4']
155
+ subject.situation_unprocessed_code_errors.must_equal( ['code2','code3','code4']+default_codes )
156
+ end
157
+ end
158
+
159
+ describe '#situation_success_code_errors' do
160
+ let(:default_codes) { [] }
161
+ it 'por padrão deve retornar os codigos padrões correspondente a sutiação success' do
162
+ subject.situation_success_code_errors.must_equal( default_codes )
163
+ end
164
+ it 'ao setar um valor deve acrescentar o valor padrão e não sobrescrever' do
165
+ subject.situation_success_code_errors = [['code2','code3'],'code4']
166
+ subject.situation_success_code_errors.must_equal( ['code2','code3','code4']+default_codes )
167
+ end
168
+ end
169
+ end
170
+
171
+ describe '#get_situation_by_message_codes' do
172
+ before do
173
+ subject.stubs(:message_codes).returns(['ERR1','ERR2'])
174
+ end
175
+ it "deve retornar :unreceived se alguma mensagem de erro estiver entre as mensagens do metodo situation_unreceived_code_errors" do
176
+ subject.situation_unreceived_code_errors = 'ERR1'
177
+ subject.get_situation_by_message_codes.must_equal :unreceived
178
+ end
179
+ it "deve retornar :unprocessed se alguma mensagem de erro estiver entre as mensagens do metodo situation_unprocessed_code_errors" do
180
+ subject.situation_unprocessed_code_errors = 'ERR1'
181
+ subject.get_situation_by_message_codes.must_equal :unprocessed
182
+ end
183
+ it "deve retornar :success se alguma mensagem de erro estiver entre as mensagens do metodo situation_success_code_errors" do
184
+ subject.situation_success_code_errors = 'ERR1'
185
+ subject.get_situation_by_message_codes.must_equal :success
186
+ end
187
+ it "deve retornar :error se o codigo não estiver presente em nenhum dos metodos com os codigos padrões" do
188
+ subject.get_situation_by_message_codes.must_equal :error
189
+ end
190
+ it "se não houver nenhuma mensagem de erro deve retornar nil" do
191
+ subject.unstub(:message_codes)
192
+ subject.get_situation_by_message_codes.must_be_nil
193
+ end
194
+ end
195
+
196
+ describe '#situation' do
197
+ it "se não houver setado uma situação e tiver alguma mensagem de erro deve buscar o valor da situação no metodo #get_situation_by_message_codes" do
198
+ subject.situation = nil
199
+ subject.stubs(:error_messages).returns(['a error'])
200
+ subject.expects(:get_situation_by_message_codes).returns(:sit)
201
+ subject.situation.must_equal :sit
202
+ subject.instance_variable_get(:@situation).must_equal :sit
203
+ end
204
+ it "se não houver setado uma situação e também não tiver mensagem de erro deve retornar nil" do
205
+ subject.situation = nil
206
+ subject.stubs(:error_messages).returns([])
207
+ subject.expects(:get_situation_by_message_codes).never
208
+ subject.situation.must_be_nil
209
+ end
210
+ it "mesmo com mensagem de erro se tiver algum valor na situação não deve tentar buscar a situação pelos codigos de erros" do
211
+ subject.situation = :some_value
212
+ subject.stubs(:error_messages).returns(['a error'])
213
+ subject.expects(:get_situation_by_message_codes).never
214
+ subject.situation.must_equal :some_value
215
+ end
216
+ end
217
+
218
+ end