fortnox-api 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +9 -1104
  4. data/.travis.yml +22 -2
  5. data/Gemfile +3 -1
  6. data/Guardfile +4 -2
  7. data/README.md +2 -2
  8. data/Rakefile +3 -1
  9. data/bin/console +17 -3
  10. data/fortnox-api.gemspec +32 -27
  11. data/lib/fortnox/api.rb +17 -16
  12. data/lib/fortnox/api/circular_queue.rb +13 -7
  13. data/lib/fortnox/api/mappers.rb +29 -25
  14. data/lib/fortnox/api/mappers/article.rb +7 -6
  15. data/lib/fortnox/api/mappers/base.rb +18 -16
  16. data/lib/fortnox/api/mappers/base/from_json.rb +37 -30
  17. data/lib/fortnox/api/mappers/base/to_json.rb +39 -37
  18. data/lib/fortnox/api/mappers/customer.rb +7 -7
  19. data/lib/fortnox/api/mappers/default_delivery_types.rb +4 -2
  20. data/lib/fortnox/api/mappers/default_templates.rb +5 -4
  21. data/lib/fortnox/api/mappers/edi_information.rb +5 -4
  22. data/lib/fortnox/api/mappers/email_information.rb +5 -4
  23. data/lib/fortnox/api/mappers/invoice.rb +10 -8
  24. data/lib/fortnox/api/mappers/invoice_row.rb +12 -7
  25. data/lib/fortnox/api/mappers/order.rb +10 -7
  26. data/lib/fortnox/api/mappers/order_row.rb +13 -6
  27. data/lib/fortnox/api/mappers/project.rb +6 -4
  28. data/lib/fortnox/api/mappers/terms_of_payments.rb +17 -0
  29. data/lib/fortnox/api/mappers/unit.rb +17 -0
  30. data/lib/fortnox/api/models.rb +9 -5
  31. data/lib/fortnox/api/models/article.rb +68 -67
  32. data/lib/fortnox/api/models/base.rb +52 -36
  33. data/lib/fortnox/api/models/customer.rb +95 -94
  34. data/lib/fortnox/api/models/document.rb +186 -0
  35. data/lib/fortnox/api/models/invoice.rb +44 -44
  36. data/lib/fortnox/api/models/label.rb +5 -3
  37. data/lib/fortnox/api/models/order.rb +8 -8
  38. data/lib/fortnox/api/models/project.rb +10 -8
  39. data/lib/fortnox/api/models/terms_of_payments.rb +28 -0
  40. data/lib/fortnox/api/models/unit.rb +24 -0
  41. data/lib/fortnox/api/repositories.rb +9 -5
  42. data/lib/fortnox/api/repositories/article.rb +6 -4
  43. data/lib/fortnox/api/repositories/base.rb +49 -46
  44. data/lib/fortnox/api/repositories/base/loaders.rb +32 -36
  45. data/lib/fortnox/api/repositories/base/savers.rb +23 -21
  46. data/lib/fortnox/api/repositories/customer.rb +6 -4
  47. data/lib/fortnox/api/repositories/invoice.rb +6 -4
  48. data/lib/fortnox/api/repositories/order.rb +6 -4
  49. data/lib/fortnox/api/repositories/project.rb +6 -4
  50. data/lib/fortnox/api/repositories/terms_of_payments.rb +17 -0
  51. data/lib/fortnox/api/repositories/unit.rb +17 -0
  52. data/lib/fortnox/api/request_handling.rb +12 -12
  53. data/lib/fortnox/api/types.rb +62 -11
  54. data/lib/fortnox/api/types/default_delivery_types.rb +5 -3
  55. data/lib/fortnox/api/types/default_templates.rb +3 -1
  56. data/lib/fortnox/api/types/defaulted.rb +2 -2
  57. data/lib/fortnox/api/types/document_row.rb +41 -42
  58. data/lib/fortnox/api/types/edi_information.rb +10 -8
  59. data/lib/fortnox/api/types/email_information.rb +10 -8
  60. data/lib/fortnox/api/types/enums.rb +60 -47
  61. data/lib/fortnox/api/types/invoice_row.rb +8 -8
  62. data/lib/fortnox/api/types/model.rb +14 -10
  63. data/lib/fortnox/api/types/nullable.rb +7 -7
  64. data/lib/fortnox/api/types/order_row.rb +5 -5
  65. data/lib/fortnox/api/types/required.rb +5 -5
  66. data/lib/fortnox/api/types/sized.rb +14 -6
  67. data/lib/fortnox/api/version.rb +3 -1
  68. data/spec/fortnox/api/mappers/article_spec.rb +3 -1
  69. data/spec/fortnox/api/mappers/base/from_json_spec.rb +15 -13
  70. data/spec/fortnox/api/mappers/base/to_json_spec.rb +4 -3
  71. data/spec/fortnox/api/mappers/base_spec.rb +40 -35
  72. data/spec/fortnox/api/mappers/contexts/json_conversion.rb +12 -11
  73. data/spec/fortnox/api/mappers/customer_spec.rb +3 -1
  74. data/spec/fortnox/api/mappers/default_delivery_types_spec.rb +3 -1
  75. data/spec/fortnox/api/mappers/edi_information_spec.rb +4 -2
  76. data/spec/fortnox/api/mappers/email_information_spec.rb +4 -2
  77. data/spec/fortnox/api/mappers/examples/mapper.rb +17 -9
  78. data/spec/fortnox/api/mappers/invoice_row_spec.rb +8 -3
  79. data/spec/fortnox/api/mappers/invoice_spec.rb +4 -1
  80. data/spec/fortnox/api/mappers/order_row_spec.rb +9 -2
  81. data/spec/fortnox/api/mappers/order_spec.rb +4 -1
  82. data/spec/fortnox/api/mappers/project_spec.rb +3 -1
  83. data/spec/fortnox/api/mappers/terms_of_payments_spec.rb +16 -0
  84. data/spec/fortnox/api/mappers/unit_spec.rb +57 -0
  85. data/spec/fortnox/api/models/article_spec.rb +2 -0
  86. data/spec/fortnox/api/models/base_spec.rb +46 -38
  87. data/spec/fortnox/api/models/customer_spec.rb +2 -0
  88. data/spec/fortnox/api/models/examples/document_base.rb +5 -3
  89. data/spec/fortnox/api/models/examples/model.rb +12 -9
  90. data/spec/fortnox/api/models/invoice_spec.rb +2 -0
  91. data/spec/fortnox/api/models/order_spec.rb +2 -0
  92. data/spec/fortnox/api/models/project_spec.rb +2 -0
  93. data/spec/fortnox/api/models/terms_of_payments_spec.rb +9 -0
  94. data/spec/fortnox/api/models/unit_spec.rb +31 -0
  95. data/spec/fortnox/api/repositories/article_spec.rb +7 -5
  96. data/spec/fortnox/api/repositories/base_spec.rb +121 -100
  97. data/spec/fortnox/api/repositories/customer_spec.rb +7 -5
  98. data/spec/fortnox/api/repositories/examples/all.rb +5 -4
  99. data/spec/fortnox/api/repositories/examples/find.rb +50 -41
  100. data/spec/fortnox/api/repositories/examples/only.rb +14 -13
  101. data/spec/fortnox/api/repositories/examples/save.rb +23 -29
  102. data/spec/fortnox/api/repositories/examples/save_with_nested_model.rb +11 -11
  103. data/spec/fortnox/api/repositories/examples/save_with_specially_named_attribute.rb +11 -10
  104. data/spec/fortnox/api/repositories/examples/search.rb +15 -15
  105. data/spec/fortnox/api/repositories/invoice_spec.rb +8 -6
  106. data/spec/fortnox/api/repositories/order_spec.rb +8 -6
  107. data/spec/fortnox/api/repositories/project_spec.rb +7 -5
  108. data/spec/fortnox/api/repositories/terms_of_payments_spec.rb +30 -0
  109. data/spec/fortnox/api/repositories/unit_spec.rb +34 -0
  110. data/spec/fortnox/api/types/account_number_spec.rb +12 -9
  111. data/spec/fortnox/api/types/default_delivery_types_spec.rb +6 -4
  112. data/spec/fortnox/api/types/edi_information_spec.rb +9 -7
  113. data/spec/fortnox/api/types/email_information_spec.rb +8 -6
  114. data/spec/fortnox/api/types/email_spec.rb +27 -14
  115. data/spec/fortnox/api/types/enums_spec.rb +3 -1
  116. data/spec/fortnox/api/types/examples/document_row.rb +10 -8
  117. data/spec/fortnox/api/types/examples/enum.rb +29 -22
  118. data/spec/fortnox/api/types/examples/types.rb +8 -4
  119. data/spec/fortnox/api/types/housework_types_spec.rb +68 -0
  120. data/spec/fortnox/api/types/invoice_row_spec.rb +3 -1
  121. data/spec/fortnox/api/types/model_spec.rb +12 -9
  122. data/spec/fortnox/api/types/nullable_spec.rb +8 -6
  123. data/spec/fortnox/api/types/order_row_spec.rb +4 -2
  124. data/spec/fortnox/api/types/required_spec.rb +4 -2
  125. data/spec/fortnox/api/types/sized_spec.rb +18 -16
  126. data/spec/fortnox/api_spec.rb +45 -43
  127. data/spec/spec_helper.rb +9 -6
  128. data/spec/support/helpers.rb +3 -1
  129. data/spec/support/helpers/configuration_helper.rb +2 -0
  130. data/spec/support/helpers/dummy_class_helper.rb +7 -8
  131. data/spec/support/helpers/repository_helper.rb +2 -0
  132. data/spec/support/helpers/when_performing_helper.rb +3 -1
  133. data/spec/support/matchers.rb +2 -0
  134. data/spec/support/matchers/type.rb +3 -1
  135. data/spec/support/matchers/type/attribute_matcher.rb +15 -14
  136. data/spec/support/matchers/type/enum_matcher.rb +9 -7
  137. data/spec/support/matchers/type/have_account_number_matcher.rb +11 -9
  138. data/spec/support/matchers/type/have_country_code_matcher.rb +6 -4
  139. data/spec/support/matchers/type/have_currency_matcher.rb +4 -2
  140. data/spec/support/matchers/type/have_customer_type_matcher.rb +6 -4
  141. data/spec/support/matchers/type/have_default_delivery_type_matcher.rb +4 -2
  142. data/spec/support/matchers/type/have_discount_type_matcher.rb +4 -2
  143. data/spec/support/matchers/type/have_email_matcher.rb +11 -9
  144. data/spec/support/matchers/type/have_housework_type_matcher.rb +9 -0
  145. data/spec/support/matchers/type/have_nullable_date_matcher.rb +29 -29
  146. data/spec/support/matchers/type/have_nullable_matcher.rb +23 -21
  147. data/spec/support/matchers/type/have_nullable_string_matcher.rb +30 -32
  148. data/spec/support/matchers/type/have_sized_float_matcher.rb +4 -2
  149. data/spec/support/matchers/type/have_sized_integer_matcher.rb +4 -2
  150. data/spec/support/matchers/type/have_sized_string_matcher.rb +16 -15
  151. data/spec/support/matchers/type/have_vat_type_matcher.rb +4 -2
  152. data/spec/support/matchers/type/numeric_matcher.rb +25 -23
  153. data/spec/support/matchers/type/require_attribute_matcher.rb +36 -37
  154. data/spec/support/matchers/type/type_matcher.rb +18 -16
  155. data/spec/support/vcr_setup.rb +2 -0
  156. data/spec/vcr_cassettes/orders/{house_work_type_babysitting.yml → housework_type_babysitting.yml} +9 -10
  157. data/spec/vcr_cassettes/orders/{house_work_type_cleaning.yml → housework_type_cleaning.yml} +9 -10
  158. data/spec/vcr_cassettes/orders/{house_work_type_construction.yml → housework_type_construction.yml} +9 -10
  159. data/spec/vcr_cassettes/orders/{house_work_type_cooking.yml → housework_type_cooking.yml} +7 -7
  160. data/spec/vcr_cassettes/orders/{house_work_type_electricity.yml → housework_type_electricity.yml} +9 -10
  161. data/spec/vcr_cassettes/orders/{house_work_type_gardening.yml → housework_type_gardening.yml} +9 -10
  162. data/spec/vcr_cassettes/orders/{house_work_type_glassmetalwork.yml → housework_type_glassmetalwork.yml} +9 -10
  163. data/spec/vcr_cassettes/orders/{house_work_type_grounddrainagework.yml → housework_type_grounddrainagework.yml} +9 -10
  164. data/spec/vcr_cassettes/orders/{house_work_type_hvac.yml → housework_type_hvac.yml} +9 -10
  165. data/spec/vcr_cassettes/orders/{house_work_type_masonry.yml → housework_type_masonry.yml} +9 -10
  166. data/spec/vcr_cassettes/orders/{house_work_type_othercare.yml → housework_type_othercare.yml} +9 -10
  167. data/spec/vcr_cassettes/orders/{house_work_type_othercosts.yml → housework_type_othercosts.yml} +9 -10
  168. data/spec/vcr_cassettes/orders/{house_work_type_paintingwallpapering.yml → housework_type_paintingwallpapering.yml} +9 -10
  169. data/spec/vcr_cassettes/orders/{house_work_type_snowplowing.yml → housework_type_snowplowing.yml} +9 -10
  170. data/spec/vcr_cassettes/orders/{house_work_type_textileclothing.yml → housework_type_textileclothing.yml} +9 -10
  171. data/spec/vcr_cassettes/orders/{house_work_type_tutoring.yml → housework_type_tutoring.yml} +7 -7
  172. data/spec/vcr_cassettes/termsofpayments/all.yml +51 -0
  173. data/spec/vcr_cassettes/termsofpayments/find_failure.yml +45 -0
  174. data/spec/vcr_cassettes/termsofpayments/find_id_1.yml +46 -0
  175. data/spec/vcr_cassettes/termsofpayments/find_new.yml +46 -0
  176. data/spec/vcr_cassettes/termsofpayments/save_new.yml +45 -0
  177. data/spec/vcr_cassettes/termsofpayments/save_old.yml +46 -0
  178. data/spec/vcr_cassettes/units/all.yml +48 -0
  179. data/spec/vcr_cassettes/units/find_failure.yml +45 -0
  180. data/spec/vcr_cassettes/units/find_id_1.yml +46 -0
  181. data/spec/vcr_cassettes/units/find_new.yml +48 -0
  182. data/spec/vcr_cassettes/units/save_new.yml +47 -0
  183. data/spec/vcr_cassettes/units/save_old.yml +48 -0
  184. data/spec/vcr_cassettes/units/save_with_specially_named_attribute.yml +47 -0
  185. metadata +127 -88
  186. data/docs/account.rb +0 -59
  187. data/docs/extraction_script.js +0 -23
  188. data/docs/generation_script.rb +0 -43
  189. data/docs/json/account.json +0 -77
  190. data/lib/fortnox/api/models/document_base.rb +0 -189
  191. data/spec/fortnox/api/types/house_work_types_spec.rb +0 -64
  192. data/spec/support/matchers/type/have_house_work_type_matcher.rb +0 -7
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api'
3
5
  require 'fortnox/api/mappers/edi_information'
4
6
  require 'fortnox/api/mappers/examples/mapper'
5
7
 
6
8
  describe Fortnox::API::Mapper::EDIInformation do
7
- key_map = {
9
+ key_map = {
8
10
  edi_global_location_number: 'EDIGlobalLocationNumber',
9
11
  edi_global_location_number_delivery: 'EDIGlobalLocationNumberDelivery',
10
12
  edi_invoice_extra1: 'EDIInvoiceExtra1',
@@ -16,6 +18,6 @@ describe Fortnox::API::Mapper::EDIInformation do
16
18
  json_entity_collection = 'EDIInformation'
17
19
 
18
20
  it_behaves_like 'mapper', key_map, json_entity_type, json_entity_collection do
19
- let(:mapper){ described_class.new }
21
+ let(:mapper) { described_class.new }
20
22
  end
21
23
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api'
3
5
  require 'fortnox/api/mappers/email_information'
4
6
  require 'fortnox/api/mappers/examples/mapper'
5
7
 
6
8
  describe Fortnox::API::Mapper::EmailInformation do
7
- key_map = {
9
+ key_map = {
8
10
  email_address_bcc: 'EmailAddressBCC',
9
11
  email_address_cc: 'EmailAddressCC'
10
12
  }
@@ -12,6 +14,6 @@ describe Fortnox::API::Mapper::EmailInformation do
12
14
  json_entity_collection = 'EmailInformation'
13
15
 
14
16
  it_behaves_like 'mapper', key_map, json_entity_type, json_entity_collection do
15
- let(:mapper){ described_class.new }
17
+ let(:mapper) { described_class.new }
16
18
  end
17
19
  end
@@ -1,25 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Metrics/LineLength
1
4
  shared_examples_for 'mapper' do |key_map, json_entity_wrapper = nil, json_collection_wrapper = nil, check_constants: true|
2
- it{ is_expected.to respond_to(:wrapped_json_collection_to_entities_hash) }
3
- it{ is_expected.to respond_to(:wrapped_json_hash_to_entity_hash) }
4
- it{ is_expected.to respond_to(:entity_to_hash) }
5
+ # rubocop:enable Metrics/LineLength
6
+
7
+ it { is_expected.to respond_to(:wrapped_json_collection_to_entities_hash) }
8
+ it { is_expected.to respond_to(:wrapped_json_hash_to_entity_hash) }
9
+ it { is_expected.to respond_to(:entity_to_hash) }
5
10
 
6
11
  if check_constants
7
12
  describe 'key_map' do
8
- subject{ described_class::KEY_MAP }
9
- it{ is_expected.to eq(key_map) }
13
+ subject { described_class::KEY_MAP }
14
+
15
+ it { is_expected.to eq(key_map) }
10
16
  end
11
17
 
12
18
  unless json_entity_wrapper.nil?
13
19
  describe 'json_entity_wrapper' do
14
- subject{ described_class::JSON_ENTITY_WRAPPER }
15
- it{ is_expected.to eq(json_entity_wrapper) }
20
+ subject { described_class::JSON_ENTITY_WRAPPER }
21
+
22
+ it { is_expected.to eq(json_entity_wrapper) }
16
23
  end
17
24
  end
18
25
 
19
26
  unless json_collection_wrapper.nil?
20
27
  describe 'json_collection_wrapper' do
21
- subject{ described_class::JSON_COLLECTION_WRAPPER }
22
- it{ is_expected.to eq(json_collection_wrapper) }
28
+ subject { described_class::JSON_COLLECTION_WRAPPER }
29
+
30
+ it { is_expected.to eq(json_collection_wrapper) }
23
31
  end
24
32
  end
25
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api'
3
5
  require 'fortnox/api/mappers/invoice_row'
@@ -5,15 +7,18 @@ require 'fortnox/api/mappers/examples/mapper'
5
7
 
6
8
  describe Fortnox::API::Mapper::InvoiceRow do
7
9
  key_map = {
8
- vat: 'VAT',
10
+ housework: 'HouseWork',
11
+ housework_hours_to_report: 'HouseWorkHoursToReport',
12
+ housework_type: 'HouseWorkType',
9
13
  price_excluding_vat: 'PriceExcludingVAT',
10
- total_excluding_vat: 'TotalExcludingVAT'
14
+ total_excluding_vat: 'TotalExcludingVAT',
15
+ vat: 'VAT'
11
16
  }
12
17
 
13
18
  json_entity_type = 'InvoiceRow'
14
19
  json_entity_collection = 'InvoiceRows'
15
20
 
16
21
  it_behaves_like 'mapper', key_map, json_entity_type, json_entity_collection do
17
- let(:mapper){ described_class.new }
22
+ let(:mapper) { described_class.new }
18
23
  end
19
24
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api'
3
5
  require 'fortnox/api/mappers/invoice'
@@ -10,6 +12,7 @@ describe Fortnox::API::Mapper::Invoice do
10
12
  edi_information: 'EDIInformation',
11
13
  eu_quarterly_report: 'EUQuarterlyReport',
12
14
  freight_vat: 'FreightVAT',
15
+ housework: 'HouseWork',
13
16
  ocr: 'OCR',
14
17
  total_vat: 'TotalVAT',
15
18
  vat_included: 'VATIncluded'
@@ -19,6 +22,6 @@ describe Fortnox::API::Mapper::Invoice do
19
22
  json_entity_collection = 'Invoices'
20
23
 
21
24
  it_behaves_like 'mapper', key_map, json_entity_type, json_entity_collection do
22
- let(:mapper){ described_class.new }
25
+ let(:mapper) { described_class.new }
23
26
  end
24
27
  end
@@ -1,14 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api'
3
5
  require 'fortnox/api/mappers/order_row'
4
6
  require 'fortnox/api/mappers/examples/mapper'
5
7
 
6
8
  describe Fortnox::API::Mapper::OrderRow do
7
- key_map = { vat: 'VAT' }
9
+ key_map = {
10
+ housework: 'HouseWork',
11
+ housework_hours_to_report: 'HouseWorkHoursToReport',
12
+ housework_type: 'HouseWorkType',
13
+ vat: 'VAT'
14
+ }
8
15
  json_entity_type = 'OrderRow'
9
16
  json_entity_collection = 'OrderRows'
10
17
 
11
18
  it_behaves_like 'mapper', key_map, json_entity_type, json_entity_collection do
12
- let(:mapper){ described_class.new }
19
+ let(:mapper) { described_class.new }
13
20
  end
14
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api'
3
5
  require 'fortnox/api/mappers/order'
@@ -8,6 +10,7 @@ describe Fortnox::API::Mapper::Order do
8
10
  {
9
11
  administration_fee_vat: 'AdministrationFeeVAT',
10
12
  freight_vat: 'FreightVAT',
13
+ housework: 'HouseWork',
11
14
  total_vat: 'TotalVAT',
12
15
  vat_included: 'VATIncluded'
13
16
  }
@@ -15,6 +18,6 @@ describe Fortnox::API::Mapper::Order do
15
18
  json_entity_collection = 'Orders'
16
19
 
17
20
  it_behaves_like 'mapper', key_map, json_entity_type, json_entity_collection do
18
- let(:mapper){ described_class.new }
21
+ let(:mapper) { described_class.new }
19
22
  end
20
23
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api'
3
5
  require 'fortnox/api/mappers/project'
@@ -5,6 +7,6 @@ require 'fortnox/api/mappers/examples/mapper'
5
7
 
6
8
  describe Fortnox::API::Mapper::Project do
7
9
  it_behaves_like 'mapper', {}, 'Project', 'Projects' do
8
- let(:mapper){ described_class.new }
10
+ let(:mapper) { described_class.new }
9
11
  end
10
12
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'fortnox/api'
5
+ require 'fortnox/api/mappers/terms_of_payments'
6
+ require 'fortnox/api/mappers/examples/mapper'
7
+
8
+ describe Fortnox::API::Mapper::TermsOfPayments do
9
+ key_map = {}
10
+ json_entity_type = 'TermsOfPayment'
11
+ json_entity_collection = 'TermsOfPayments'
12
+
13
+ it_behaves_like 'mapper', key_map, json_entity_type, json_entity_collection do
14
+ let(:mapper) { described_class.new }
15
+ end
16
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'fortnox/api'
5
+ require 'fortnox/api/mappers/unit'
6
+ require 'fortnox/api/models/unit'
7
+ require 'fortnox/api/mappers/examples/mapper'
8
+
9
+ module Fortnox
10
+ module API
11
+ # Shhh Rubocop, we don't need a comment here ... Really
12
+ module Mapper
13
+ describe Unit do
14
+ context 'when mapping model' do
15
+ let(:model) { Model::Unit.new(code: 'lbs', description: 'Pounds') }
16
+ let(:serialised_model_hash) { { 'Unit' => { 'Code' => 'lbs', 'Description' => 'Pounds' } } }
17
+ let(:model_hash) { { code: 'lbs', description: 'Pounds' } }
18
+
19
+ describe '#entity_to_hash' do
20
+ subject { Unit.new.entity_to_hash(model, {}) }
21
+
22
+ it { is_expected.to eq(serialised_model_hash) }
23
+ end
24
+
25
+ describe '#wrapped_json_hash_to_entity_hash' do
26
+ subject { Unit.new.wrapped_json_hash_to_entity_hash(serialised_model_hash) }
27
+
28
+ it { is_expected.to eq(model_hash) }
29
+ end
30
+ end
31
+
32
+ context 'when mapping collection' do
33
+ let(:serialised_collection_hash) do
34
+ { 'Units' => [
35
+ { 'Unit' => { 'Code' => 'lbs', 'Description' => 'Pounds' } },
36
+ { 'Unit' => { 'Code' => 'ohm', 'Description' => 'Ω' } },
37
+ { 'Unit' => { 'Code' => 'A/V', 'Description' => 'Ampere volt' } }
38
+ ] }
39
+ end
40
+ let(:collection_hash) do
41
+ [
42
+ { unit: { code: 'lbs', description: 'Pounds' } },
43
+ { unit: { code: 'ohm', description: 'Ω' } },
44
+ { unit: { code: 'A/V', description: 'Ampere volt' } }
45
+ ]
46
+ end
47
+
48
+ describe '#wrapped_json_collection_to_entities_hash' do
49
+ subject { Unit.new.wrapped_json_collection_to_entities_hash(serialised_collection_hash) }
50
+
51
+ it { is_expected.to eq(collection_hash) }
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api/models/article'
3
5
  require 'fortnox/api/models/examples/model'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api/models/base'
3
5
  require 'fortnox/api/types'
@@ -5,7 +7,7 @@ require 'fortnox/api/types'
5
7
  describe Fortnox::API::Model::Base do
6
8
  using_test_classes do
7
9
  class Entity < Fortnox::API::Model::Base
8
- attribute :private, Fortnox::API::Types::String.with( read_only: true )
10
+ attribute :private, Fortnox::API::Types::String.is(:read_only)
9
11
  attribute :string, Fortnox::API::Types::Required::String
10
12
  attribute :number, Fortnox::API::Types::Nullable::Integer
11
13
  attribute :account, Fortnox::API::Types::AccountNumber
@@ -14,85 +16,91 @@ describe Fortnox::API::Model::Base do
14
16
 
15
17
  describe '.new' do
16
18
  context 'with basic attribute' do
17
- subject{ Entity.new( string: 'Test' ) }
19
+ subject { Entity.new(string: 'Test') }
18
20
 
19
- it{ is_expected.to be_a Entity }
20
- it{ is_expected.to be_new }
21
- it{ is_expected.not_to be_saved }
21
+ it { is_expected.to be_a Entity }
22
+ it { is_expected.to be_new }
23
+ it { is_expected.not_to be_saved }
22
24
  end
23
25
 
24
26
  context 'without required attribute' do
25
- subject{ ->{ Entity.new({}) } }
27
+ subject { -> { Entity.new({}) } }
26
28
 
27
- it{ is_expected.to raise_error Fortnox::API::Exception }
28
- it{ is_expected.to raise_error Fortnox::API::MissingAttributeError }
29
- it{ is_expected.to raise_error Fortnox::API::MissingAttributeError, /Missing attribute :string/ }
29
+ it { is_expected.to raise_error Fortnox::API::Exception }
30
+ it { is_expected.to raise_error Fortnox::API::MissingAttributeError }
31
+ it { is_expected.to raise_error Fortnox::API::MissingAttributeError, /Missing attribute :string/ }
30
32
  end
31
33
 
32
34
  context 'with invalid attribute value' do
33
- subject{ ->{ Entity.new({ string: 'Test', account: 13337 }) } }
35
+ subject { -> { Entity.new(string: 'Test', account: 13_337) } }
34
36
 
35
- it{ is_expected.to raise_error Fortnox::API::Exception }
36
- it{ is_expected.to raise_error Fortnox::API::AttributeError }
37
- it{ is_expected.to raise_error Fortnox::API::AttributeError, /invalid type for :account/ }
37
+ it { is_expected.to raise_error Fortnox::API::Exception }
38
+ it { is_expected.to raise_error Fortnox::API::AttributeError }
39
+ it { is_expected.to raise_error Fortnox::API::AttributeError, /invalid type for :account/ }
38
40
  end
39
41
  end
40
42
 
41
43
  describe '.update' do
42
- let(:original){ Entity.new( string: 'Test' ) }
44
+ let(:original) { Entity.new(string: 'Test') }
43
45
 
44
46
  context 'with new, simple value' do
45
- subject{ updated_model }
47
+ subject { updated_model }
46
48
 
47
- let(:updated_model){ original.update( string: 'Variant' ) }
49
+ let(:updated_model) { original.update(string: 'Variant') }
48
50
 
49
- it{ is_expected.to be_new }
50
- it{ is_expected.not_to be_saved }
51
+ it { is_expected.to be_new }
52
+ it { is_expected.not_to be_saved }
51
53
 
52
54
  it 'returns a new object' do
53
- is_expected.not_to eql( original )
55
+ is_expected.not_to eql(original)
54
56
  end
55
57
 
56
58
  describe 'updated attribute' do
57
- subject{ updated_model.string }
58
- it{ is_expected.to eql( 'Variant' ) }
59
+ subject { updated_model.string }
60
+
61
+ it { is_expected.to eql('Variant') }
59
62
  end
60
63
 
61
64
  describe 'returned class' do
62
- subject{ updated_model.class }
63
- it{ is_expected.to eql( original.class ) }
65
+ subject { updated_model.class }
66
+
67
+ it { is_expected.to eql(original.class) }
64
68
  end
65
69
  end
66
70
 
67
71
  context 'with the same, simple value' do
68
- subject( :updated_model ){ original.update( string: 'Test' ) }
72
+ subject(:updated_model) { original.update(string: 'Test') }
69
73
 
70
74
  it 'returns the same object' do
71
- is_expected.to eql( original )
75
+ is_expected.to eql(original)
72
76
  end
73
77
 
74
78
  it 'returns a object with the same value' do
75
- expect( updated_model.string ).to eql( 'Test' )
79
+ expect(updated_model.string).to eql('Test')
76
80
  end
77
81
 
78
- it{ is_expected.to be_new }
79
- it{ is_expected.not_to be_saved }
82
+ it { is_expected.to be_new }
83
+ it { is_expected.not_to be_saved }
80
84
  end
81
85
 
82
- context 'a saved entity' do
83
- subject( :updated_entry ){ saved_entry.update( string: 'Updated' ) }
86
+ context 'when updating' do
87
+ let(:updated_entity) do
88
+ saved_entity = Entity.new(string: 'Saved', new: false, unsaved: false)
89
+ saved_entity.update(string: 'Updated')
90
+ end
84
91
 
85
- let( :saved_entry ){ Entity.new( string: 'Saved', new: false, unsaved: false) }
92
+ describe 'updated entity' do
93
+ subject { updated_entity }
86
94
 
87
- before do
88
- expect(saved_entry).not_to be_new
89
- expect(saved_entry).to be_saved
95
+ it { is_expected.not_to be_saved }
96
+ it { is_expected.not_to be_new }
90
97
  end
91
98
 
92
- specify{ expect(updated_entry.string).to eq( 'Updated' ) }
93
- it{ is_expected.not_to be_new }
94
- it{ is_expected.not_to be_saved }
99
+ describe 'updated attribute value' do
100
+ subject { updated_entity.string }
101
+
102
+ it { is_expected.to eq('Updated') }
103
+ end
95
104
  end
96
105
  end
97
-
98
106
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api/models/customer'
3
5
  require 'fortnox/api/models/examples/model'
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fortnox/api/models/examples/model'
2
4
 
3
5
  shared_examples_for 'DocumentBase Model' do |row_class, row_attribute, valid_row_hash: {}|
4
6
  it_behaves_like 'a model', 1
5
7
 
6
- context "when having a(n) #{ row_class }" do
8
+ context "when having a(n) #{row_class}" do
7
9
  it 'returns the correct object' do
8
10
  row = row_class.new(valid_row_hash)
9
- document_base = described_class.new( customer_number: '123', row_attribute => [row] )
10
- expect(document_base.send(row_attribute)).to eq([row])
11
+ document = described_class.new(customer_number: '123', row_attribute => [row])
12
+ expect(document.send(row_attribute)).to eq([row])
11
13
  end
12
14
  end
13
15
  end