br_nfe 2.1.0 → 2.1.1

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 +1 -0
  3. data/.travis.yml +0 -1
  4. data/Gemfile.lock +1 -1
  5. data/README.markdown +264 -106
  6. data/lib/br_nfe/{helper → association}/have_address.rb +1 -1
  7. data/lib/br_nfe/{helper → association}/have_condicao_pagamento.rb +1 -1
  8. data/lib/br_nfe/association/have_destinatario.rb +22 -0
  9. data/lib/br_nfe/association/have_emitente.rb +24 -0
  10. data/lib/br_nfe/base.rb +37 -27
  11. data/lib/br_nfe/condicao_pagamento.rb +2 -0
  12. data/lib/br_nfe/constants.rb +33 -0
  13. data/lib/br_nfe/endereco.rb +10 -0
  14. data/lib/br_nfe/helper/string_methods.rb +4 -0
  15. data/lib/br_nfe/{emitente.rb → person.rb} +11 -7
  16. data/lib/br_nfe/product/base.rb +82 -0
  17. data/lib/br_nfe/product/consulta_status_servico.rb +35 -0
  18. data/lib/br_nfe/product/emitente.rb +8 -0
  19. data/lib/br_nfe/product/gateway/base.rb +62 -0
  20. data/lib/br_nfe/product/gateway/web_service_svrs.rb +39 -0
  21. data/lib/br_nfe/product/value_nf.rb +9 -0
  22. data/lib/br_nfe/product/xml/soap_env.xml.slim +8 -0
  23. data/lib/br_nfe/product/xml/v3_10/XSD/consReciNFe_v3.10.xsd +9 -0
  24. data/lib/br_nfe/product/xml/v3_10/XSD/consSitNFe_v3.10.xsd +9 -0
  25. data/lib/br_nfe/product/xml/v3_10/XSD/consStatServ_v3.10.xsd +9 -0
  26. data/lib/br_nfe/product/xml/v3_10/XSD/enviNFe_v3.10.xsd +9 -0
  27. data/lib/br_nfe/product/xml/v3_10/XSD/inutNFe_v3.10.xsd +9 -0
  28. data/lib/br_nfe/product/xml/v3_10/XSD/leiauteConsSitNFe_v3.10.xsd +502 -0
  29. data/lib/br_nfe/product/xml/v3_10/XSD/leiauteConsStatServ_v3.10.xsd +98 -0
  30. data/lib/br_nfe/product/xml/v3_10/XSD/leiauteInutNFe_v3.10.xsd +193 -0
  31. data/lib/br_nfe/product/xml/v3_10/XSD/leiauteNFe_v3.10.xsd +6060 -0
  32. data/lib/br_nfe/product/xml/v3_10/XSD/nfe_v3.10.xsd +9 -0
  33. data/lib/br_nfe/product/xml/v3_10/XSD/procInutNFe_v3.10.xsd +9 -0
  34. data/lib/br_nfe/product/xml/v3_10/XSD/procNFe_v3.10.xsd +9 -0
  35. data/lib/br_nfe/product/xml/v3_10/XSD/retConsReciNFe_v3.10.xsd +9 -0
  36. data/lib/br_nfe/product/xml/v3_10/XSD/retConsSitNFe_v3.10.xsd +9 -0
  37. data/lib/br_nfe/product/xml/v3_10/XSD/retConsStatServ_v3.10.xsd +9 -0
  38. data/lib/br_nfe/product/xml/v3_10/XSD/retEnviNFe_v3.10.xsd +9 -0
  39. data/lib/br_nfe/product/xml/v3_10/XSD/retInutNFe_v3.10.xsd +9 -0
  40. data/lib/br_nfe/product/xml/v3_10/XSD/tiposBasico_v3.10.xsd +571 -0
  41. data/lib/br_nfe/product/xml/v3_10/XSD/xmldsig-core-schema_v1.01.xsd +98 -0
  42. data/lib/br_nfe/product/xml/v3_10/consulta_status_servico.xml.slim +4 -0
  43. data/lib/br_nfe/service/association/have_intermediario.rb +26 -0
  44. data/lib/br_nfe/service/association/have_rps.rb +36 -0
  45. data/lib/br_nfe/service/base.rb +24 -20
  46. data/lib/br_nfe/service/betha/v1/cancela_nfse.rb +43 -0
  47. data/lib/br_nfe/service/betha/v1/consulta_lote_rps.rb +20 -6
  48. data/lib/br_nfe/service/betha/v1/consulta_nfs_por_rps.rb +17 -6
  49. data/lib/br_nfe/service/betha/v1/consulta_nfse.rb +16 -5
  50. data/lib/br_nfe/service/betha/v1/consulta_situacao_lote_rps.rb +15 -6
  51. data/lib/br_nfe/service/betha/v1/gateway.rb +4 -0
  52. data/lib/br_nfe/service/betha/v1/recepcao_lote_rps.rb +13 -5
  53. data/lib/br_nfe/service/betha/v1/xml/_tc_identificacao_prestador.xml.slim +3 -0
  54. data/lib/br_nfe/service/betha/v1/xml/_tc_pedido_cancelamento.xml.slim +4 -0
  55. data/lib/br_nfe/service/concerns/rules/cancelamento_nfs.rb +8 -0
  56. data/lib/br_nfe/service/concerns/rules/consulta_nfs_por_rps.rb +1 -1
  57. data/lib/br_nfe/service/concerns/rules/consulta_nfse.rb +5 -2
  58. data/lib/br_nfe/service/concerns/values_ts/service_v1.rb +319 -0
  59. data/lib/br_nfe/service/destinatario.rb +7 -0
  60. data/lib/br_nfe/service/emitente.rb +8 -0
  61. data/lib/br_nfe/service/intermediario.rb +1 -12
  62. data/lib/br_nfe/service/item.rb +7 -7
  63. data/lib/br_nfe/service/response/build/base.rb +166 -0
  64. data/lib/br_nfe/service/response/build/cancelamento.rb +62 -0
  65. data/lib/br_nfe/service/response/build/consulta_lote_rps.rb +25 -0
  66. data/lib/br_nfe/service/response/build/consulta_nfs_por_rps.rb +25 -0
  67. data/lib/br_nfe/service/response/build/consulta_nfse.rb +24 -0
  68. data/lib/br_nfe/service/response/build/consulta_situacao_lote_rps.rb +56 -0
  69. data/lib/br_nfe/service/response/build/invoice_build.rb +359 -0
  70. data/lib/br_nfe/service/response/build/recepcao_lote_rps.rb +69 -0
  71. data/lib/br_nfe/service/response/cancelamento.rb +22 -0
  72. data/lib/br_nfe/service/response/consulta_lote_rps.rb +18 -0
  73. data/lib/br_nfe/service/response/consulta_nfs_por_rps.rb +10 -0
  74. data/lib/br_nfe/service/response/consulta_nfse.rb +10 -0
  75. data/lib/br_nfe/service/response/consulta_situacao_lote_rps.rb +74 -0
  76. data/lib/br_nfe/service/response/default.rb +93 -0
  77. data/lib/br_nfe/{response/service → service/response}/nota_fiscal.rb +19 -12
  78. data/lib/br_nfe/service/response/paths/v1/tc_nfse.rb +275 -0
  79. data/lib/br_nfe/service/response/recepcao_lote_rps.rb +35 -0
  80. data/lib/br_nfe/service/rps.rb +30 -27
  81. data/lib/br_nfe/service/sc/florianopolis/xml/_service_item.xml.slim +4 -4
  82. data/lib/br_nfe/service/sc/florianopolis/xml/inf_requisicao.xml.slim +4 -4
  83. data/lib/br_nfe/service/simpliss/v1/cancela_nfse.rb +16 -6
  84. data/lib/br_nfe/service/simpliss/v1/consulta_lote_rps.rb +20 -12
  85. data/lib/br_nfe/service/simpliss/v1/consulta_nfs_por_rps.rb +21 -6
  86. data/lib/br_nfe/service/simpliss/v1/consulta_nfse.rb +20 -6
  87. data/lib/br_nfe/service/simpliss/v1/consulta_situacao_lote_rps.rb +17 -6
  88. data/lib/br_nfe/service/simpliss/v1/recepcao_lote_rps.rb +16 -4
  89. data/lib/br_nfe/service/simpliss/v1/xml/_tc_item_servico.xml.slim +2 -2
  90. data/lib/br_nfe/service/thema/v1/cancela_nfse.rb +21 -19
  91. data/lib/br_nfe/service/thema/v1/consulta_lote_rps.rb +21 -19
  92. data/lib/br_nfe/service/thema/v1/consulta_nfs_por_rps.rb +25 -18
  93. data/lib/br_nfe/service/thema/v1/consulta_nfse.rb +20 -20
  94. data/lib/br_nfe/service/thema/v1/consulta_situacao_lote_rps.rb +14 -20
  95. data/lib/br_nfe/service/thema/v1/recepcao_lote_rps.rb +11 -16
  96. data/lib/br_nfe/service/thema/v1/recepcao_lote_rps_limitado.rb +8 -6
  97. data/lib/br_nfe/service/xml/v1/_tc_identificacao_nfse.xml.slim +1 -1
  98. data/lib/br_nfe/service/xml/v1/_tc_pedido_cancelamento.xml.slim +1 -1
  99. data/lib/br_nfe/service/xml/v1/_tc_valores.xml.slim +11 -11
  100. data/lib/br_nfe/version.rb +1 -1
  101. data/lib/br_nfe.rb +62 -62
  102. data/test/br_nfe/association/have_address_test.rb +64 -0
  103. data/test/br_nfe/association/have_condicao_pagamento_test.rb +75 -0
  104. data/test/br_nfe/association/have_destinatario_test.rb +76 -0
  105. data/test/br_nfe/association/have_emitente_test.rb +80 -0
  106. data/test/br_nfe/base_test.rb +96 -61
  107. data/test/br_nfe/endereco_test.rb +21 -0
  108. data/test/br_nfe/person_test.rb +55 -0
  109. data/test/br_nfe/product/base_test.rb +150 -0
  110. data/test/br_nfe/product/consulta_status_servico_test.rb +59 -0
  111. data/test/br_nfe/product/emitente_test.rb +29 -0
  112. data/test/br_nfe/product/gateway/base_test.rb +16 -0
  113. data/test/br_nfe/product/gateway/web_service_svrs_test.rb +36 -0
  114. data/test/br_nfe/service/association/have_intermediario_test.rb +80 -0
  115. data/test/br_nfe/service/association/have_rps_test.rb +62 -0
  116. data/test/br_nfe/service/base_test.rb +42 -42
  117. data/test/br_nfe/service/betha/v1/cancela_nfse_test.rb +90 -0
  118. data/test/br_nfe/service/betha/v1/consulta_lote_rps_test.rb +105 -5
  119. data/test/br_nfe/service/betha/v1/consulta_nfs_por_rps_test.rb +103 -5
  120. data/test/br_nfe/service/betha/v1/consulta_nfse_test.rb +114 -5
  121. data/test/br_nfe/service/betha/v1/consulta_situacao_lote_rps_test.rb +118 -5
  122. data/test/br_nfe/service/betha/v1/gateway_test.rb +1 -1
  123. data/test/br_nfe/service/betha/v1/recepcao_lote_rps_test.rb +51 -5
  124. data/test/br_nfe/service/concerns/rules/cancelamento_nfs_test.rb +2 -2
  125. data/test/br_nfe/service/concerns/rules/consulta_nfs_por_rps_test.rb +2 -7
  126. data/test/br_nfe/service/concerns/rules/consulta_nfse_test.rb +24 -3
  127. data/test/br_nfe/service/concerns/rules/recepcao_lote_rps_test.rb +1 -1
  128. data/test/br_nfe/{helper → service/concerns}/values_ts/service_v1_test.rb +2 -2
  129. data/test/br_nfe/{destinatario_test.rb → service/destinatario_test.rb} +3 -4
  130. data/test/br_nfe/service/emitente_test.rb +29 -0
  131. data/test/br_nfe/service/item_test.rb +14 -14
  132. data/test/br_nfe/service/response/build/base_test.rb +80 -0
  133. data/test/br_nfe/{response/service → service/response}/default_test.rb +1 -82
  134. data/test/br_nfe/service/response/nota_fiscal_test.rb +59 -0
  135. data/test/br_nfe/{response/service → service/response}/paths/v1/tc_nfse_test.rb +10 -10
  136. data/test/br_nfe/service/rps_test.rb +107 -138
  137. data/test/br_nfe/service/sc/florianopolis/emission_rps_test.rb +9 -9
  138. data/test/br_nfe/service/simpliss/v1/base_test.rb +1 -1
  139. data/test/br_nfe/service/simpliss/v1/cancela_nfse_test.rb +7 -10
  140. data/test/br_nfe/service/simpliss/v1/consulta_lote_rps_test.rb +11 -18
  141. data/test/br_nfe/service/simpliss/v1/consulta_nfs_por_rps_test.rb +11 -18
  142. data/test/br_nfe/service/simpliss/v1/consulta_nfse_test.rb +11 -18
  143. data/test/br_nfe/service/simpliss/v1/consulta_situacao_lote_rps_test.rb +7 -11
  144. data/test/br_nfe/service/simpliss/v1/recepcao_lote_rps_test.rb +3 -9
  145. data/test/br_nfe/service/thema/v1/base_test.rb +1 -1
  146. data/test/br_nfe/service/thema/v1/cancela_nfse_test.rb +7 -14
  147. data/test/br_nfe/service/thema/v1/consulta_lote_rps_test.rb +6 -17
  148. data/test/br_nfe/service/thema/v1/consulta_nfs_por_rps_test.rb +6 -13
  149. data/test/br_nfe/service/thema/v1/consulta_nfse_test.rb +11 -18
  150. data/test/br_nfe/service/thema/v1/consulta_situacao_lote_rps_test.rb +7 -11
  151. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_limitado_test.rb +1 -5
  152. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_test.rb +3 -9
  153. data/test/factories/base.rb +0 -1
  154. data/test/factories/{emitente.rb → person.rb} +1 -1
  155. data/test/factories/product/base.rb +12 -0
  156. data/test/factories/product/consulta_status_servico.rb +12 -0
  157. data/test/factories/product/emitente.rb +15 -0
  158. data/test/factories/product/gateway/base.rb +5 -0
  159. data/test/factories/product/gateway/web_service_svrs.rb +5 -0
  160. data/test/factories/service/betha/v1/{cancelamento_nfs.rb → cancela_nfse.rb} +2 -1
  161. data/test/factories/service/betha/v1/consulta_lote_rps.rb +1 -1
  162. data/test/factories/service/betha/v1/consulta_nfs_por_rps.rb +1 -1
  163. data/test/factories/service/betha/v1/consulta_nfse.rb +1 -1
  164. data/test/factories/service/betha/v1/consulta_situacao_lote_rps.rb +1 -1
  165. data/test/factories/{destinatario.rb → service/destinatario.rb} +1 -1
  166. data/test/factories/service/emitente.rb +15 -0
  167. data/test/factories/service/item.rb +4 -4
  168. data/test/factories/service/response/build_response.rb +5 -0
  169. data/test/factories/service/response/default.rb +6 -0
  170. data/test/factories/{response/service → service/response}/nota_fiscal.rb +8 -8
  171. data/test/factories/service/rps.rb +11 -11
  172. data/test/factories/service/sc/florianopolis/base.rb +1 -1
  173. data/test/factories/service/sc/florianopolis/cancellation.rb +1 -1
  174. data/test/factories/service/sc/florianopolis/emission_rps.rb +1 -1
  175. data/test/factories/service/simpliss/v1/base.rb +1 -1
  176. data/test/factories/service/simpliss/v1/cancela_nfse.rb +1 -1
  177. data/test/factories/service/simpliss/v1/consulta_lote_rps.rb +1 -1
  178. data/test/factories/service/simpliss/v1/consulta_nfs_por_rps.rb +1 -1
  179. data/test/factories/service/simpliss/v1/consulta_nfse.rb +1 -1
  180. data/test/factories/service/simpliss/v1/consulta_situacao_lote_rps.rb +1 -1
  181. data/test/factories/service/simpliss/v1/recepcao_lote_rps.rb +1 -1
  182. data/test/factories/service/thema/v1/base.rb +1 -1
  183. data/test/factories/service/thema/v1/cancela_nfse.rb +1 -1
  184. data/test/factories/service/thema/v1/consulta_lote_rps.rb +1 -1
  185. data/test/factories/service/thema/v1/consulta_nfs_por_rps.rb +1 -1
  186. data/test/factories/service/thema/v1/consulta_nfse.rb +1 -1
  187. data/test/factories/service/thema/v1/consulta_situacao_lote_rps.rb +1 -1
  188. data/test/factories/service/thema/v1/recepcao_lote_rps.rb +1 -1
  189. data/test/fixtures/service/response/betha/v1/cancela_nfse/fault.xml +17 -0
  190. data/test/fixtures/service/response/betha/v1/cancela_nfse/success.xml +48 -0
  191. data/test/fixtures/service/response/betha/v1/consulta_lote_rps/fault.xml +18 -0
  192. data/test/fixtures/service/response/betha/v1/consulta_lote_rps/success.xml +108 -0
  193. data/test/fixtures/service/response/betha/v1/consulta_nfse/fault.xml +18 -0
  194. data/test/fixtures/service/response/betha/v1/consulta_nfse/nfs_empty.xml +12 -0
  195. data/test/fixtures/service/response/betha/v1/consulta_nfse/success.xml +115 -0
  196. data/test/fixtures/service/response/betha/v1/consulta_nfse_por_rps/fault.xml +18 -0
  197. data/test/fixtures/service/response/betha/v1/consulta_nfse_por_rps/success.xml +103 -0
  198. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/error.xml +13 -0
  199. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/fault.xml +17 -0
  200. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/success.xml +13 -0
  201. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unprocessed.xml +13 -0
  202. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unprocessed_by_code_error.xml +17 -0
  203. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unreceived.xml +13 -0
  204. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unreceived_by_code_error.xml +17 -0
  205. data/test/fixtures/service/response/betha/v1/recepcao_lote_rps/error.xml +17 -0
  206. data/test/fixtures/service/response/betha/v1/recepcao_lote_rps/success.xml +14 -0
  207. metadata +160 -94
  208. data/lib/br_nfe/destinatario.rb +0 -26
  209. data/lib/br_nfe/helper/have_destinatario.rb +0 -18
  210. data/lib/br_nfe/helper/have_emitente.rb +0 -20
  211. data/lib/br_nfe/helper/have_intermediario.rb +0 -24
  212. data/lib/br_nfe/helper/have_rps.rb +0 -34
  213. data/lib/br_nfe/helper/values_ts/service_v1.rb +0 -317
  214. data/lib/br_nfe/response/service/build_response.rb +0 -463
  215. data/lib/br_nfe/response/service/default.rb +0 -185
  216. data/lib/br_nfe/response/service/paths/base.rb +0 -127
  217. data/lib/br_nfe/response/service/paths/v1/servico_cancelar_nfse_resposta.rb +0 -22
  218. data/lib/br_nfe/response/service/paths/v1/servico_consultar_lote_rps_resposta.rb +0 -25
  219. data/lib/br_nfe/response/service/paths/v1/servico_consultar_nfse_resposta.rb +0 -25
  220. data/lib/br_nfe/response/service/paths/v1/servico_consultar_nfse_rps_resposta.rb +0 -25
  221. data/lib/br_nfe/response/service/paths/v1/servico_consultar_situacao_lote_rps_resposta.rb +0 -31
  222. data/lib/br_nfe/response/service/paths/v1/servico_enviar_lote_rps_resposta.rb +0 -36
  223. data/lib/br_nfe/response/service/paths/v1/tc_nfse.rb +0 -271
  224. data/lib/br_nfe/service/betha/v1/cancelamento_nfs.rb +0 -36
  225. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_lote_rps_resposta.rb +0 -23
  226. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_resposta.rb +0 -21
  227. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +0 -21
  228. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_cancelar_nfse_resposta.rb +0 -22
  229. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_lote_rps_resposta.rb +0 -25
  230. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_nfse_resposta.rb +0 -25
  231. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +0 -25
  232. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_situacao_lote_rps_resposta.rb +0 -31
  233. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_enviar_lote_rps_resposta.rb +0 -36
  234. data/lib/br_nfe/service/thema/v1/response_paths/servico_cancelar_nfse_resposta.rb +0 -17
  235. data/lib/br_nfe/service/thema/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +0 -19
  236. data/test/br_nfe/emitente_test.rb +0 -46
  237. data/test/br_nfe/helper/have_address_test.rb +0 -62
  238. data/test/br_nfe/helper/have_condicao_pagamento_test.rb +0 -71
  239. data/test/br_nfe/helper/have_destinatario_test.rb +0 -64
  240. data/test/br_nfe/helper/have_emitente_test.rb +0 -63
  241. data/test/br_nfe/helper/have_intermediario_test.rb +0 -77
  242. data/test/br_nfe/helper/have_rps_test.rb +0 -59
  243. data/test/br_nfe/response/service/build_response_test.rb +0 -205
  244. data/test/br_nfe/response/service/nota_fiscal_test.rb +0 -41
  245. data/test/br_nfe/response/service/paths/base_test.rb +0 -196
  246. data/test/br_nfe/response/service/paths/v1/servico_cancelar_nfse_resposta_test.rb +0 -25
  247. data/test/br_nfe/response/service/paths/v1/servico_consultar_lote_rps_resposta_test.rb +0 -30
  248. data/test/br_nfe/response/service/paths/v1/servico_consultar_nfse_resposta_test.rb +0 -30
  249. data/test/br_nfe/response/service/paths/v1/servico_consultar_nfse_rps_resposta_test.rb +0 -30
  250. data/test/br_nfe/response/service/paths/v1/servico_consultar_situacao_lote_rps_resposta_test.rb +0 -30
  251. data/test/br_nfe/response/service/paths/v1/servico_enviar_lote_rps_resposta_test.rb +0 -34
  252. data/test/br_nfe/service/betha/v1/cancelamento_nfs_test.rb +0 -54
  253. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_lote_rps_resposta_test.rb +0 -16
  254. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_resposta_test.rb +0 -16
  255. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_rps_resposta_test.rb +0 -16
  256. data/test/factories/response/service/build_response.rb +0 -5
  257. data/test/factories/response/service/default.rb +0 -10
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  describe BrNfe::Service::Betha::V1::ConsultaNfse do
4
4
  subject { FactoryGirl.build(:servico_betha_consulta_nfse, emitente: emitente) }
5
- let(:emitente) { FactoryGirl.build(:emitente) }
5
+ let(:emitente) { FactoryGirl.build(:service_emitente) }
6
6
 
7
7
  describe "superclass" do
8
8
  it { subject.class.superclass.must_equal BrNfe::Service::Betha::V1::Gateway }
@@ -28,10 +28,6 @@ describe BrNfe::Service::Betha::V1::ConsultaNfse do
28
28
  it { subject.method_wsdl.must_equal :consultar_nfse_envio }
29
29
  end
30
30
 
31
- it "#response_root_path" do
32
- subject.response_root_path.must_equal [:consultar_nfse_envio_response]
33
- end
34
-
35
31
  describe "Validação do XML através do XSD" do
36
32
  let(:schemas_dir) { BrNfe.root+'/test/br_nfe/service/betha/v1/xsd' }
37
33
 
@@ -46,4 +42,117 @@ describe BrNfe::Service::Betha::V1::ConsultaNfse do
46
42
  end
47
43
  end
48
44
  end
45
+
46
+ it "não deve adicionar a tag InscricaoMunicipal no XML" do
47
+ # Se emitir uma NFS com InscricaoMunicipal 1234 e no cadastro da prefeitura
48
+ # a InscricaoMunicipal estiver cadastrada como 123-4, a nota vai emitir porém
49
+ # no momento de consultar da erro dizendo que a inscrição municipal não existe
50
+ # para o municipio.
51
+ subject.emitente.inscricao_municipal = '12345'
52
+ subject.emitente.cpf_cnpj = '12345678901234'
53
+ content_xml = Nori.new.parse(subject.content_xml).deep_transform_keys!{|k| k.to_s.underscore.to_sym}
54
+ prestador = content_xml[:'ns1:consultar_nfse_envio'][:prestador]
55
+
56
+ prestador[:cnpj].must_equal '12345678901234'
57
+ prestador[:inscricao_municipal].must_be_nil
58
+ end
59
+
60
+ describe "#request and set response" do
61
+ before { savon.mock! }
62
+ after { savon.unmock! }
63
+
64
+ it "Se não encontrar nenhuma NFe" do
65
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/betha/v1/consulta_nfse/nfs_empty.xml')
66
+ savon.expects(:consultar_nfse_envio).returns(fixture)
67
+ subject.request
68
+ response = subject.response
69
+
70
+ response.notas_fiscais.must_be_empty
71
+ response.status.must_equal :success
72
+ response.successful_request?.must_equal true
73
+ end
74
+
75
+ it "Quando a requisição voltar com erro deve setar os erros corretamente" do
76
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/betha/v1/consulta_nfse/fault.xml')
77
+
78
+ savon.expects(:consultar_nfse_envio).returns(fixture)
79
+ subject.request
80
+ response = subject.response
81
+
82
+ response.status.must_equal :falied
83
+ response.error_messages.size.must_equal 1
84
+ response.error_messages[0][:code].must_equal 'E160'
85
+ response.error_messages[0][:message].must_equal 'Arquivo enviado fora da estrutura do arquivo XML de entrada.'
86
+ response.error_messages[0][:solution].must_equal 'Envie um arquivo dentro do schema do arquivo XML de entrada.'
87
+ response.successful_request?.must_equal true
88
+ end
89
+
90
+ it "Quando encontrar uma nota fiscal com as informações básicas preenchidas" do
91
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/betha/v1/consulta_nfse/success.xml')
92
+ savon.expects(:consultar_nfse_envio).returns(fixture)
93
+ subject.request
94
+ response = subject.response
95
+
96
+ response.notas_fiscais.size.must_equal 1
97
+ response.status.must_equal :success
98
+ response.successful_request?.must_equal true
99
+
100
+ nf = response.notas_fiscais[0]
101
+ nf.numero_nf.must_equal '55'
102
+ nf.codigo_verificacao.must_equal 'F0O08ZQ2M'
103
+ nf.data_emissao.must_equal DateTime.parse('2013-12-17T21:39:57.630-02:00')
104
+ nf.url_nf.must_equal 'http://e-gov.betha.com.br/e-nota/visualizarnotaeletronica?id=tQ12313131=='
105
+ nf.xml_nf[0..89].must_equal '<ConsultarNfseResposta><ListaNfse><ComplNfse><Nfse><InfNfse><Numero>55</Numero><CodigoVeri'
106
+ nf.rps_numero.must_equal '22'
107
+ nf.rps_serie.must_equal 'SN'
108
+ nf.rps_tipo.must_equal '1'
109
+ nf.rps_situacao.must_be_nil
110
+ nf.rps_substituido_numero.must_be_nil
111
+ nf.rps_substituido_serie.must_be_nil
112
+ nf.rps_substituido_tipo.must_be_nil
113
+ nf.data_emissao_rps.must_equal DateTime.parse('2013-12-17T00:00:00-02:00')
114
+ nf.competencia.must_equal DateTime.parse('2013-12-01T00:00:00-02:00')
115
+ nf.natureza_operacao.must_equal '1'
116
+ nf.regime_especial_tributacao.must_be_nil
117
+ nf.optante_simples_nacional.must_equal '1'
118
+ nf.incentivador_cultural.must_be_nil
119
+ nf.outras_informacoes.must_equal 'http://e-gov.betha.com.br/e-nota/visualizarnotaeletronica?id=tQ12313131=='
120
+ nf.item_lista_servico.must_equal '0102'
121
+ nf.cnae_code.must_equal '6202300'
122
+ nf.description.must_equal 'Descrição: 1 Video Institucional. 1.600,00'
123
+ nf.codigo_municipio.must_equal '4204202'
124
+ nf.valor_total_servicos.must_equal '1600'
125
+ nf.iss_retido.must_equal '2'
126
+ nf.total_iss.must_equal '0'
127
+ nf.base_calculo.must_equal '1600'
128
+ nf.iss_aliquota.must_equal '2'
129
+ nf.valor_liquido.must_equal '1600'
130
+ nf.deducoes.must_equal '0'
131
+ nf.valor_pis.must_equal '0.00'
132
+ nf.valor_cofins.must_equal '0.00'
133
+ nf.valor_inss.must_equal '0.00'
134
+ nf.valor_ir.must_equal '0.00'
135
+ nf.valor_csll.must_equal '0.00'
136
+ nf.outras_retencoes.must_be_nil
137
+ nf.desconto_condicionado.must_equal '0'
138
+ nf.desconto_incondicionado.must_equal '0'
139
+ nf.responsavel_retencao.must_be_nil
140
+ nf.numero_processo.must_be_nil
141
+ nf.municipio_incidencia.must_be_nil
142
+ nf.orgao_gerador_municipio.must_equal '4204202'
143
+ nf.orgao_gerador_uf.must_equal 'SC'
144
+ nf.cancelamento_codigo.must_be_nil
145
+ nf.cancelamento_numero_nf.must_be_nil
146
+ nf.cancelamento_cnpj.must_be_nil
147
+ nf.cancelamento_inscricao_municipal.must_be_nil
148
+ nf.cancelamento_municipio.must_be_nil
149
+ nf.cancelamento_sucesso.must_equal false
150
+ nf.cancelamento_data_hora.must_be_nil
151
+ nf.nfe_substituidora.must_be_nil
152
+ nf.codigo_obra.must_be_nil
153
+ nf.codigo_art.must_be_nil
154
+
155
+ nf.destinatario.cpf_cnpj.must_equal '22222222222222'
156
+ end
157
+ end
49
158
  end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  describe BrNfe::Service::Betha::V1::ConsultaSituacaoLoteRps do
4
4
  subject { FactoryGirl.build(:servico_betha_consulta_situacao_lote_rps, emitente: emitente) }
5
- let(:emitente) { FactoryGirl.build(:emitente) }
5
+ let(:emitente) { FactoryGirl.build(:service_emitente) }
6
6
 
7
7
  describe "superclass" do
8
8
  it { subject.class.superclass.must_equal BrNfe::Service::Betha::V1::ConsultaLoteRps }
@@ -24,10 +24,6 @@ describe BrNfe::Service::Betha::V1::ConsultaSituacaoLoteRps do
24
24
  it { subject.method_wsdl.must_equal :consultar_situacao_lote_rps_envio }
25
25
  end
26
26
 
27
- it "#response_root_path" do
28
- subject.response_root_path.must_equal [:consultar_situacao_lote_rps_envio_response]
29
- end
30
-
31
27
  describe "Validação do XML através do XSD" do
32
28
  let(:schemas_dir) { BrNfe.root+'/test/br_nfe/service/betha/v1/xsd' }
33
29
 
@@ -42,4 +38,121 @@ describe BrNfe::Service::Betha::V1::ConsultaSituacaoLoteRps do
42
38
  end
43
39
  end
44
40
  end
41
+
42
+ it "não deve adicionar a tag InscricaoMunicipal no XML" do
43
+ # Se emitir uma NFS com InscricaoMunicipal 1234 e no cadastro da prefeitura
44
+ # a InscricaoMunicipal estiver cadastrada como 123-4, a nota vai emitir porém
45
+ # no momento de consultar da erro dizendo que a inscrição municipal não existe
46
+ # para o municipio.
47
+ subject.emitente.inscricao_municipal = '12345'
48
+ subject.emitente.cpf_cnpj = '12345678901234'
49
+ content_xml = Nori.new.parse(subject.content_xml).deep_transform_keys!{|k| k.to_s.underscore.to_sym}
50
+ prestador = content_xml[:'ns1:consultar_situacao_lote_rps_envio'][:prestador]
51
+
52
+ prestador[:cnpj].must_equal '12345678901234'
53
+ prestador[:inscricao_municipal].must_be_nil
54
+ end
55
+
56
+ describe "#request and set response" do
57
+ before { savon.mock! }
58
+ after { savon.unmock! }
59
+
60
+ it "Quando processou o RPS com sucesso deve setar a situation com :success" do
61
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/success.xml')
62
+ savon.expects(:consultar_situacao_lote_rps_envio).returns(fixture)
63
+ subject.request
64
+ response = subject.response
65
+
66
+ response.must_be_kind_of BrNfe::Service::Response::ConsultaSituacaoLoteRps
67
+ response.situation.must_equal :success
68
+ response.numero_lote.must_equal '10'
69
+ response.status.must_equal :success
70
+ response.successful_request?.must_equal true
71
+ end
72
+
73
+ it "Quando processou o RPS com erros deve setar a situation com :error" do
74
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/error.xml')
75
+ savon.expects(:consultar_situacao_lote_rps_envio).returns(fixture)
76
+ subject.request
77
+ response = subject.response
78
+
79
+ response.must_be_kind_of BrNfe::Service::Response::ConsultaSituacaoLoteRps
80
+ response.situation.must_equal :error
81
+ response.numero_lote.must_equal '13'
82
+ response.status.must_equal :success
83
+ response.successful_request?.must_equal true
84
+ end
85
+
86
+ it "Quando não processou o RPS deve setar a situation com :unprocessed" do
87
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unprocessed.xml')
88
+ savon.expects(:consultar_situacao_lote_rps_envio).returns(fixture)
89
+ subject.request
90
+ response = subject.response
91
+
92
+ response.must_be_kind_of BrNfe::Service::Response::ConsultaSituacaoLoteRps
93
+ response.situation.must_equal :unprocessed
94
+ response.numero_lote.must_equal '11'
95
+ response.status.must_equal :success
96
+ response.successful_request?.must_equal true
97
+ end
98
+
99
+ it "Quando não encontrar o RPS deve setar a situation com :unreceived" do
100
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unreceived.xml')
101
+ savon.expects(:consultar_situacao_lote_rps_envio).returns(fixture)
102
+ subject.request
103
+ response = subject.response
104
+
105
+ response.must_be_kind_of BrNfe::Service::Response::ConsultaSituacaoLoteRps
106
+ response.situation.must_equal :unreceived
107
+ response.numero_lote.must_equal '12'
108
+ response.status.must_equal :success
109
+ response.successful_request?.must_equal true
110
+ end
111
+
112
+ it "Quando a requisição voltar com erro deve setar os erros corretamente" do
113
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/fault.xml')
114
+
115
+ savon.expects(:consultar_situacao_lote_rps_envio).returns(fixture)
116
+ subject.request
117
+ response = subject.response
118
+
119
+ response.must_be_kind_of BrNfe::Service::Response::ConsultaSituacaoLoteRps
120
+ response.numero_lote.must_be_nil
121
+ response.situation.must_equal :error
122
+ response.status.must_equal :falied
123
+ response.error_messages.size.must_equal 1
124
+ response.error_messages[0][:code].must_equal 'E86'
125
+ response.error_messages[0][:message].must_equal 'Número do protocolo de recebimento do lote inexistente na base de dados.'
126
+ response.error_messages[0][:solution].must_equal 'Confira se o lote foi enviado e informe o número correto do protocolo de recebimento.'
127
+ response.successful_request?.must_equal true
128
+ end
129
+
130
+ it "Quando a requisição voltar com erro E4 deve definir a situação como unreceived" do
131
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unreceived_by_code_error.xml')
132
+
133
+ savon.expects(:consultar_situacao_lote_rps_envio).returns(fixture)
134
+ subject.request
135
+ response = subject.response
136
+
137
+ response.must_be_kind_of BrNfe::Service::Response::ConsultaSituacaoLoteRps
138
+ response.situation.must_equal :unreceived
139
+ response.numero_lote.must_be_nil
140
+ response.status.must_equal :falied
141
+ response.successful_request?.must_equal true
142
+ end
143
+
144
+ it "Quando a requisição voltar com erro E92 deve definir a situação como unprocessed" do
145
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unprocessed_by_code_error.xml')
146
+
147
+ savon.expects(:consultar_situacao_lote_rps_envio).returns(fixture)
148
+ subject.request
149
+ response = subject.response
150
+
151
+ response.must_be_kind_of BrNfe::Service::Response::ConsultaSituacaoLoteRps
152
+ response.situation.must_equal :unprocessed
153
+ response.numero_lote.must_be_nil
154
+ response.status.must_equal :falied
155
+ response.successful_request?.must_equal true
156
+ end
157
+ end
45
158
  end
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  describe BrNfe::Service::Betha::V1::Gateway do
4
4
  subject { FactoryGirl.build(:br_nfe_servico_betha_v1_gateway, emitente: emitente) }
5
5
  let(:rps) { FactoryGirl.build(:br_nfe_rps, :completo) }
6
- let(:emitente) { FactoryGirl.build(:emitente) }
6
+ let(:emitente) { FactoryGirl.build(:service_emitente) }
7
7
  let(:intermediario) { FactoryGirl.build(:intermediario) }
8
8
 
9
9
  describe "inheritance class" do
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  describe BrNfe::Service::Betha::V1::RecepcaoLoteRps do
4
4
  subject { FactoryGirl.build(:br_nfe_servico_betha_recepcao_lote_rps, emitente: emitente) }
5
- let(:emitente) { FactoryGirl.build(:emitente) }
5
+ let(:emitente) { FactoryGirl.build(:service_emitente) }
6
6
  let(:rps_1) { FactoryGirl.build(:br_nfe_rps, valor_pis: '', valor_cofins: nil, valor_inss: nil, valor_ir: nil, valor_csll: nil) }
7
7
  let(:rps_2) { FactoryGirl.build(:br_nfe_rps, :completo) }
8
8
 
@@ -44,10 +44,6 @@ describe BrNfe::Service::Betha::V1::RecepcaoLoteRps do
44
44
  it { subject.method_wsdl.must_equal :enviar_lote_rps_envio }
45
45
  end
46
46
 
47
- it "#response_root_path" do
48
- subject.response_root_path.must_equal [:enviar_lote_rps_envio_response]
49
- end
50
-
51
47
  describe "Validação do XML através do XSD" do
52
48
  let(:rps_basico) { FactoryGirl.build(:br_nfe_rps) }
53
49
  let(:rps_completo) { FactoryGirl.build(:br_nfe_rps, :completo) }
@@ -76,5 +72,55 @@ describe BrNfe::Service::Betha::V1::RecepcaoLoteRps do
76
72
  end
77
73
  end
78
74
 
75
+ it "Deve adicionar a tag InscricaoMunicipal no XML" do
76
+ subject.lote_rps = [rps_1]
77
+ # Esse test foi feito devido a sobrescrita do XML _tc_identificacao_prestador
78
+ subject.emitente.inscricao_municipal = '12345'
79
+ subject.emitente.cpf_cnpj = '12345678901234'
80
+ content_xml = Nori.new.parse(subject.content_xml).deep_transform_keys!{|k| k.to_s.underscore.to_sym}
81
+ prestador = content_xml[:'ns1:enviar_lote_rps_envio'][:lote_rps][:lista_rps][:rps][:inf_rps][:prestador]
82
+
83
+ prestador[:cnpj].must_equal '12345678901234'
84
+ prestador[:inscricao_municipal].must_equal '12345'
85
+ end
86
+
87
+ describe "#request and set response" do
88
+ before { savon.mock! }
89
+ after { savon.unmock! }
90
+
91
+ it "Quando gravou o RPS com sucesso deve setar seus valores corretamente na resposta" do
92
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/betha/v1/recepcao_lote_rps/success.xml')
93
+
94
+ savon.expects(:enviar_lote_rps_envio).returns(fixture)
95
+ subject.request
96
+ response = subject.response
97
+
98
+ response.must_be_kind_of BrNfe::Service::Response::RecepcaoLoteRps
99
+ response.protocolo.must_equal '925721130413341'
100
+ response.data_recebimento.must_equal Time.parse('2016-09-22T18:11:20.310-03:00')
101
+ response.numero_lote.must_equal '1'
102
+ response.status.must_equal :success
103
+ response.successful_request?.must_equal true
104
+ end
105
+
106
+ it "Quando a requisição voltar com erro deve setar os erros corretamente" do
107
+ fixture = File.read(BrNfe.root+'/test/fixtures/service/response/betha/v1/recepcao_lote_rps/error.xml')
108
+
109
+ savon.expects(:enviar_lote_rps_envio).returns(fixture)
110
+ subject.request
111
+ response = subject.response
112
+
113
+ response.must_be_kind_of BrNfe::Service::Response::RecepcaoLoteRps
114
+ response.protocolo.must_be_nil
115
+ response.data_recebimento.must_be_nil
116
+ response.numero_lote.must_be_nil
117
+ response.status.must_equal :falied
118
+ response.error_messages.size.must_equal 1
119
+ response.error_messages[0][:code].must_equal 'E44'
120
+ response.error_messages[0][:message].must_equal 'CNPJ do prestador inválido'
121
+ response.error_messages[0][:solution].must_equal 'Informe o número do CNPJ correto do prestador.'
122
+ response.successful_request?.must_equal true
123
+ end
124
+ end
79
125
 
80
126
  end
@@ -6,10 +6,10 @@ end
6
6
 
7
7
  describe BrNfe::Service::Concerns::Rules::CancelamentoNfs do
8
8
  subject { RuleCancelamentoNfsTest.new(nfe_number: 1254, codigo_cancelamento: 1, emitente: emitente) }
9
- let(:emitente) { FactoryGirl.build(:emitente, endereco: endereco) }
9
+ let(:emitente) { FactoryGirl.build(:service_emitente, endereco: endereco) }
10
10
  let(:endereco) { FactoryGirl.build(:endereco) }
11
11
 
12
12
  it { must validate_presence_of(:nfe_number) }
13
13
  it { must validate_presence_of(:codigo_cancelamento) }
14
-
14
+ it { must validate_presence_of(:codigo_ibge_municipio_prestacao) }
15
15
  end
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require 'br_nfe/helper/have_rps_test'
3
2
 
4
3
 
5
4
  describe BrNfe::Service::Concerns::Rules::ConsultaNfsPorRps do
@@ -8,16 +7,12 @@ describe BrNfe::Service::Concerns::Rules::ConsultaNfsPorRps do
8
7
  end
9
8
 
10
9
  subject { RuleConsultaNfsPorRpsTest.new(rps: rps, emitente: emitente) }
11
- let(:emitente) { FactoryGirl.build(:emitente, endereco: endereco) }
10
+ let(:emitente) { FactoryGirl.build(:service_emitente, endereco: endereco) }
12
11
  let(:endereco) { FactoryGirl.build(:endereco) }
13
12
  let(:rps) { FactoryGirl.build(:br_nfe_rps) }
14
13
 
15
14
  it "deve ter o o helper HaveRps incluido" do
16
- subject.class.included_modules.must_include BrNfe::Helper::HaveRps
17
- end
18
-
19
- describe "rps" do
20
- include BrNfeTest::HelperTest::HaveRpsTest
15
+ subject.class.included_modules.must_include BrNfe::Service::Association::HaveRps
21
16
  end
22
17
 
23
18
  describe "#validate_rps" do
@@ -6,16 +6,16 @@ end
6
6
 
7
7
  describe BrNfe::Service::Concerns::Rules::ConsultaNfse do
8
8
  subject { RuleConsultaNfseTest.new(nfe_number: '554', start_date: 1.month.ago, end_date: Time.now, emitente: emitente) }
9
- let(:emitente) { FactoryGirl.build(:emitente, endereco: endereco) }
9
+ let(:emitente) { FactoryGirl.build(:service_emitente, endereco: endereco) }
10
10
  let(:endereco) { FactoryGirl.build(:endereco) }
11
11
  let(:rps) { FactoryGirl.build(:br_nfe_rps) }
12
12
 
13
13
  it "deve ter o o helper HaveDestinatario incluido" do
14
- subject.class.included_modules.must_include BrNfe::Helper::HaveDestinatario
14
+ subject.class.included_modules.must_include BrNfe::Association::HaveDestinatario
15
15
  end
16
16
 
17
17
  it "deve ter o o helper HaveIntermediario incluido" do
18
- subject.class.included_modules.must_include BrNfe::Helper::HaveIntermediario
18
+ subject.class.included_modules.must_include BrNfe::Service::Association::HaveIntermediario
19
19
  end
20
20
 
21
21
  describe "#start_date" do
@@ -39,4 +39,25 @@ describe BrNfe::Service::Concerns::Rules::ConsultaNfse do
39
39
  subject.end_date.must_equal ''
40
40
  end
41
41
  end
42
+
43
+ describe "#destinatario" do
44
+ class OtherClassDestinatario < BrNfe::ActiveModelBase
45
+ end
46
+ it "deve ter incluso o module HaveDestinatario" do
47
+ subject.class.included_modules.must_include BrNfe::Association::HaveDestinatario
48
+ end
49
+ it "o método #destinatario_class deve ter por padrão a class BrNfe::Service::Destinatario" do
50
+ subject.destinatario.must_be_kind_of BrNfe::Service::Destinatario
51
+ subject.send(:destinatario_class).must_equal BrNfe::Service::Destinatario
52
+ end
53
+ it "a class do destinatario pode ser modificada através da configuração destinatario_service_class" do
54
+ BrNfe.destinatario_service_class = OtherClassDestinatario
55
+ subject.destinatario.must_be_kind_of OtherClassDestinatario
56
+ subject.send(:destinatario_class).must_equal OtherClassDestinatario
57
+
58
+ # É necessário voltar a configuração original para não falhar outros testes
59
+ BrNfe.destinatario_service_class = BrNfe::Service::Destinatario
60
+ end
61
+ end
62
+
42
63
  end
@@ -6,7 +6,7 @@ end
6
6
 
7
7
  describe BrNfe::Service::Concerns::Rules::RecepcaoLoteRps do
8
8
  subject { RuleRecepcaoLoteRpsTest.new(numero_lote_rps: 545, operacao: '1', emitente: emitente) }
9
- let(:emitente) { FactoryGirl.build(:emitente, endereco: endereco) }
9
+ let(:emitente) { FactoryGirl.build(:service_emitente, endereco: endereco) }
10
10
  let(:endereco) { FactoryGirl.build(:endereco) }
11
11
  let(:rps) { FactoryGirl.build(:br_nfe_rps) }
12
12
 
@@ -1,9 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
- describe BrNfe::Helper::ValuesTs::ServiceV1 do
3
+ describe BrNfe::Service::Concerns::ValuesTs::ServiceV1 do
4
4
 
5
5
  class HelperValuesTsServiceV1Test < BrNfe::ActiveModelBase
6
- include BrNfe::Helper::ValuesTs::ServiceV1
6
+ include BrNfe::Service::Concerns::ValuesTs::ServiceV1
7
7
  end
8
8
 
9
9
  subject { HelperValuesTsServiceV1Test.new }
@@ -1,8 +1,7 @@
1
1
  require 'test_helper'
2
- require 'br_nfe/helper/have_address_test.rb'
3
2
 
4
- describe BrNfe::Destinatario do
5
- subject { FactoryGirl.build(:destinatario, endereco: endereco) }
3
+ describe BrNfe::Service::Destinatario do
4
+ subject { FactoryGirl.build(:service_destinatario, endereco: endereco) }
6
5
  let(:endereco) { FactoryGirl.build(:endereco) }
7
6
 
8
7
  describe "validations" do
@@ -25,7 +24,7 @@ describe BrNfe::Destinatario do
25
24
 
26
25
 
27
26
  describe "#endereco" do
28
- include BrNfeTest::HelperTest::HaveAddressTest
27
+ # include BrNfeTest::HelperTest::HaveAddressTest
29
28
  end
30
29
 
31
30
  describe "#razao_social" do
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Service::Emitente do
4
+ subject { FactoryGirl.build(:service_emitente, endereco: endereco) }
5
+ let(:endereco) { FactoryGirl.build(:endereco) }
6
+
7
+ it "deve herdar da classe ::Person" do
8
+ subject.must_be_kind_of BrNfe::Service::Emitente
9
+ subject.must_be_kind_of BrNfe::Person
10
+ end
11
+
12
+ describe "validations" do
13
+ it { must validate_presence_of(:inscricao_municipal) }
14
+ it { must validate_presence_of(:natureza_operacao) }
15
+ describe "valida o endereco" do
16
+ it "deve ser inválido se endereco for invalido" do
17
+ subject.endereco.stubs(:valid?).returns(false)
18
+ subject.endereco.stubs(:errors).returns(stub(full_messages: ["Erro 1"] ))
19
+ subject.valid?.must_equal false
20
+ subject.errors.full_messages.include?("Endereço: Erro 1").must_equal true
21
+ end
22
+ it "deve ser válido se endereco for valido" do
23
+ subject.endereco.stubs(:valid?).returns(true)
24
+ subject.valid?.must_equal true
25
+ end
26
+ end
27
+ end
28
+
29
+ end
@@ -4,31 +4,31 @@ describe BrNfe::Service::Item do
4
4
  subject { FactoryGirl.build(:service_item) }
5
5
 
6
6
  describe "#default_values" do
7
- context "#quantity" do
7
+ context "#quantidade" do
8
8
  it "valor padrão deve ser 1" do
9
- subject.class.new.quantity.must_equal 1
9
+ subject.class.new.quantidade.must_equal 1
10
10
  end
11
11
  it "posso modificar o valor" do
12
- subject.class.new(quantity: 50.88).quantity.must_equal 50.88
12
+ subject.class.new(quantidade: 50.88).quantidade.must_equal 50.88
13
13
  end
14
14
  end
15
15
  end
16
16
 
17
- describe "#total_value" do
17
+ describe "#valor_total" do
18
18
  it "se não for setado nenhum valor deve sempre retornar a multiplicação entre a quantidade e o valor unitário" do
19
- subject.total_value = nil
20
- subject.assign_attributes(quantity: 3.5, unit_value: 10.0)
21
- subject.total_value.must_equal 35.0
19
+ subject.valor_total = nil
20
+ subject.assign_attributes(quantidade: 3.5, valor_unitario: 10.0)
21
+ subject.valor_total.must_equal 35.0
22
22
  end
23
- it "se setar um valor em total_value não deve multiplicar a quantidade com o valor unitário" do
24
- subject.total_value = 66.0
25
- subject.assign_attributes(quantity: 3.5, unit_value: 10.0)
26
- subject.total_value.must_equal 66.0
23
+ it "se setar um valor em valor_total não deve multiplicar a quantidade com o valor unitário" do
24
+ subject.valor_total = 66.0
25
+ subject.assign_attributes(quantidade: 3.5, valor_unitario: 10.0)
26
+ subject.valor_total.must_equal 66.0
27
27
  end
28
28
  it "se quantidade ou valor unitário forem nil deve retornar zero" do
29
- subject.total_value = nil
30
- subject.assign_attributes(quantity: nil, unit_value: nil)
31
- subject.total_value.must_equal 0.0
29
+ subject.valor_total = nil
30
+ subject.assign_attributes(quantidade: nil, valor_unitario: nil)
31
+ subject.valor_total.must_equal 0.0
32
32
  end
33
33
  end
34
34
  end
@@ -0,0 +1,80 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Service::Response::Build::Base do
4
+ subject { FactoryGirl.build(:service_build_response) }
5
+ let(:response) { FactoryGirl.build(:response_service_default) }
6
+
7
+ describe "#find_value_for_keys" do
8
+ let(:var_hash) { {lvl1: {lvl2: {lvl3: 'value' } } } }
9
+
10
+ it "deve retornar o valor do hash quando encontra-lo" do
11
+ subject.find_value_for_keys(var_hash, [:lvl1, :lvl2, :lvl3]).must_equal 'value'
12
+ end
13
+ it "Se as chaves não exisitrem deve retornar nil" do
14
+ subject.find_value_for_keys(var_hash, [:lvl1, :noexist, :lvl4]).must_be_nil
15
+ end
16
+ it "o valor da chave não for um hash e ainda não terminar o loop não deve dar erro" do
17
+ subject.find_value_for_keys(var_hash, [:lvl1, :lvl2, :lvl3, :lvl4]).must_be_nil
18
+ end
19
+ it "pode retornar um hash se o ultimo valor for Hash" do
20
+ subject.find_value_for_keys(var_hash, [:lvl1, :lvl2]).must_equal({lvl3: 'value'})
21
+ end
22
+ it "se não passar apenas uma chave sem array deve retorar o valor da chave" do
23
+ subject.find_value_for_keys(var_hash, :lvl1).must_equal({lvl2: {lvl3: 'value'}})
24
+ end
25
+ end
26
+
27
+ describe "#path_with_root" do
28
+ it "deve concatenar o array do parametro com o Array do root path" do
29
+ subject.keys_root_path = [:root_path]
30
+ subject.path_with_root([:child, :child2]).must_equal([:root_path, :child, :child2])
31
+ end
32
+ it "se o path do params estiver em branco deve retornar nil" do
33
+ subject.keys_root_path = [:root_path]
34
+ subject.path_with_root([]).must_be_nil
35
+ end
36
+ end
37
+
38
+ describe "#get_message_for_path" do
39
+ before do
40
+ subject.stubs(:savon_body).returns(:savon_body)
41
+ subject.stubs(:path_with_root).with(:msg_path).returns([:msg, :path])
42
+ end
43
+ it "Quando ao procurar a mensagem retornar um Hash deve buscar a msg pelo metodo get_message_for_hash" do
44
+ subject.expects(:find_value_for_keys).with(:savon_body, [:msg, :path]).returns({message: 'ok'}).in_sequence(sequence_1)
45
+ subject.expects(:get_message_for_hash).with({message: 'ok'}).returns("MSG")
46
+
47
+ subject.get_message_for_path(:msg_path).must_equal ['MSG']
48
+ end
49
+ it "Quando ao procurar a mensagem retornar um Array deve buscar as msgs do array pelo metodo get_message_for_hash" do
50
+ subject.expects(:find_value_for_keys).with(:savon_body, [:msg, :path]).returns([{msg: 1},{msg: 2}]).in_sequence(sequence_1)
51
+ subject.expects(:get_message_for_hash).with({msg: 1}).returns("MSG1").in_sequence(sequence_1)
52
+ subject.expects(:get_message_for_hash).with({msg: 2}).returns("MSG2").in_sequence(sequence_1)
53
+
54
+ subject.get_message_for_path(:msg_path).must_equal ['MSG1','MSG2']
55
+ end
56
+ it "Quando ao procurar a mensagem retornar uma String deve add a string na msg" do
57
+ subject.expects(:find_value_for_keys).with(:savon_body, [:msg, :path]).returns('MESSAGE').in_sequence(sequence_1)
58
+ subject.expects(:get_message_for_hash).never
59
+
60
+ subject.get_message_for_path(:msg_path).must_equal ['MESSAGE']
61
+ end
62
+ end
63
+
64
+ describe "#get_message_for_hash" do
65
+ it "deve retornar um Hash com :code, :message e :solution que devem ser encontradas no has do parametro" do
66
+ subject.stubs(:message_code_key).returns(:codigo)
67
+ subject.stubs(:message_msg_key).returns(:mensagem)
68
+ subject.stubs(:message_solution_key).returns(:solucao)
69
+ result = subject.get_message_for_hash({codigo: 'CODE', mensagem: 'Mensagem de erro', solucao: "Solução"})
70
+ result.must_equal({
71
+ code: 'CODE',
72
+ message: 'Mensagem de erro',
73
+ solution: 'Solução'
74
+ })
75
+ end
76
+ end
77
+
78
+
79
+
80
+ end