fortnox-api 0.6.2 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +5 -1
  3. data/.travis.yml +20 -22
  4. data/CHANGELOG.md +48 -0
  5. data/README.md +14 -19
  6. data/Rakefile +5 -0
  7. data/fortnox-api.gemspec +10 -10
  8. data/lib/fortnox/api/mappers.rb +5 -38
  9. data/lib/fortnox/api/mappers/base.rb +2 -24
  10. data/lib/fortnox/api/mappers/base/canonical_name_sym.rb +21 -0
  11. data/lib/fortnox/api/mappers/base/from_json.rb +6 -1
  12. data/lib/fortnox/api/mappers/value/array.rb +18 -0
  13. data/lib/fortnox/api/mappers/value/country_string.rb +24 -0
  14. data/lib/fortnox/api/mappers/value/date.rb +11 -0
  15. data/lib/fortnox/api/mappers/value/hash.rb +16 -0
  16. data/lib/fortnox/api/mappers/value/identity.rb +18 -0
  17. data/lib/fortnox/api/models/document.rb +6 -3
  18. data/lib/fortnox/api/models/invoice.rb +1 -1
  19. data/lib/fortnox/api/models/order.rb +1 -1
  20. data/lib/fortnox/api/repositories/base.rb +9 -11
  21. data/lib/fortnox/api/request_handling.rb +0 -1
  22. data/lib/fortnox/api/types.rb +40 -3
  23. data/lib/fortnox/api/types/enums.rb +36 -31
  24. data/lib/fortnox/api/types/shim/country_string.rb +10 -0
  25. data/lib/fortnox/api/version.rb +1 -1
  26. data/spec/fortnox/api/circular_queue_spec.rb +52 -0
  27. data/spec/fortnox/api/mappers/base/canonical_name_sym_spec.rb +34 -0
  28. data/spec/fortnox/api/mappers/base_spec.rb +33 -43
  29. data/spec/fortnox/api/mappers/contexts/json_conversion.rb +1 -1
  30. data/spec/fortnox/api/repositories/article_spec.rb +4 -2
  31. data/spec/fortnox/api/repositories/base_spec.rb +28 -8
  32. data/spec/fortnox/api/repositories/customer_spec.rb +29 -1
  33. data/spec/fortnox/api/repositories/invoice_spec.rb +147 -3
  34. data/spec/fortnox/api/repositories/order_spec.rb +2 -2
  35. data/spec/fortnox/api/repositories/project_spec.rb +1 -1
  36. data/spec/fortnox/api/repositories/terms_of_payment_spec.rb +4 -2
  37. data/spec/fortnox/api/repositories/unit_spec.rb +6 -3
  38. data/spec/fortnox/api/types/account_number_spec.rb +19 -15
  39. data/spec/fortnox/api/types/country_code_spec.rb +42 -0
  40. data/spec/fortnox/api/types/country_spec.rb +67 -0
  41. data/spec/fortnox/api/types/email_spec.rb +8 -7
  42. data/spec/fortnox/api/types/enums_spec.rb +1 -1
  43. data/spec/fortnox/api/types/examples/document_row.rb +1 -1
  44. data/spec/fortnox/api/types/housework_types_spec.rb +151 -34
  45. data/spec/fortnox/api_spec.rb +3 -1
  46. data/spec/vcr_cassettes/articles/all.yml +40 -10
  47. data/spec/vcr_cassettes/articles/find_by_hash_failure.yml +21 -8
  48. data/spec/vcr_cassettes/articles/find_failure.yml +21 -8
  49. data/spec/vcr_cassettes/articles/find_id_1.yml +22 -9
  50. data/spec/vcr_cassettes/articles/find_new.yml +24 -11
  51. data/spec/vcr_cassettes/articles/multi_param_find_by_hash.yml +21 -8
  52. data/spec/vcr_cassettes/articles/save_new.yml +22 -8
  53. data/spec/vcr_cassettes/articles/save_old.yml +24 -11
  54. data/spec/vcr_cassettes/articles/save_with_specially_named_attribute.yml +22 -8
  55. data/spec/vcr_cassettes/articles/search_by_name.yml +21 -8
  56. data/spec/vcr_cassettes/articles/search_miss.yml +21 -8
  57. data/spec/vcr_cassettes/articles/search_with_special_char.yml +21 -8
  58. data/spec/vcr_cassettes/articles/single_param_find_by_hash.yml +33 -10
  59. data/spec/vcr_cassettes/customers/all.yml +26 -13
  60. data/spec/vcr_cassettes/customers/find_by_hash_failure.yml +21 -8
  61. data/spec/vcr_cassettes/customers/find_failure.yml +21 -8
  62. data/spec/vcr_cassettes/customers/find_id_1.yml +22 -9
  63. data/spec/vcr_cassettes/customers/find_new.yml +24 -11
  64. data/spec/vcr_cassettes/customers/multi_param_find_by_hash.yml +21 -8
  65. data/spec/vcr_cassettes/customers/save_new.yml +21 -7
  66. data/spec/vcr_cassettes/customers/save_new_with_country_code_SE.yml +60 -0
  67. data/spec/vcr_cassettes/customers/save_old.yml +23 -10
  68. data/spec/vcr_cassettes/customers/save_with_specially_named_attribute.yml +21 -7
  69. data/spec/vcr_cassettes/customers/search_by_name.yml +32 -10
  70. data/spec/vcr_cassettes/customers/search_miss.yml +21 -8
  71. data/spec/vcr_cassettes/customers/search_with_special_char.yml +21 -8
  72. data/spec/vcr_cassettes/customers/single_param_find_by_hash.yml +22 -9
  73. data/spec/vcr_cassettes/invoices/all.yml +118 -67
  74. data/spec/vcr_cassettes/invoices/filter_hit.yml +26 -10
  75. data/spec/vcr_cassettes/invoices/filter_invalid.yml +20 -6
  76. data/spec/vcr_cassettes/invoices/find_by_hash_failure.yml +21 -8
  77. data/spec/vcr_cassettes/invoices/find_failure.yml +21 -8
  78. data/spec/vcr_cassettes/invoices/find_id_1.yml +23 -10
  79. data/spec/vcr_cassettes/invoices/find_new.yml +26 -14
  80. data/spec/vcr_cassettes/invoices/multi_param_find_by_hash.yml +23 -10
  81. data/spec/vcr_cassettes/invoices/save_new.yml +23 -10
  82. data/spec/vcr_cassettes/invoices/save_new_with_comments.yml +61 -0
  83. data/spec/vcr_cassettes/invoices/save_new_with_country.yml +60 -0
  84. data/spec/vcr_cassettes/invoices/save_new_with_country_GB.yml +61 -0
  85. data/spec/vcr_cassettes/invoices/save_new_with_country_KR.yml +61 -0
  86. data/spec/vcr_cassettes/invoices/save_new_with_country_Norge.yml +60 -0
  87. data/spec/vcr_cassettes/invoices/save_new_with_country_Norway.yml +60 -0
  88. data/spec/vcr_cassettes/invoices/save_new_with_country_Sverige.yml +60 -0
  89. data/spec/vcr_cassettes/invoices/save_new_with_country_VA.yml +61 -0
  90. data/spec/vcr_cassettes/invoices/save_new_with_country_VI.yml +61 -0
  91. data/spec/vcr_cassettes/invoices/save_new_with_country_empty_string.yml +60 -0
  92. data/spec/vcr_cassettes/invoices/save_new_with_country_nil.yml +60 -0
  93. data/spec/vcr_cassettes/invoices/save_old.yml +25 -13
  94. data/spec/vcr_cassettes/invoices/save_old_with_empty_comments.yml +61 -0
  95. data/spec/vcr_cassettes/invoices/save_old_with_empty_country.yml +60 -0
  96. data/spec/vcr_cassettes/invoices/save_old_with_nil_comments.yml +61 -0
  97. data/spec/vcr_cassettes/invoices/save_old_with_nil_country.yml +60 -0
  98. data/spec/vcr_cassettes/invoices/save_with_nested_model.yml +23 -10
  99. data/spec/vcr_cassettes/invoices/save_with_specially_named_attribute.yml +23 -10
  100. data/spec/vcr_cassettes/invoices/search_by_name.yml +28 -11
  101. data/spec/vcr_cassettes/invoices/search_miss.yml +21 -8
  102. data/spec/vcr_cassettes/invoices/search_with_special_char.yml +21 -8
  103. data/spec/vcr_cassettes/invoices/single_param_find_by_hash.yml +24 -11
  104. data/spec/vcr_cassettes/orders/all.yml +120 -107
  105. data/spec/vcr_cassettes/orders/filter_hit.yml +28 -12
  106. data/spec/vcr_cassettes/orders/filter_invalid.yml +20 -6
  107. data/spec/vcr_cassettes/orders/find_by_hash_failure.yml +21 -8
  108. data/spec/vcr_cassettes/orders/find_failure.yml +21 -8
  109. data/spec/vcr_cassettes/orders/find_id_1.yml +23 -10
  110. data/spec/vcr_cassettes/orders/find_new.yml +26 -14
  111. data/spec/vcr_cassettes/orders/housework_invalid_tax_reduction_type.yml +57 -0
  112. data/spec/vcr_cassettes/orders/housework_othercoses_invalid.yml +57 -0
  113. data/spec/vcr_cassettes/orders/housework_type_babysitting.yml +24 -10
  114. data/spec/vcr_cassettes/orders/housework_type_cleaning.yml +24 -10
  115. data/spec/vcr_cassettes/orders/housework_type_construction.yml +24 -10
  116. data/spec/vcr_cassettes/orders/housework_type_cooking.yml +21 -7
  117. data/spec/vcr_cassettes/orders/housework_type_electricity.yml +24 -10
  118. data/spec/vcr_cassettes/orders/housework_type_gardening.yml +24 -10
  119. data/spec/vcr_cassettes/orders/housework_type_glassmetalwork.yml +24 -10
  120. data/spec/vcr_cassettes/orders/housework_type_grounddrainagework.yml +24 -10
  121. data/spec/vcr_cassettes/orders/housework_type_hvac.yml +24 -10
  122. data/spec/vcr_cassettes/orders/housework_type_itservices.yml +60 -0
  123. data/spec/vcr_cassettes/orders/housework_type_majorappliancerepair.yml +60 -0
  124. data/spec/vcr_cassettes/orders/housework_type_masonry.yml +24 -10
  125. data/spec/vcr_cassettes/orders/housework_type_movingservices.yml +60 -0
  126. data/spec/vcr_cassettes/orders/housework_type_othercare.yml +24 -10
  127. data/spec/vcr_cassettes/orders/housework_type_othercosts.yml +24 -10
  128. data/spec/vcr_cassettes/orders/housework_type_paintingwallpapering.yml +24 -10
  129. data/spec/vcr_cassettes/orders/housework_type_snowplowing.yml +24 -10
  130. data/spec/vcr_cassettes/orders/housework_type_textileclothing.yml +24 -10
  131. data/spec/vcr_cassettes/orders/housework_type_tutoring.yml +21 -7
  132. data/spec/vcr_cassettes/orders/housework_without_tax_reduction_type.yml +57 -0
  133. data/spec/vcr_cassettes/orders/multi_param_find_by_hash.yml +22 -9
  134. data/spec/vcr_cassettes/orders/save_new.yml +23 -10
  135. data/spec/vcr_cassettes/orders/save_old.yml +25 -13
  136. data/spec/vcr_cassettes/orders/save_with_nested_model.yml +23 -10
  137. data/spec/vcr_cassettes/orders/search_by_name.yml +25 -11
  138. data/spec/vcr_cassettes/orders/search_miss.yml +21 -8
  139. data/spec/vcr_cassettes/orders/search_with_special_char.yml +21 -8
  140. data/spec/vcr_cassettes/orders/single_param_find_by_hash.yml +23 -10
  141. data/spec/vcr_cassettes/projects/all.yml +41 -16
  142. data/spec/vcr_cassettes/projects/find_by_hash_failure.yml +21 -8
  143. data/spec/vcr_cassettes/projects/find_failure.yml +21 -8
  144. data/spec/vcr_cassettes/projects/find_id_1.yml +21 -8
  145. data/spec/vcr_cassettes/projects/find_new.yml +24 -11
  146. data/spec/vcr_cassettes/projects/multi_param_find_by_hash.yml +23 -10
  147. data/spec/vcr_cassettes/projects/save_new.yml +22 -8
  148. data/spec/vcr_cassettes/projects/save_old.yml +24 -11
  149. data/spec/vcr_cassettes/projects/single_param_find_by_hash.yml +22 -9
  150. data/spec/vcr_cassettes/termsofpayments/all.yml +31 -14
  151. data/spec/vcr_cassettes/termsofpayments/find_failure.yml +21 -8
  152. data/spec/vcr_cassettes/termsofpayments/find_id_1.yml +22 -9
  153. data/spec/vcr_cassettes/termsofpayments/find_new.yml +23 -10
  154. data/spec/vcr_cassettes/termsofpayments/save_new.yml +22 -8
  155. data/spec/vcr_cassettes/termsofpayments/save_old.yml +23 -10
  156. data/spec/vcr_cassettes/units/all.yml +31 -12
  157. data/spec/vcr_cassettes/units/find_failure.yml +21 -8
  158. data/spec/vcr_cassettes/units/find_id_1.yml +21 -8
  159. data/spec/vcr_cassettes/units/find_new.yml +23 -12
  160. data/spec/vcr_cassettes/units/save_new.yml +22 -10
  161. data/spec/vcr_cassettes/units/save_old.yml +23 -12
  162. data/spec/vcr_cassettes/units/save_with_specially_named_attribute.yml +22 -10
  163. data/temp.txt +1 -0
  164. metadata +99 -21
  165. data/spec/support/matchers/type/have_country_code_matcher.rb +0 -15
@@ -20,13 +20,14 @@ describe Fortnox::API::Types::Email do
20
20
  end
21
21
 
22
22
  context 'when created with valid email' do
23
- emails = ['valid@example.com', 'kanal_75_ab-faktura@mail.unit4agresso.readsoftonline.com']
24
-
25
- emails.each do |email|
26
- subject { described_class[input] }
27
-
28
- let(:input) { email }
29
- it { is_expected.to eq input }
23
+ valid_emails = [
24
+ 'valid@example.com',
25
+ 'kanal_75_ab-faktura@mail.unit4agresso.readsoftonline.com',
26
+ 'sköldpadda@example.com'
27
+ ]
28
+
29
+ valid_emails.each do |email|
30
+ it { expect(described_class[email]).to eq email }
30
31
  end
31
32
  end
32
33
 
@@ -6,7 +6,6 @@ require 'fortnox/api/types/examples/enum'
6
6
 
7
7
  describe Fortnox::API::Types do
8
8
  it_behaves_like 'enum', 'ArticleType', 'ArticleTypes'
9
- it_behaves_like 'enum', 'CountryCode', 'CountryCodes', auto_crop: true
10
9
  it_behaves_like 'enum', 'Currency', 'Currencies', auto_crop: true
11
10
  it_behaves_like 'enum', 'CustomerType', 'CustomerTypes'
12
11
  it_behaves_like 'enum', 'DiscountType', 'DiscountTypes'
@@ -14,4 +13,5 @@ describe Fortnox::API::Types do
14
13
  it_behaves_like 'enum', 'VATType', 'VATTypes'
15
14
  it_behaves_like 'enum', 'DefaultDeliveryType', 'DefaultDeliveryTypeValues'
16
15
  it_behaves_like 'enum', 'ProjectStatusType', 'ProjectStatusTypes'
16
+ it_behaves_like 'enum', 'TaxReductionType', 'TaxReductionTypes'
17
17
  end
@@ -14,7 +14,7 @@ shared_examples_for 'DocumentRow' do |valid_hash|
14
14
 
15
15
  it { is_expected.to have_sized_float(:price, 0.0, 99_999_999_999.9, valid_hash) }
16
16
 
17
- it do
17
+ it do # rubocop:disable RSpec/ExampleLength
18
18
  is_expected.to have_sized_float(
19
19
  :delivered_quantity,
20
20
  -9_999_999_999_999.9,
@@ -14,29 +14,32 @@ describe 'HouseworkTypes', integration: true do
14
14
  before { set_api_test_configuration }
15
15
 
16
16
  let(:repository) { Fortnox::API::Repository::Order.new }
17
- let(:valid_model) do
18
- Fortnox::API::Model::Order.new(customer_number: '1', order_rows: [order_row])
19
- end
20
- let(:order_row) do
21
- Fortnox::API::Types::OrderRow.new(ordered_quantity: 1,
22
- article_number: '0000',
23
- housework_type: housework_type)
24
- end
25
17
 
26
- shared_examples_for 'housework type' do |type, legacy: false|
18
+ shared_examples_for 'housework type' do |type, tax_reduction_type, legacy: false, housework: true|
27
19
  subject do
28
- lambda do
29
- VCR.use_cassette("orders/housework_type_#{type.downcase}") do
30
- repository.save(valid_model)
31
- end
32
- end
20
+ cassette = "orders/housework_type_#{type.downcase}"
21
+ -> { VCR.use_cassette(cassette) { repository.save(document) } }
33
22
  end
34
23
 
35
- let(:error_message) { 'Skattereduktion för den valda typen av husarbete har upphört.' }
36
- let(:housework_type) { Fortnox::API::Types::HouseworkTypes[type] }
24
+ let(:document) do
25
+ Fortnox::API::Model::Order.new(
26
+ customer_number: '1',
27
+ tax_reduction_type: tax_reduction_type,
28
+ order_rows: [
29
+ Fortnox::API::Types::OrderRow.new(
30
+ ordered_quantity: 1,
31
+ article_number: '0000',
32
+ housework_type: Fortnox::API::Types::HouseworkTypes[type],
33
+ housework: housework
34
+ )
35
+ ]
36
+ )
37
+ end
37
38
 
38
39
  context "when creating an OrderRow with housework_type set to #{type}" do
39
40
  if legacy
41
+ let(:error_message) { 'Skattereduktion för den valda typen av husarbete har upphört.' }
42
+
40
43
  it 'raises an error' do
41
44
  is_expected.to raise_error(Fortnox::API::RemoteServerError, error_message)
42
45
  end
@@ -46,23 +49,137 @@ describe 'HouseworkTypes', integration: true do
46
49
  end
47
50
  end
48
51
 
49
- it_behaves_like 'housework type', 'CONSTRUCTION'
50
- it_behaves_like 'housework type', 'ELECTRICITY'
51
- it_behaves_like 'housework type', 'GLASSMETALWORK'
52
- it_behaves_like 'housework type', 'GROUNDDRAINAGEWORK'
53
- it_behaves_like 'housework type', 'MASONRY'
54
- it_behaves_like 'housework type', 'PAINTINGWALLPAPERING'
55
- it_behaves_like 'housework type', 'HVAC'
56
- it_behaves_like 'housework type', 'CLEANING'
57
- it_behaves_like 'housework type', 'TEXTILECLOTHING'
58
- it_behaves_like 'housework type', 'CLEANING'
59
- it_behaves_like 'housework type', 'SNOWPLOWING'
60
- it_behaves_like 'housework type', 'GARDENING'
61
- it_behaves_like 'housework type', 'BABYSITTING'
62
- it_behaves_like 'housework type', 'OTHERCARE'
63
- it_behaves_like 'housework type', 'OTHERCOSTS'
64
-
65
- it_behaves_like 'housework type', 'COOKING', legacy: true
66
- it_behaves_like 'housework type', 'TUTORING', legacy: true
52
+ TYPE_ROT = Fortnox::API::Types::TaxReductionTypes['rot']
53
+ TYPE_RUT = Fortnox::API::Types::TaxReductionTypes['rut']
54
+
55
+ it_behaves_like 'housework type', 'CONSTRUCTION', TYPE_ROT
56
+ it_behaves_like 'housework type', 'ELECTRICITY', TYPE_ROT
57
+ it_behaves_like 'housework type', 'GLASSMETALWORK', TYPE_ROT
58
+ it_behaves_like 'housework type', 'GROUNDDRAINAGEWORK', TYPE_ROT
59
+ it_behaves_like 'housework type', 'MASONRY', TYPE_ROT
60
+ it_behaves_like 'housework type', 'PAINTINGWALLPAPERING', TYPE_ROT
61
+ it_behaves_like 'housework type', 'HVAC', TYPE_ROT
62
+ it_behaves_like 'housework type', 'OTHERCOSTS', TYPE_ROT, housework: false
63
+
64
+ it_behaves_like 'housework type', 'MAJORAPPLIANCEREPAIR', TYPE_RUT
65
+ it_behaves_like 'housework type', 'MOVINGSERVICES', TYPE_RUT
66
+ it_behaves_like 'housework type', 'ITSERVICES', TYPE_RUT
67
+ it_behaves_like 'housework type', 'CLEANING', TYPE_RUT
68
+ it_behaves_like 'housework type', 'TEXTILECLOTHING', TYPE_RUT
69
+ it_behaves_like 'housework type', 'SNOWPLOWING', TYPE_RUT
70
+ it_behaves_like 'housework type', 'GARDENING', TYPE_RUT
71
+ it_behaves_like 'housework type', 'BABYSITTING', TYPE_RUT
72
+ it_behaves_like 'housework type', 'OTHERCARE', TYPE_RUT
73
+ it_behaves_like 'housework type', 'OTHERCOSTS', TYPE_RUT, housework: false
74
+
75
+ # rubocop:disable RSpec/RepeatedDescription
76
+ pending 'to be added' do
77
+ raise Exception, 'Will be supported 2021-01-01'
78
+ # it_behaves_like 'housework type', 'HOMEMAINTENANCE', TYPE_RUT
79
+ # it_behaves_like 'housework type', 'FURNISHING', TYPE_RUT
80
+ # it_behaves_like 'housework type', 'TRANSPORTATIONSERVICES', TYPE_RUT
81
+ # it_behaves_like 'housework type', 'WASHINGANDCAREOFCLOTHING', TYPE_RUT
82
+ end
83
+
84
+ pending 'to be added' do
85
+ raise Exception, 'Will be supported 2021-01-01'
86
+ # it_behaves_like 'housework type', 'SOLARCELLS', TYPE_GREEN
87
+ # it_behaves_like 'housework type', 'STORAGESELFPRODUCEDELECTRICTY', TYPE_GREEN
88
+ # it_behaves_like 'housework type', 'CHARGINGSTATIONELECTRICVEHICLE', TYPE_GREEN
89
+ # it_behaves_like 'housework type', 'OTHERCOSTS', TYPE_GREEN
90
+ end
91
+ # rubocop:enable RSpec/RepeatedDescription
92
+
93
+ it_behaves_like 'housework type', 'COOKING', TYPE_RUT, legacy: true
94
+ it_behaves_like 'housework type', 'TUTORING', TYPE_RUT, legacy: true
95
+
96
+ describe 'without tax reduction type' do
97
+ subject do
98
+ cassette = 'orders/housework_without_tax_reduction_type'
99
+ -> { VCR.use_cassette(cassette) { repository.save(document) } }
100
+ end
101
+
102
+ let(:document) do
103
+ Fortnox::API::Model::Order.new(
104
+ customer_number: '1',
105
+ order_rows: [
106
+ Fortnox::API::Types::OrderRow.new(
107
+ ordered_quantity: 1,
108
+ article_number: '0000',
109
+ housework_type: Fortnox::API::Types::HouseworkTypes['CONSTRUCTION'],
110
+ housework: true
111
+ )
112
+ ]
113
+ )
114
+ end
115
+
116
+ let(:error_message) do
117
+ 'Dokument utan angiven skattereduktionstyp får inte innehålla artikelrader med husarbetestyp.'
118
+ end
119
+
120
+ it 'raises an error' do
121
+ is_expected.to raise_error(Fortnox::API::RemoteServerError, error_message)
122
+ end
123
+ end
124
+
125
+ describe 'with OTHERCOSTS' do
126
+ subject do
127
+ cassette = 'orders/housework_othercoses_invalid'
128
+ -> { VCR.use_cassette(cassette) { repository.save(document) } }
129
+ end
130
+
131
+ let(:document) do
132
+ Fortnox::API::Model::Order.new(
133
+ customer_number: '1',
134
+ tax_reduction_type: TYPE_ROT,
135
+ order_rows: [
136
+ Fortnox::API::Types::OrderRow.new(
137
+ ordered_quantity: 1,
138
+ article_number: '0000',
139
+ housework_type: Fortnox::API::Types::HouseworkTypes['OTHERCOSTS'],
140
+ housework: true
141
+ )
142
+ ]
143
+ )
144
+ end
145
+
146
+ let(:error_message) { 'Kan inte sätta typen övrig kostnad på en rad markerad som husarbete.' }
147
+
148
+ it "can't have housework set to true" do
149
+ is_expected.to raise_error(Fortnox::API::RemoteServerError, error_message)
150
+ end
151
+ end
152
+
153
+ describe 'with wrong tax reduction type' do
154
+ subject do
155
+ cassette = 'orders/housework_invalid_tax_reduction_type'
156
+ -> { VCR.use_cassette(cassette) { repository.save(document) } }
157
+ end
158
+
159
+ let(:type) { 'CONSTRUCTION' }
160
+ let(:document) do
161
+ Fortnox::API::Model::Order.new(
162
+ customer_number: '1',
163
+ tax_reduction_type: TYPE_RUT,
164
+ order_rows: [
165
+ Fortnox::API::Types::OrderRow.new(
166
+ ordered_quantity: 1,
167
+ article_number: '0000',
168
+ housework_type: Fortnox::API::Types::HouseworkTypes[type],
169
+ housework: true
170
+ )
171
+ ]
172
+ )
173
+ end
174
+
175
+ let(:error_message) do
176
+ "Dokument med skattereduktionstypen '#{TYPE_RUT}' " \
177
+ "får inte innehålla rader med husarbetestypen '#{type}'."
178
+ end
179
+
180
+ it 'raises an error' do
181
+ is_expected.to raise_error(Fortnox::API::RemoteServerError, error_message)
182
+ end
183
+ end
67
184
  end
68
185
  # rubocop:enable RSpec/DescribeClass
@@ -104,7 +104,9 @@ describe Fortnox::API do
104
104
  end
105
105
 
106
106
  shared_examples_for 'valid argument' do
107
- subject { described_class.configure { |config| config.access_tokens = value } }
107
+ subject { described_class.config.access_tokens }
108
+
109
+ before { described_class.configure { |config| config.access_tokens = value } }
108
110
 
109
111
  it { is_expected.to eql(value) }
110
112
  end
@@ -15,6 +15,10 @@ http_interactions:
15
15
  - 9aBA8ZgsvR
16
16
  Access-Token:
17
17
  - ccaef817-d5d8-4b1c-a316-54f3e55c5c54
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ User-Agent:
21
+ - Ruby
18
22
  response:
19
23
  status:
20
24
  code: 200
@@ -23,23 +27,32 @@ http_interactions:
23
27
  Server:
24
28
  - nginx
25
29
  Date:
26
- - Sun, 08 Oct 2017 21:51:31 GMT
30
+ - Mon, 21 Dec 2020 20:40:04 GMT
27
31
  Content-Type:
28
32
  - application/json
29
33
  Connection:
30
34
  - close
31
35
  Vary:
32
36
  - Accept-Encoding
33
- - Accept-Encoding
34
37
  X-Rack-Responsetime:
35
- - '21'
38
+ - '30'
36
39
  X-Uid:
37
- - 1aa0352f
40
+ - f81e8818
38
41
  X-Build:
39
- - e1392b4cf7
42
+ - d59e2acefa
43
+ Strict-Transport-Security:
44
+ - max-age=31536000; includeSubdomains
45
+ X-Xss-Protection:
46
+ - 1; mode=block
47
+ X-Content-Type-Options:
48
+ - nosniff
49
+ X-Frame-Options:
50
+ - sameorigin
51
+ Referrer-Policy:
52
+ - strict-origin-when-cross-origin
40
53
  body:
41
- encoding: UTF-8
42
- string: '{"MetaInformation":{"@TotalResources":12,"@TotalPages":1,"@CurrentPage":1},"Articles":[{"@url":"https:\/\/api.fortnox.se\/3\/articles\/0000","ArticleNumber":"0000","Description":"Testartikel","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":"","StockValue":"0","Unit":null,"VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/0001","ArticleNumber":"0001","Description":"Cykelpump","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":"100","QuantityInStock":"0","ReservedQuantity":"0","StockPlace":"","StockValue":"0","Unit":null,"VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/1","ArticleNumber":"1","Description":"Testartikel","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":"100","QuantityInStock":"0","ReservedQuantity":"0","StockPlace":"","StockValue":"0","Unit":null,"VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/2","ArticleNumber":"2","Description":"A
54
+ encoding: ASCII-8BIT
55
+ string: '{"MetaInformation":{"@TotalResources":29,"@TotalPages":1,"@CurrentPage":1},"Articles":[{"@url":"https:\/\/api.fortnox.se\/3\/articles\/0000","ArticleNumber":"0000","Description":"Testartikel","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":"","StockValue":"0","Unit":null,"VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/0001","ArticleNumber":"0001","Description":"Cykelpump","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":"100","QuantityInStock":"0","ReservedQuantity":"0","StockPlace":"","StockValue":"0","Unit":null,"VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/1","ArticleNumber":"1","Description":"Testartikel","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":"100","QuantityInStock":"0","ReservedQuantity":"0","StockPlace":"","StockValue":"0","Unit":null,"VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/2","ArticleNumber":"2","Description":"A
43
56
  value","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/3","ArticleNumber":"3","Description":"Test
44
57
  article","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/4","ArticleNumber":"4","Description":"Test
45
58
  article","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/5","ArticleNumber":"5","Description":"Test
@@ -48,7 +61,24 @@ http_interactions:
48
61
  article","DisposableQuantity":"0","EAN":"5901234123457","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/8","ArticleNumber":"8","Description":"A
49
62
  value","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/9","ArticleNumber":"9","Description":"A
50
63
  value","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/10","ArticleNumber":"10","Description":"Abc
51
- 123","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false}]}'
64
+ 123","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/11","ArticleNumber":"11","Description":"A
65
+ value","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/12","ArticleNumber":"12","Description":"Test
66
+ article","DisposableQuantity":"0","EAN":"5901234123457","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/13","ArticleNumber":"13","Description":"Test
67
+ article","DisposableQuantity":"0","EAN":"5901234123457","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/14","ArticleNumber":"14","Description":"A
68
+ value","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":null,"VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/15","ArticleNumber":"15","Description":"A
69
+ value","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/16","ArticleNumber":"16","Description":"Test
70
+ article","DisposableQuantity":"0","EAN":"5901234123457","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/17","ArticleNumber":"17","Description":"A
71
+ value","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/18","ArticleNumber":"18","Description":"Updated
72
+ description","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":null,"VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/19","ArticleNumber":"19","Description":"Updated
73
+ description","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":null,"VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/20","ArticleNumber":"20","Description":"Test
74
+ article","DisposableQuantity":"0","EAN":"5901234123457","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/21","ArticleNumber":"21","Description":"Updated
75
+ description","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":null,"VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/22","ArticleNumber":"22","Description":"Test
76
+ article","DisposableQuantity":"0","EAN":"5901234123457","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/23","ArticleNumber":"23","Description":"Updated
77
+ description","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":null,"VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/24","ArticleNumber":"24","Description":"Test
78
+ article","DisposableQuantity":"0","EAN":"5901234123457","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/25","ArticleNumber":"25","Description":"A
79
+ value","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/26","ArticleNumber":"26","Description":"Updated
80
+ description","DisposableQuantity":"0","EAN":"","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":null,"VAT":null,"WebshopArticle":false},{"@url":"https:\/\/api.fortnox.se\/3\/articles\/27","ArticleNumber":"27","Description":"Test
81
+ article","DisposableQuantity":"0","EAN":"5901234123457","Housework":false,"PurchasePrice":"0","SalesPrice":null,"QuantityInStock":"0","ReservedQuantity":"0","StockPlace":null,"StockValue":"0","Unit":"","VAT":null,"WebshopArticle":false}]}'
52
82
  http_version:
53
- recorded_at: Sun, 08 Oct 2017 21:51:31 GMT
54
- recorded_with: VCR 3.0.3
83
+ recorded_at: Mon, 21 Dec 2020 20:40:04 GMT
84
+ recorded_with: VCR 4.0.0
@@ -15,6 +15,10 @@ http_interactions:
15
15
  - 9aBA8ZgsvR
16
16
  Access-Token:
17
17
  - ccaef817-d5d8-4b1c-a316-54f3e55c5c54
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ User-Agent:
21
+ - Ruby
18
22
  response:
19
23
  status:
20
24
  code: 200
@@ -23,23 +27,32 @@ http_interactions:
23
27
  Server:
24
28
  - nginx
25
29
  Date:
26
- - Sun, 08 Oct 2017 21:51:44 GMT
30
+ - Mon, 21 Dec 2020 20:40:04 GMT
27
31
  Content-Type:
28
32
  - application/json
29
33
  Connection:
30
34
  - close
31
35
  Vary:
32
36
  - Accept-Encoding
33
- - Accept-Encoding
34
37
  X-Rack-Responsetime:
35
- - '20'
38
+ - '26'
36
39
  X-Uid:
37
- - 4b1a3e1d
40
+ - 750fbfe3
38
41
  X-Build:
39
- - e1392b4cf7
42
+ - d59e2acefa
43
+ Strict-Transport-Security:
44
+ - max-age=31536000; includeSubdomains
45
+ X-Xss-Protection:
46
+ - 1; mode=block
47
+ X-Content-Type-Options:
48
+ - nosniff
49
+ X-Frame-Options:
50
+ - sameorigin
51
+ Referrer-Policy:
52
+ - strict-origin-when-cross-origin
40
53
  body:
41
- encoding: UTF-8
54
+ encoding: ASCII-8BIT
42
55
  string: '{"MetaInformation":{"@TotalResources":0,"@TotalPages":0,"@CurrentPage":1},"Articles":[]}'
43
56
  http_version:
44
- recorded_at: Sun, 08 Oct 2017 21:51:44 GMT
45
- recorded_with: VCR 3.0.3
57
+ recorded_at: Mon, 21 Dec 2020 20:40:04 GMT
58
+ recorded_with: VCR 4.0.0
@@ -15,6 +15,10 @@ http_interactions:
15
15
  - 9aBA8ZgsvR
16
16
  Access-Token:
17
17
  - ccaef817-d5d8-4b1c-a316-54f3e55c5c54
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ User-Agent:
21
+ - Ruby
18
22
  response:
19
23
  status:
20
24
  code: 404
@@ -23,23 +27,32 @@ http_interactions:
23
27
  Server:
24
28
  - nginx
25
29
  Date:
26
- - Sun, 08 Oct 2017 21:51:44 GMT
30
+ - Mon, 21 Dec 2020 20:40:04 GMT
27
31
  Content-Type:
28
32
  - application/json
29
33
  Connection:
30
34
  - close
31
35
  Vary:
32
36
  - Accept-Encoding
33
- - Accept-Encoding
34
37
  X-Rack-Responsetime:
35
- - '20'
38
+ - '24'
36
39
  X-Uid:
37
- - 9d7a18ed
40
+ - b205151d
38
41
  X-Build:
39
- - e1392b4cf7
42
+ - d59e2acefa
43
+ Strict-Transport-Security:
44
+ - max-age=31536000; includeSubdomains
45
+ X-Xss-Protection:
46
+ - 1; mode=block
47
+ X-Content-Type-Options:
48
+ - nosniff
49
+ X-Frame-Options:
50
+ - sameorigin
51
+ Referrer-Policy:
52
+ - strict-origin-when-cross-origin
40
53
  body:
41
- encoding: UTF-8
54
+ encoding: ASCII-8BIT
42
55
  string: '{"ErrorInformation":{"Error":1,"Message":"Kan inte hitta artikeln.","Code":2000428}}'
43
56
  http_version:
44
- recorded_at: Sun, 08 Oct 2017 21:51:44 GMT
45
- recorded_with: VCR 3.0.3
57
+ recorded_at: Mon, 21 Dec 2020 20:40:04 GMT
58
+ recorded_with: VCR 4.0.0
@@ -15,6 +15,10 @@ http_interactions:
15
15
  - 9aBA8ZgsvR
16
16
  Access-Token:
17
17
  - ccaef817-d5d8-4b1c-a316-54f3e55c5c54
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ User-Agent:
21
+ - Ruby
18
22
  response:
19
23
  status:
20
24
  code: 200
@@ -23,23 +27,32 @@ http_interactions:
23
27
  Server:
24
28
  - nginx
25
29
  Date:
26
- - Sun, 08 Oct 2017 21:51:43 GMT
30
+ - Mon, 21 Dec 2020 20:40:04 GMT
27
31
  Content-Type:
28
32
  - application/json
29
33
  Connection:
30
34
  - close
31
35
  Vary:
32
36
  - Accept-Encoding
33
- - Accept-Encoding
34
37
  X-Rack-Responsetime:
35
- - '32'
38
+ - '27'
36
39
  X-Uid:
37
- - 8b796198
40
+ - b06edbf5
38
41
  X-Build:
39
- - e1392b4cf7
42
+ - d59e2acefa
43
+ Strict-Transport-Security:
44
+ - max-age=31536000; includeSubdomains
45
+ X-Xss-Protection:
46
+ - 1; mode=block
47
+ X-Content-Type-Options:
48
+ - nosniff
49
+ X-Frame-Options:
50
+ - sameorigin
51
+ Referrer-Policy:
52
+ - strict-origin-when-cross-origin
40
53
  body:
41
- encoding: UTF-8
42
- string: '{"Article":{"@url":"https:\/\/api.fortnox.se\/3\/articles\/1","ArticleNumber":"1","Bulky":false,"ConstructionAccount":1030,"Depth":null,"Description":"Testartikel","DisposableQuantity":-163995.5,"EAN":"","EUAccount":1030,"EUVATAccount":1030,"ExportAccount":1030,"Height":null,"Housework":false,"HouseworkType":null,"Active":true,"Manufacturer":null,"ManufacturerArticleNumber":null,"Note":"","PurchaseAccount":1030,"PurchasePrice":0,"QuantityInStock":0,"ReservedQuantity":163995.5,"SalesAccount":1030,"StockGoods":false,"StockPlace":"","StockValue":0,"StockWarning":null,"SupplierName":null,"SupplierNumber":null,"Type":"STOCK","Unit":null,"VAT":0,"WebshopArticle":false,"Weight":null,"Width":null,"Expired":false,"SalesPrice":100,"CostCalculationMethod":null,"StockAccount":null,"StockChangeAccount":null,"DirectCost":0,"FreightCost":0,"OtherCost":0}}'
54
+ encoding: ASCII-8BIT
55
+ string: '{"Article":{"@url":"https:\/\/api.fortnox.se\/3\/articles\/1","ArticleNumber":"1","Bulky":false,"ConstructionAccount":1030,"Depth":null,"Description":"Testartikel","DisposableQuantity":-163995.5,"EAN":"","EUAccount":1030,"EUVATAccount":1030,"ExportAccount":1030,"Height":null,"Housework":false,"HouseworkType":null,"Active":true,"Manufacturer":null,"ManufacturerArticleNumber":null,"Note":"","PurchaseAccount":1030,"PurchasePrice":0,"QuantityInStock":0,"ReservedQuantity":163995.5,"SalesAccount":1030,"StockGoods":false,"StockPlace":"","StockValue":0,"StockWarning":null,"SupplierName":null,"SupplierNumber":null,"Type":"STOCK","Unit":null,"VAT":0,"WebshopArticle":false,"Weight":null,"Width":null,"Expired":false,"SalesPrice":100,"CostCalculationMethod":null,"StockAccount":null,"StockChangeAccount":null,"DirectCost":null,"FreightCost":null,"OtherCost":null,"DefaultStockPoint":null,"DefaultStockLocation":null}}'
43
56
  http_version:
44
- recorded_at: Sun, 08 Oct 2017 21:51:43 GMT
45
- recorded_with: VCR 3.0.3
57
+ recorded_at: Mon, 21 Dec 2020 20:40:04 GMT
58
+ recorded_with: VCR 4.0.0