afipws 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +6 -1
  3. data/README.md +1 -0
  4. data/afipws.gemspec +1 -0
  5. data/lib/afipws.rb +1 -1
  6. data/lib/afipws/client.rb +0 -1
  7. data/lib/afipws/persona_service_a100.rb +14 -6
  8. data/lib/afipws/persona_service_a4.rb +14 -4
  9. data/lib/afipws/version.rb +1 -1
  10. data/lib/afipws/w_cons_declaracion.rb +63 -0
  11. data/lib/afipws/ws_constancia_inscripcion.rb +15 -5
  12. data/lib/afipws/wsaa.rb +2 -2
  13. data/lib/afipws/wsfe.rb +8 -6
  14. data/spec/afipws/core_ext/hash_spec.rb +3 -3
  15. data/spec/afipws/persona_service_a100_spec.rb +3 -3
  16. data/spec/afipws/persona_service_a4_spec.rb +1 -1
  17. data/spec/afipws/w_cons_declaracion_spec.rb +87 -0
  18. data/spec/afipws/ws_constancia_inscripcion_spec.rb +12 -14
  19. data/spec/afipws/wsaa_spec.rb +2 -2
  20. data/spec/afipws/wsfe_spec.rb +49 -47
  21. data/spec/fixtures/wconsdeclaracion/detallada_estado/success.xml +24 -0
  22. data/spec/fixtures/wconsdeclaracion/detallada_lista_declaraciones/por_fecha_success.xml +39 -0
  23. data/spec/fixtures/wconsdeclaracion/detallada_lista_declaraciones/por_id_inexistente.xml +16 -0
  24. data/spec/fixtures/wconsdeclaracion/detallada_lista_declaraciones/por_id_success.xml +29 -0
  25. data/spec/fixtures/wconsdeclaracion/dummy/success.xml +12 -0
  26. data/spec/fixtures/wconsdeclaracion/wconsdeclaracion.wsdl +2976 -0
  27. data/spec/fixtures/{constancia_inscripcion_dummy → ws_sr_constancia_inscripcion/dummy}/success.xml +0 -0
  28. data/spec/fixtures/{constancia_inscripcion_get_persona → ws_sr_constancia_inscripcion/get_persona}/failure.xml +0 -0
  29. data/spec/fixtures/{constancia_inscripcion_get_persona → ws_sr_constancia_inscripcion/get_persona}/fault.xml +0 -0
  30. data/spec/fixtures/{constancia_inscripcion_get_persona → ws_sr_constancia_inscripcion/get_persona}/success.xml +0 -0
  31. data/spec/fixtures/{ws_constancia_inscripcion.wsdl → ws_sr_constancia_inscripcion/ws_constancia_inscripcion.wsdl} +0 -0
  32. data/spec/fixtures/{login_cms → wsaa/login_cms}/fault.xml +0 -0
  33. data/spec/fixtures/{login_cms → wsaa/login_cms}/success.xml +0 -0
  34. data/spec/fixtures/{login_cms → wsaa/login_cms}/token_expirado.xml +0 -0
  35. data/spec/fixtures/{wsaa.wsdl → wsaa/wsaa.wsdl} +0 -0
  36. data/spec/fixtures/{fe_comp_consultar → wsfe/fe_comp_consultar}/success.xml +0 -0
  37. data/spec/fixtures/{fe_comp_tot_x_request → wsfe/fe_comp_tot_x_request}/success.xml +0 -0
  38. data/spec/fixtures/{fe_comp_ultimo_autorizado → wsfe/fe_comp_ultimo_autorizado}/success.xml +0 -0
  39. data/spec/fixtures/{fe_dummy → wsfe/fe_dummy}/success.xml +0 -0
  40. data/spec/fixtures/{fe_param_get_cotizacion → wsfe/fe_param_get_cotizacion}/dolar.xml +0 -0
  41. data/spec/fixtures/{fe_param_get_cotizacion → wsfe/fe_param_get_cotizacion}/inexistente.xml +0 -0
  42. data/spec/fixtures/{fe_param_get_ptos_venta → wsfe/fe_param_get_ptos_venta}/success.xml +0 -0
  43. data/spec/fixtures/{fe_param_get_tipos_cbte → wsfe/fe_param_get_tipos_cbte}/failure_1_error.xml +0 -0
  44. data/spec/fixtures/{fe_param_get_tipos_cbte → wsfe/fe_param_get_tipos_cbte}/failure_2_errors.xml +0 -0
  45. data/spec/fixtures/{fe_param_get_tipos_cbte → wsfe/fe_param_get_tipos_cbte}/success.xml +0 -0
  46. data/spec/fixtures/{fe_param_get_tipos_concepto → wsfe/fe_param_get_tipos_concepto}/success.xml +0 -0
  47. data/spec/fixtures/{fe_param_get_tipos_doc → wsfe/fe_param_get_tipos_doc}/success.xml +0 -0
  48. data/spec/fixtures/{fe_param_get_tipos_iva → wsfe/fe_param_get_tipos_iva}/success.xml +0 -0
  49. data/spec/fixtures/{fe_param_get_tipos_monedas → wsfe/fe_param_get_tipos_monedas}/success.xml +0 -0
  50. data/spec/fixtures/{fe_param_get_tipos_opcional → wsfe/fe_param_get_tipos_opcional}/success.xml +0 -0
  51. data/spec/fixtures/{fe_param_get_tipos_tributos → wsfe/fe_param_get_tipos_tributos}/success.xml +0 -0
  52. data/spec/fixtures/{fecae_solicitar → wsfe/fecae_solicitar}/autorizacion_1_cbte.xml +0 -0
  53. data/spec/fixtures/{fecae_solicitar → wsfe/fecae_solicitar}/autorizacion_2_cbtes.xml +0 -0
  54. data/spec/fixtures/{fecae_solicitar → wsfe/fecae_solicitar}/dos_observaciones.xml +0 -0
  55. data/spec/fixtures/{fecae_solicitar → wsfe/fecae_solicitar}/una_observacion.xml +0 -0
  56. data/spec/fixtures/{fecaea_consultar → wsfe/fecaea_consultar}/success.xml +0 -0
  57. data/spec/fixtures/{fecaea_reg_informativo → wsfe/fecaea_reg_informativo}/informe_rtdo_parcial.xml +0 -0
  58. data/spec/fixtures/{fecaea_sin_movimiento_informar → wsfe/fecaea_sin_movimiento_informar}/success.xml +0 -0
  59. data/spec/fixtures/{fecaea_solicitar → wsfe/fecaea_solicitar}/caea_ya_otorgado.xml +0 -0
  60. data/spec/fixtures/{fecaea_solicitar → wsfe/fecaea_solicitar}/error_distinto.xml +0 -0
  61. data/spec/fixtures/{fecaea_solicitar → wsfe/fecaea_solicitar}/success.xml +0 -0
  62. data/spec/fixtures/{wsfe.wsdl → wsfe/wsfe.wsdl} +1371 -1371
  63. data/spec/spec_helper.rb +3 -2
  64. data/spec/support/fake_wsaa.rb +11 -0
  65. metadata +105 -75
  66. data/lib/afipws/ws_base.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ed8e558f8cf41675bf7ba19aa0f8c0b6cc29bb5
4
- data.tar.gz: 271002cc672721b11bce0c1824c011d518a264f4
3
+ metadata.gz: 481dd3449d5658b7d7222c4e041d7a4efe8d095d
4
+ data.tar.gz: 092b5b8ded81405f91cb9665d0a2bff98a310096
5
5
  SHA512:
6
- metadata.gz: 30ab4619718e0cd10b36d895868b8557a5b6a42b8463e66f61ba6ef1d2af6a7c18c8fc99fba06332db96ea2e2c88391bcd405df6417301c25b3e3c3ad9fec827
7
- data.tar.gz: 13d842061c17115fe92fe8f14bcfd2df65240484ac95570178412b1d0a9d7ad8f77fa4272df83bb092e936bfcecadc1dbdc6ea3714f9aabf879dfecddccd99cc
6
+ metadata.gz: 7e5be4d4543156ffed6574a0739c1dd58b56068c256e57030fe2b0a86d74af5de15fb77d624b7ab5a14df59baa251d59134ae66d9c82ee39977edee62e05d4bc
7
+ data.tar.gz: 2d88703b4e60a13b27d69f2d337d0bda512348a77758bf70263747543c61e58a5673e7396d03cbf558d7eb7b81030aa94145a5be871295e94f59ad8c8b566ad1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- afipws (1.1.0)
4
+ afipws (1.2.0)
5
5
  activesupport
6
6
  builder
7
7
  nokogiri
@@ -20,6 +20,7 @@ GEM
20
20
  nokogiri
21
21
  ast (2.4.0)
22
22
  builder (3.2.3)
23
+ byebug (11.0.1)
23
24
  coderay (1.1.2)
24
25
  concurrent-ruby (1.0.5)
25
26
  diff-lcs (1.3)
@@ -71,6 +72,9 @@ GEM
71
72
  pry (0.11.3)
72
73
  coderay (~> 1.1.0)
73
74
  method_source (~> 0.9.0)
75
+ pry-byebug (3.7.0)
76
+ byebug (~> 11.0)
77
+ pry (~> 0.10)
74
78
  rack (2.0.6)
75
79
  rainbow (3.0.0)
76
80
  rake (10.4.2)
@@ -127,6 +131,7 @@ DEPENDENCIES
127
131
  guard-rspec
128
132
  mocha
129
133
  pry
134
+ pry-byebug
130
135
  rspec
131
136
  rubocop
132
137
 
data/README.md CHANGED
@@ -11,6 +11,7 @@ Ruby client para los web services de la AFIP.
11
11
  * ws_sr_constancia_inscripcion (WSConstanciaInscripcion)
12
12
  * ws_sr_padron_a100 (PersonaServiceA100)
13
13
  * ws_sr_padron_a4 (PersonaServiceA4)
14
+ * wconsdeclaracion (WConsDeclaracion)
14
15
 
15
16
  ## Uso
16
17
 
data/afipws.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency 'guard-rspec'
24
24
  s.add_development_dependency 'rubocop'
25
25
  s.add_development_dependency 'pry'
26
+ s.add_development_dependency 'pry-byebug'
26
27
  s.add_dependency "builder"
27
28
  s.add_dependency "savon", '~> 2.11.0'
28
29
  s.add_dependency "nokogiri"
data/lib/afipws.rb CHANGED
@@ -13,9 +13,9 @@ require 'afipws/core_ext/hash'
13
13
  require 'afipws/excepciones'
14
14
  require 'afipws/type_conversions'
15
15
  require 'afipws/client'
16
- require 'afipws/ws_base'
17
16
  require 'afipws/wsaa'
18
17
  require 'afipws/wsfe'
19
18
  require 'afipws/ws_constancia_inscripcion'
20
19
  require 'afipws/persona_service_a4'
21
20
  require 'afipws/persona_service_a100'
21
+ require 'afipws/w_cons_declaracion'
data/lib/afipws/client.rb CHANGED
@@ -4,7 +4,6 @@ module Afipws
4
4
  @client = Savon.client savon_options.reverse_merge(soap_version: 2, ssl_version: :TLSv1)
5
5
  end
6
6
 
7
-
8
7
  def request action, body = nil
9
8
  @client.call action, message: body
10
9
  end
@@ -1,15 +1,17 @@
1
1
  module Afipws
2
- class PersonaServiceA100 < WSBase
2
+ class PersonaServiceA100
3
3
  WSDL = {
4
4
  development: 'https://awshomo.afip.gov.ar/sr-parametros/webservices/parameterServiceA100?WSDL',
5
5
  production: 'https://aws.afip.gov.ar/sr-parametros/webservices/parameterServiceA100?WSDL',
6
6
  test: Root + '/spec/fixtures/ws_sr_padron_a100.wsdl'
7
7
  }.freeze
8
8
 
9
+ attr_reader :wsaa
10
+
9
11
  def initialize options = {}
10
- super
12
+ @cuit = options[:cuit]
11
13
  @wsaa = WSAA.new options.merge(service: 'ws_sr_padron_a100')
12
- @client = Client.new Hash(options[:savon]).reverse_merge(wsdl: WSDL[env], soap_version: 1)
14
+ @client = Client.new Hash(options[:savon]).reverse_merge(wsdl: WSDL[@wsaa.env], soap_version: 1)
13
15
  end
14
16
 
15
17
  def dummy
@@ -32,12 +34,18 @@ module Afipws
32
34
 
33
35
  def get_parameter_collection_by_name type
34
36
  message = {
35
- token: auth[:token],
36
- sign: auth[:sign],
37
- cuitRepresentada: cuit,
37
+ token: @wsaa.auth[:token],
38
+ sign: @wsaa.auth[:sign],
39
+ cuitRepresentada: @cuit,
38
40
  collectionName: type
39
41
  }
40
42
  request(:get_parameter_collection_by_name, message)[:parameter_collection_return][:parameter_collection]
41
43
  end
44
+
45
+ def request action, body = nil
46
+ @client.request(action, body).to_hash[:"#{action}_response"]
47
+ rescue Savon::SOAPFault => f
48
+ raise WSError, f.message
49
+ end
42
50
  end
43
51
  end
@@ -1,15 +1,17 @@
1
1
  module Afipws
2
- class PersonaServiceA4 < WSBase
2
+ class PersonaServiceA4
3
3
  WSDL = {
4
4
  development: 'https://awshomo.afip.gov.ar/sr-padron/webservices/personaServiceA4?WSDL',
5
5
  production: 'https://aws.afip.gov.ar/sr-padron/webservices/personaServiceA4?WSDL',
6
6
  test: Root + '/spec/fixtures/ws_sr_padron_a4.wsdl'
7
7
  }.freeze
8
8
 
9
+ attr_reader :wsaa
10
+
9
11
  def initialize options = {}
10
- super
12
+ @cuit = options[:cuit]
11
13
  @wsaa = WSAA.new options.merge(service: 'ws_sr_padron_a4')
12
- @client = Client.new Hash(options[:savon]).reverse_merge(wsdl: WSDL[env], soap_version: 1)
14
+ @client = Client.new Hash(options[:savon]).reverse_merge(wsdl: WSDL[@wsaa.env], soap_version: 1)
13
15
  end
14
16
 
15
17
  def dummy
@@ -17,8 +19,16 @@ module Afipws
17
19
  end
18
20
 
19
21
  def get_persona id
20
- message = auth.merge(cuitRepresentada: cuit, idPersona: id)
22
+ message = @wsaa.auth.merge(cuitRepresentada: @cuit, idPersona: id)
21
23
  request(:get_persona, message)[:persona_return][:persona]
22
24
  end
25
+
26
+ private
27
+
28
+ def request action, body = nil
29
+ @client.request(action, body).to_hash[:"#{action}_response"]
30
+ rescue Savon::SOAPFault => f
31
+ raise WSError, f.message
32
+ end
23
33
  end
24
34
  end
@@ -1,3 +1,3 @@
1
1
  module Afipws
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -0,0 +1,63 @@
1
+ module Afipws
2
+ class WConsDeclaracion
3
+ WSDL = {
4
+ development: 'https://wsaduhomoext.afip.gob.ar/diav2/wconsdeclaracion/wconsdeclaracion.asmx?WSDL',
5
+ production: 'https://webservicesadu.afip.gov.ar/DIAV2/wconsdeclaracion/wconsdeclaracion.asmx?WSDL',
6
+ test: Root + '/spec/fixtures/wconsdeclaracion/wconsdeclaracion.wsdl'
7
+ }.freeze
8
+
9
+ attr_reader :wsaa
10
+
11
+ def initialize tipo_agente: 'IMEX', rol: 'IMEX', **options
12
+ @cuit, @tipo_agente, @rol = options[:cuit], tipo_agente, rol
13
+ @wsaa = WSAA.new(options.merge(service: 'wconsdeclaracion'))
14
+ @client = Client.new(Hash(options[:savon]).reverse_merge(wsdl: WSDL[@wsaa.env]))
15
+ end
16
+
17
+ def dummy
18
+ request :dummy
19
+ end
20
+
21
+ def detallada_lista_declaraciones identificador_declaracion: nil, fecha_oficializacion_desde: nil, fecha_oficializacion_hasta: nil
22
+ message = {
23
+ 'argDetalladasListaParams' => {
24
+ 'CuitImportadorExportador' => @cuit,
25
+ 'IdentificadorDeclaracion' => identificador_declaracion,
26
+ 'FechaOficializacionDesde' => fecha_oficializacion_desde&.iso8601,
27
+ 'FechaOficializacionHasta' => fecha_oficializacion_hasta&.iso8601
28
+ }.compact
29
+ }
30
+ request(:detallada_lista_declaraciones, auth.merge(message))[:declaraciones][:declaracion]
31
+ end
32
+
33
+ def detallada_estado identificador_declaracion
34
+ message = {'argIdentificadorDestinacion' => identificador_declaracion}
35
+ request(:detallada_estado, auth.merge(message))[:estado]
36
+ end
37
+
38
+ private
39
+
40
+ def request action, body = nil
41
+ response = @client.request(action, body).to_hash[:"#{action}_response"][:"#{action}_result"]
42
+ if response[:lista_errores] && response[:lista_errores][:detalle_error][:codigo] != '0'
43
+ raise WSError, Array.wrap(response[:lista_errores][:detalle_error]).map { |e| {code: e[:codigo], msg: e[:descripcion]} }
44
+ else
45
+ response
46
+ end
47
+ rescue Savon::SOAPFault => f
48
+ raise WSError, f.message
49
+ end
50
+
51
+ def auth
52
+ {
53
+ 'argWSAutenticacionEmpresa' => {
54
+ 'Token' => @wsaa.auth[:token],
55
+ 'Sign' => @wsaa.auth[:sign],
56
+ 'CuitEmpresaConectada' => @cuit,
57
+ 'TipoAgente' => @tipo_agente,
58
+ 'Rol' => @rol
59
+ }
60
+ }
61
+ end
62
+ end
63
+ end
@@ -1,15 +1,17 @@
1
1
  module Afipws
2
- class WSConstanciaInscripcion < WSBase
2
+ class WSConstanciaInscripcion
3
3
  WSDL = {
4
4
  development: 'https://awshomo.afip.gov.ar/sr-padron/webservices/personaServiceA5?WSDL',
5
5
  production: 'https://aws.afip.gov.ar/sr-padron/webservices/personaServiceA5?WSDL',
6
- test: Root + '/spec/fixtures/ws_constancia_inscripcion.wsdl'
6
+ test: Root + '/spec/fixtures/ws_sr_constancia_inscripcion/ws_constancia_inscripcion.wsdl'
7
7
  }.freeze
8
8
 
9
+ attr_reader :wsaa
10
+
9
11
  def initialize options = {}
10
- super
12
+ @cuit = options[:cuit]
11
13
  @wsaa = WSAA.new options.merge(service: 'ws_sr_constancia_inscripcion')
12
- @client = Client.new Hash(options[:savon]).reverse_merge(wsdl: WSDL[env], soap_version: 1)
14
+ @client = Client.new Hash(options[:savon]).reverse_merge(wsdl: WSDL[@wsaa.env], soap_version: 1)
13
15
  end
14
16
 
15
17
  def dummy
@@ -17,8 +19,16 @@ module Afipws
17
19
  end
18
20
 
19
21
  def get_persona id
20
- message = auth.merge(cuit_representada: cuit, id_persona: id)
22
+ message = @wsaa.auth.merge(cuit_representada: @cuit, id_persona: id)
21
23
  request(:get_persona, message)[:persona_return]
22
24
  end
25
+
26
+ private
27
+
28
+ def request action, body = nil
29
+ @client.request(action, body).to_hash[:"#{action}_response"]
30
+ rescue Savon::SOAPFault => f
31
+ raise WSError, f.message
32
+ end
23
33
  end
24
34
  end
data/lib/afipws/wsaa.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  module Afipws
2
2
  class WSAA
3
- attr_reader :key, :cert, :service, :ta, :cuit, :client
3
+ attr_reader :key, :cert, :service, :ta, :cuit, :client, :env
4
4
 
5
5
  WSDL = {
6
6
  development: 'https://wsaahomo.afip.gov.ar/ws/services/LoginCms?wsdl',
7
7
  production: 'https://wsaa.afip.gov.ar/ws/services/LoginCms?wsdl',
8
- test: Root + '/spec/fixtures/wsaa.wsdl'
8
+ test: Root + '/spec/fixtures/wsaa/wsaa.wsdl'
9
9
  }
10
10
 
11
11
  def initialize options = {}
data/lib/afipws/wsfe.rb CHANGED
@@ -1,17 +1,19 @@
1
1
  module Afipws
2
- class WSFE < WSBase
3
- include TypeConversions
4
-
2
+ class WSFE
5
3
  WSDL = {
6
4
  development: 'https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL',
7
5
  production: 'https://servicios1.afip.gov.ar/wsfev1/service.asmx?WSDL',
8
- test: Root + '/spec/fixtures/wsfe.wsdl'
6
+ test: Root + '/spec/fixtures/wsfe/wsfe.wsdl'
9
7
  }.freeze
10
8
 
9
+ include TypeConversions
10
+
11
+ attr_reader :wsaa, :cuit
12
+
11
13
  def initialize options = {}
12
- super
14
+ @cuit = options[:cuit]
13
15
  @wsaa = WSAA.new options.merge(service: 'wsfe')
14
- @client = Client.new Hash(options[:savon]).reverse_merge(wsdl: WSDL[env], convert_request_keys_to: :camelcase)
16
+ @client = Client.new Hash(options[:savon]).reverse_merge(wsdl: WSDL[@wsaa.env], convert_request_keys_to: :camelcase)
15
17
  end
16
18
 
17
19
  def dummy
@@ -15,9 +15,9 @@ describe Hash do
15
15
  subject { Hash[1, 2, 3, 4] }
16
16
 
17
17
  it 'debería devolver true cuando self incluye todas las entries del hash parametro' do
18
- should have_entries 1 => 2
19
- should have_entries 3 => 4, 1 => 2
20
- should_not have_entries 1 => 3
18
+ should include 1 => 2
19
+ should include 3 => 4, 1 => 2
20
+ should_not include 1 => 3
21
21
  end
22
22
  end
23
23
  end
@@ -16,21 +16,21 @@ module Afipws
16
16
  savon.expects(:get_parameter_collection_by_name)
17
17
  .with(message: message.merge(collectionName: 'SUPA.E_PROVINCIA'))
18
18
  .returns(fixture('ws_sr_padron_a100/jurisdictions/success'))
19
- ws.jurisdictions.should have_entries name: 'SUPA.E_PROVINCIA'
19
+ ws.jurisdictions.should include name: 'SUPA.E_PROVINCIA'
20
20
  end
21
21
 
22
22
  it 'company_types' do
23
23
  savon.expects(:get_parameter_collection_by_name)
24
24
  .with(message: message.merge(collectionName: 'SUPA.TIPO_EMPRESA_JURIDICA'))
25
25
  .returns(fixture('ws_sr_padron_a100/company_types/success'))
26
- ws.company_types.should have_entries name: 'SUPA.TIPO_EMPRESA_JURIDICA'
26
+ ws.company_types.should include name: 'SUPA.TIPO_EMPRESA_JURIDICA'
27
27
  end
28
28
 
29
29
  it 'public_organisms' do
30
30
  savon.expects(:get_parameter_collection_by_name)
31
31
  .with(message: message.merge(collectionName: 'SUPA.E_ORGANISMO_INFORMANTE'))
32
32
  .returns(fixture('ws_sr_padron_a100/public_organisms/success'))
33
- ws.public_organisms.should have_entries name: 'SUPA.E_ORGANISMO_INFORMANTE'
33
+ ws.public_organisms.should include name: 'SUPA.E_ORGANISMO_INFORMANTE'
34
34
  end
35
35
  end
36
36
  end
@@ -16,7 +16,7 @@ module Afipws
16
16
  savon.expects(:get_persona)
17
17
  .with(message: message.merge(idPersona: '98765432198'))
18
18
  .returns(fixture('ws_sr_padron_a4/get_persona/success'))
19
- ws.get_persona('98765432198').should have_entries apellido: 'ERNESTO DANIEL'
19
+ ws.get_persona('98765432198').should include apellido: 'ERNESTO DANIEL'
20
20
  end
21
21
  end
22
22
  end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ module Afipws
4
+ describe WConsDeclaracion do
5
+ let(:ta) { {token: 't', sign: 's'} }
6
+ let(:ws) { WConsDeclaracion.new(env: :test, cuit: '23076925089').tap { |ws| ws.wsaa.stubs auth: ta } }
7
+
8
+ it 'utiliza los parámetros correctos en el WSAA' do
9
+ ws.wsaa.service.should == 'wconsdeclaracion'
10
+ ws.wsaa.cuit.should == '23076925089'
11
+ ws.wsaa.env.should == :test
12
+ end
13
+
14
+ context 'métodos del WS' do
15
+ it 'dummy' do
16
+ savon.expects(:dummy).returns(fixture('wconsdeclaracion/dummy/success'))
17
+ ws.dummy.should == {app_server: 'OK', db_server: 'OK', auth_server: 'OK'}
18
+ end
19
+
20
+ context 'detallada_lista_declaraciones' do
21
+ it 'x id declaración' do
22
+ message = with_auth_section(
23
+ 'argDetalladasListaParams' => {
24
+ 'CuitImportadorExportador' => '23076925089',
25
+ 'IdentificadorDeclaracion' => '19093SIMI000434X'
26
+ }
27
+ )
28
+ savon.expects(:detallada_lista_declaraciones).with(message: message)
29
+ .returns(fixture('wconsdeclaracion/detallada_lista_declaraciones/por_id_success'))
30
+ declaracion = ws.detallada_lista_declaraciones identificador_declaracion: '19093SIMI000434X'
31
+ declaracion.should include identificador_declaracion: '19093SIMI000434X', cuit_importador_exportador: '23076925089'
32
+ end
33
+
34
+ it 'x rango de fecha de oficialización' do
35
+ message = with_auth_section(
36
+ 'argDetalladasListaParams' => {
37
+ 'CuitImportadorExportador' => '23076925089',
38
+ 'FechaOficializacionDesde' => '2019-04-01T00:00:00-03:00',
39
+ 'FechaOficializacionHasta' => '2019-04-30T00:00:00-03:00'
40
+ }
41
+ )
42
+ savon.expects(:detallada_lista_declaraciones).with(message: message)
43
+ .returns(fixture('wconsdeclaracion/detallada_lista_declaraciones/por_fecha_success'))
44
+ declaraciones = ws.detallada_lista_declaraciones(
45
+ fecha_oficializacion_desde: Time.parse('2019-04-01T00:00:00-03:00'),
46
+ fecha_oficializacion_hasta: Time.parse('2019-04-30T00:00:00-03:00')
47
+ )
48
+ declaraciones.should match_array [
49
+ include(identificador_declaracion: '19092SIMI000313M'),
50
+ include(identificador_declaracion: '19092SIMI000314N')
51
+ ]
52
+ end
53
+
54
+ it 'x id inexistente' do
55
+ savon.expects(:detallada_lista_declaraciones).with(message: :any)
56
+ .returns(fixture('wconsdeclaracion/detallada_lista_declaraciones/por_id_inexistente'))
57
+ -> { ws.detallada_lista_declaraciones identificador_declaracion: '...' }
58
+ .should raise_error WSError, '21248: Declaracion 19093SIMI000434. inexistente o invalida'
59
+ end
60
+ end
61
+
62
+ context 'detallada_estado' do
63
+ it 'caso exitoso' do
64
+ message = with_auth_section('argIdentificadorDestinacion' => '19093SIMI000434X')
65
+ savon.expects(:detallada_estado).with(message: message)
66
+ .returns(fixture('wconsdeclaracion/detallada_estado/success'))
67
+ ws.detallada_estado('19093SIMI000434X').should include(
68
+ fecha_salida: DateTime.parse('2019-04-25T18:48:12'),
69
+ fecha_cancelacion: DateTime.parse('2019-07-04T02:29:34')
70
+ )
71
+ end
72
+ end
73
+
74
+ def with_auth_section message
75
+ {
76
+ 'argWSAutenticacionEmpresa' => {
77
+ 'Token' => 't',
78
+ 'Sign' => 's',
79
+ 'CuitEmpresaConectada' => '23076925089',
80
+ 'TipoAgente' => 'IMEX',
81
+ 'Rol' => 'IMEX'
82
+ }
83
+ }.merge message
84
+ end
85
+ end
86
+ end
87
+ end