-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathbill_spec.rb
119 lines (96 loc) · 3.69 KB
/
bill_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# encoding: utf-8
require 'spec_helper'
describe 'Bill' do
let(:bill) { @bill = Bravo::Bill.new(iva_condition: :consumidor_final, invoice_type: :invoice) }
describe '.header' do
it 'sets up the header hash' do
@header = Bravo::Bill.header(0)
@header.size.should == 3
['CantReg', 'CbteTipo', 'PtoVta'].each do |key|
@header.has_key?(key).should == true
end
end
end
describe '.initialize' do
it 'applies Bravos defaults' do
bill.client.class.name.should == 'Savon::Client'
['Token', 'Sign', 'Cuit'].each do |key|
bill.body['Auth'][key].should_not == nil
end
bill.document_type.should == Bravo.default_documento
bill.currency.should == Bravo.default_moneda
end
end
describe '#bill_type' do
before { bill.invoice_type = :invoice }
it 'returns the bill type for Responsable Inscripto' do
bill.iva_condition = :responsable_inscripto
bill.bill_type.should == '01'
end
it 'returns the bill type for Consumidor Final' do
bill.iva_condition = :consumidor_final
bill.bill_type.should == '06'
end
end
describe '#iva_sum and #total' do
it 'calculate the IVA array values' do
bill.iva_condition = :responsable_inscripto
bill.currency = :peso
bill.net = 100.89
bill.aliciva_id = 2
bill.iva_sum.should be_within(0.005).of(21.19)
bill.total.should be_within(0.005).of(122.08)
end
end
describe '#setup_bill' do
before do
bill.net = 100
bill.aliciva_id = 2
bill.document_number = '30710151543'
bill.iva_condition = :responsable_inscripto
bill.concept = 'Servicios'
end
it 'uses today dates when due and service dates are ommitted', vcr: { cassette_name: 'setup_bill_ommitted_date' } do
bill.setup_bill
detail = bill.body['FeCAEReq']['FeDetReq']['FECAEDetRequest']
detail['FchServDesde'].should == Time.new.strftime('%Y%m%d')
detail['FchServHasta'].should == Time.new.strftime('%Y%m%d')
detail['FchVtoPago'].should == Time.new.strftime('%Y%m%d')
end
it 'uses given due and service dates', vcr: { cassette_name: 'setup_bill_given_date' } do
bill.due_date = Date.new(2011, 12, 10).strftime('%Y%m%d')
bill.date_from = Date.new(2011, 11, 01).strftime('%Y%m%d')
bill.date_to = Date.new(2011, 11, 30).strftime('%Y%m%d')
bill.setup_bill
detail = bill.body['FeCAEReq']['FeDetReq']['FECAEDetRequest']
detail['FchServDesde'].should == '20111101'
detail['FchServHasta'].should == '20111130'
detail['FchVtoPago'].should == '20111210'
end
end
describe '#authorize' do
describe 'for facturas' do
Bravo::BILL_TYPE[Bravo.own_iva_cond].keys.each do |target_iva_cond|
describe "issued to #{ target_iva_cond.to_s }" do
Bravo::BILL_TYPE[Bravo.own_iva_cond][target_iva_cond].keys.each do |bill_type|
vcr_options = { cassette_name: "#{ target_iva_cond.to_s }_and_#{ bill_type }" }
it "authorizes bill type #{ bill_type }", vcr: vcr_options do
bill.net = 10000.88
bill.aliciva_id = 2
bill.document_number = '30710151543'
bill.iva_condition = target_iva_cond
bill.concept = 'Servicios'
bill.invoice_type = bill_type
bill.authorized?.should == false
bill.authorize.should == true
bill.authorized?.should == true
response = bill.response
response.length.should == 28
response.cae.length.should == 14
end
end
end
end
end
end
end