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,13 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fortnox
2
4
  module API
3
5
  module Types
4
-
5
6
  module Required
6
- String = Types::Strict::String.constructor{ |value| value.to_s unless value.nil? }.with( required: true )
7
- Integer = Types::Strict::Int.constructor{ |value| value.to_i unless value.nil? }.with( required: true )
8
- Float = Types::Strict::Float.constructor{ |value| value.to_f unless value.nil? }.with( required: true )
7
+ String = Types::Strict::String.constructor { |value| value.to_s unless value.nil? }.is(:required)
8
+ Integer = Types::Strict::Int.constructor { |value| value.to_i unless value.nil? }.is(:required)
9
+ Float = Types::Strict::Float.constructor { |value| value.to_f unless value.nil? }.is(:required)
9
10
  end
10
-
11
11
  end
12
12
  end
13
13
  end
@@ -1,22 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fortnox
2
4
  module API
3
5
  module Types
4
6
  module Sized
5
7
  module String
6
- def self.[]( size )
7
- Types::Strict::String.constrained( max_size: size ).optional.constructor{ |value| value.to_s unless value.nil? }
8
+ def self.[](size)
9
+ Types::Strict::String.constrained(max_size: size).optional.constructor do |value|
10
+ value.to_s unless value.nil?
11
+ end
8
12
  end
9
13
  end
10
14
 
11
15
  module Integer
12
- def self.[]( low, high )
13
- Types::Strict::Int.constrained( gteq: low, lteq: high ).optional.constructor{ |value| value.to_i unless value.nil? }
16
+ def self.[](low, high)
17
+ Types::Strict::Int.constrained(gteq: low, lteq: high).optional.constructor do |value|
18
+ value.to_i unless value.nil?
19
+ end
14
20
  end
15
21
  end
16
22
 
17
23
  module Float
18
- def self.[]( low, high )
19
- Types::Strict::Float.constrained( gteq: low, lteq: high ).optional.constructor{ |value| value.to_f unless value.nil? }
24
+ def self.[](low, high)
25
+ Types::Strict::Float.constrained(gteq: low, lteq: high).optional.constructor do |value|
26
+ value.to_f unless value.nil?
27
+ end
20
28
  end
21
29
  end
22
30
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fortnox
2
4
  module API
3
- VERSION = "0.5.2".freeze
5
+ VERSION = '0.6.0'
4
6
  end
5
7
  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/customer'
@@ -10,6 +12,6 @@ describe Fortnox::API::Mapper::Article do
10
12
  json_entity_collection = 'Articles'
11
13
 
12
14
  it_behaves_like 'mapper', key_map, json_entity_type, json_entity_collection do
13
- let(:mapper){ described_class.new }
15
+ let(:mapper) { described_class.new }
14
16
  end
15
17
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api/mappers/base/from_json'
3
5
  require 'fortnox/api/mappers/contexts/json_conversion'
4
6
 
5
7
  describe Fortnox::API::Mapper::FromJSON do
6
- include_context 'JSON conversion'
8
+ include_context 'with JSON conversion'
7
9
 
8
10
  before do
9
11
  module Test
@@ -12,20 +14,20 @@ describe Fortnox::API::Mapper::FromJSON do
12
14
  end
13
15
  end
14
16
 
15
- register_mapper( :categories, Test::CategoryMapper )
16
- register_mapper( :designer, Test::ProductDesignerMapper )
17
+ register_mapper(:categories, Test::CategoryMapper)
18
+ register_mapper(:designer, Test::ProductDesignerMapper)
17
19
  end
18
20
 
19
- let( :mapper ){ Test::ProductMapper.new }
21
+ let(:mapper) { Test::ProductMapper.new }
20
22
 
21
23
  describe 'wrapped_json_hash_to_entity_hash' do
22
- let( :entity_hash ){ mapper.wrapped_json_hash_to_entity_hash( wrapped_json_hash ) }
23
- let( :wrapped_json_hash ) do
24
+ let(:entity_hash) { mapper.wrapped_json_hash_to_entity_hash(wrapped_json_hash) }
25
+ let(:wrapped_json_hash) do
24
26
  {
25
27
  'Product' => {
26
28
  '@url': 'someurl@example.com',
27
29
  'Name': 'Ford Mustang',
28
- 'VAT': 30000,
30
+ 'VAT': 30_000,
29
31
  'Categories': [{ 'Name' => 'Cars', 'ID' => '1' }, { 'Name' => 'Fast cars', 'ID' => '2' }],
30
32
  'Designer': { 'Name' => 'John Najjar', 'ID' => '23' }
31
33
  }
@@ -33,11 +35,11 @@ describe Fortnox::API::Mapper::FromJSON do
33
35
  end
34
36
 
35
37
  specify 'converts keys without mapping correctly' do
36
- expect( entity_hash[:name] ).to eq 'Ford Mustang'
38
+ expect(entity_hash[:name]).to eq 'Ford Mustang'
37
39
  end
38
40
 
39
41
  specify 'converts keys with mapping correctly' do
40
- expect( entity_hash[:vat] ).to eq 30000
42
+ expect(entity_hash[:vat]).to eq 30_000
41
43
  end
42
44
 
43
45
  specify 'converts keys starting with "@" correctly'
@@ -46,20 +48,20 @@ describe Fortnox::API::Mapper::FromJSON do
46
48
  # end
47
49
 
48
50
  context 'with nested models' do
49
- let( :expected_nested_model_hash ) do
51
+ let(:expected_nested_model_hash) do
50
52
  [{ name: 'Cars', id: '1' }, { name: 'Fast cars', id: '2' }]
51
53
  end
52
54
 
53
55
  specify 'are converted correctly' do
54
- expect( entity_hash[:categories] ).to eq( expected_nested_model_hash )
56
+ expect(entity_hash[:categories]).to eq(expected_nested_model_hash)
55
57
  end
56
58
  end
57
59
 
58
60
  context 'with nested model' do
59
- let( :expected_nested_model_hash ){ { name: 'John Najjar', id: '23' } }
61
+ let(:expected_nested_model_hash) { { name: 'John Najjar', id: '23' } }
60
62
 
61
63
  specify 'is converted correctly' do
62
- expect( entity_hash[:designer] ).to eq( expected_nested_model_hash )
64
+ expect(entity_hash[:designer]).to eq(expected_nested_model_hash)
63
65
  end
64
66
  end
65
67
  end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api/mappers/base/to_json'
3
5
  require 'fortnox/api/mappers/contexts/json_conversion'
4
6
 
5
7
  describe Fortnox::API::Mapper::ToJSON do
6
- # TODO:
7
- # Following error is risen sometimes when all specs are run:
8
+ # TODO: Following error is risen sometimes when all specs are run:
8
9
  # "NoMethodError: undefined method `call\' for Test::ProductMapper:Class`"
9
10
  it 'should be tested when random error is fixed!'
10
11
 
@@ -12,7 +13,7 @@ describe Fortnox::API::Mapper::ToJSON do
12
13
  it 'should be tested'
13
14
  end
14
15
 
15
- # include_context 'JSON conversion'
16
+ # include_context 'with JSON conversion'
16
17
 
17
18
  # before do
18
19
  # module Test
@@ -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'
@@ -8,73 +10,75 @@ describe Fortnox::API::Mapper::Base do
8
10
  it_behaves_like 'mapper', nil, nil, nil, check_constants: false
9
11
 
10
12
  shared_examples_for 'simple mapper' do |registry_key, exp_value|
11
- subject{ mapper.call( value ) }
12
- let( :mapper ){ Fortnox::API::Registry[ registry_key ] }
13
- it{ is_expected.to eq( exp_value ) }
13
+ subject { mapper.call(value) }
14
+
15
+ let(:mapper) { Fortnox::API::Registry[registry_key] }
16
+ it { is_expected.to eq(exp_value) }
14
17
  end
15
18
 
16
19
  shared_examples_for 'identity mapper' do |registry_key|
17
- subject{ mapper.call( value ) }
18
- let( :mapper ){ Fortnox::API::Registry[ registry_key ] }
19
- it{ is_expected.to eq( value ) }
20
+ subject { mapper.call(value) }
21
+
22
+ let(:mapper) { Fortnox::API::Registry[registry_key] }
23
+ it { is_expected.to eq(value) }
20
24
  end
21
25
 
22
26
  describe 'string' do
23
27
  include_examples 'identity mapper', :string do
24
- let( :value ){ Fortnox::API::Types::Nullable::String[ 'test' ] }
28
+ let(:value) { Fortnox::API::Types::Nullable::String['test'] }
25
29
  end
26
30
  end
27
31
 
28
32
  describe 'int' do
29
33
  include_examples 'identity mapper', :int do
30
- let( :value ){ Fortnox::API::Types::Nullable::Integer[ 1337 ] }
34
+ let(:value) { Fortnox::API::Types::Nullable::Integer[1337] }
31
35
  end
32
36
  end
33
37
 
34
38
  describe 'float' do
35
39
  include_examples 'identity mapper', :float do
36
- let( :value ){ Fortnox::API::Types::Nullable::Float[ 13.37 ] }
40
+ let(:value) { Fortnox::API::Types::Nullable::Float[13.37] }
37
41
  end
38
42
  end
39
43
 
40
44
  describe 'boolean' do
41
45
  include_examples 'identity mapper', :boolean do
42
- let( :value ){ Fortnox::API::Types::Nullable::Boolean[ false ] }
46
+ let(:value) { Fortnox::API::Types::Nullable::Boolean[false] }
43
47
  end
44
48
  end
45
49
 
46
50
  describe 'array' do
47
51
  include_examples 'identity mapper', :array do
48
- let( :value ){ [1,3,3,7] }
52
+ let(:value) { [1, 3, 3, 7] }
49
53
  end
50
54
  end
51
55
 
52
56
  describe 'array with very large int (Bigint if Ruby <2.4)' do
53
57
  include_examples 'identity mapper', :array do
54
- let( :value ){ [(100**10)] }
58
+ let(:value) { [(100**10)] }
55
59
  end
56
60
  end
57
61
 
58
62
  describe 'advanced array' do
59
- include_examples 'simple mapper', :array, [ "2016-01-01", "2016-01-02" ] do
60
- let( :value ){ [ Date.new(2016, 1, 1), Date.new(2016, 1, 2) ] }
63
+ include_examples 'simple mapper', :array, ['2016-01-01', '2016-01-02'] do
64
+ let(:value) { [Date.new(2016, 1, 1), Date.new(2016, 1, 2)] }
61
65
  end
62
66
  end
63
67
 
64
68
  describe 'hash' do
65
69
  include_examples 'identity mapper', :hash do
66
- let( :value ){ { string: 'test', int: 1337, float: 13.37 } }
70
+ let(:value) { { string: 'test', int: 1337, float: 13.37 } }
67
71
  end
68
72
  end
69
73
 
70
74
  describe 'advanced hash' do
71
75
  expected_hash = {
72
76
  string: 'test',
73
- date_array: [ "2016-01-01", "2016-01-02"],
74
- nested_hash: { date: "2016-01-03", string: 'test' }
77
+ date_array: ['2016-01-01', '2016-01-02'],
78
+ nested_hash: { date: '2016-01-03', string: 'test' }
75
79
  }
76
80
  include_examples 'identity mapper', :hash, expected_hash do
77
- let( :value ) do
81
+ let(:value) do
78
82
  {
79
83
  string: 'test',
80
84
  date_array: [Date.new(2016, 1, 1), Date.new(2016, 1, 2)],
@@ -86,77 +90,78 @@ describe Fortnox::API::Mapper::Base do
86
90
 
87
91
  describe 'trueclass' do
88
92
  include_examples 'identity mapper', :trueclass do
89
- let( :value ){ true }
93
+ let(:value) { true }
90
94
  end
91
95
  end
92
96
  describe 'falseclass' do
93
97
  include_examples 'identity mapper', :falseclass do
94
- let( :value ){ false }
98
+ let(:value) { false }
95
99
  end
96
100
  end
97
101
 
98
102
  describe 'date' do
99
- include_examples 'simple mapper', :date, "2016-01-01" do
100
- let( :value ){ Date.new(2016, 1, 1) }
103
+ include_examples 'simple mapper', :date, '2016-01-01' do
104
+ let(:value) { Date.new(2016, 1, 1) }
101
105
  end
102
106
  end
103
107
 
104
108
  describe 'nilclass' do
105
109
  include_examples 'identity mapper', :nilclass do
106
- let( :value ){ Fortnox::API::Types::Nullable::String[ nil ] }
110
+ let(:value) { Fortnox::API::Types::Nullable::String[nil] }
107
111
  end
108
112
  end
109
113
 
110
114
  describe 'AccountNumber' do
111
115
  include_examples 'identity mapper', :account_number do
112
- let( :value ){ Fortnox::API::Types::AccountNumber[ 1234 ] }
116
+ let(:value) { Fortnox::API::Types::AccountNumber[1234] }
113
117
  end
114
118
  end
115
119
 
116
120
  describe 'CountryCode' do
117
121
  include_examples 'identity mapper', :country_code do
118
- let( :value ){ Fortnox::API::Types::CountryCode[ 'SE' ] }
122
+ let(:value) { Fortnox::API::Types::CountryCode['SE'] }
119
123
  end
120
124
  end
121
125
 
122
126
  describe 'Currency' do
123
127
  include_examples 'identity mapper', :currency do
124
- let( :value ){ Fortnox::API::Types::Currency[ 'SEK' ] }
128
+ let(:value) { Fortnox::API::Types::Currency['SEK'] }
125
129
  end
126
130
  end
127
131
 
128
132
  describe 'CustomerType' do
129
133
  include_examples 'identity mapper', :customer_type do
130
- let( :value ){ Fortnox::API::Types::CustomerType[ 'PRIVATE' ] }
134
+ let(:value) { Fortnox::API::Types::CustomerType['PRIVATE'] }
131
135
  end
132
136
  end
133
137
 
134
138
  describe 'DiscountType' do
135
139
  include_examples 'identity mapper', :discount_type do
136
- let( :value ){ Fortnox::API::Types::DiscountType[ 'PERCENT' ] }
140
+ let(:value) { Fortnox::API::Types::DiscountType['PERCENT'] }
137
141
  end
138
142
  end
139
143
 
140
144
  describe 'Email' do
141
145
  include_examples 'identity mapper', :email do
142
- let( :value ){ Fortnox::API::Types::Email[ 'email@example.com' ] }
146
+ let(:value) { Fortnox::API::Types::Email['email@example.com'] }
143
147
  end
144
148
  end
145
149
 
146
- describe 'HouseWorkType' do
147
- include_examples 'identity mapper', :house_work_type do
148
- let( :value ){ Fortnox::API::Types::HouseWorkType[ 'CONSTRUCTION' ] }
150
+ describe 'HouseworkType' do
151
+ include_examples 'identity mapper', :housework_type do
152
+ let(:value) { Fortnox::API::Types::HouseworkType['CONSTRUCTION'] }
149
153
  end
150
154
  end
151
155
 
152
156
  describe 'VATType' do
153
157
  include_examples 'identity mapper', :vat_type do
154
- let( :value ){ Fortnox::API::Types::VATType[ 'SEVAT' ] }
158
+ let(:value) { Fortnox::API::Types::VATType['SEVAT'] }
155
159
  end
156
160
  end
157
161
 
158
162
  describe '#canonical_name_sym' do
159
- subject{ described_class.canonical_name_sym }
160
- it{ is_expected.to eq( described_class.name.split( '::' ).last.downcase.to_sym ) }
163
+ subject { described_class.canonical_name_sym }
164
+
165
+ it { is_expected.to eq(described_class.name.split('::').last.downcase.to_sym) }
161
166
  end
162
167
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fortnox/api'
2
4
  require 'fortnox/api/mappers'
3
5
 
4
- shared_context 'JSON conversion' do
6
+ shared_context 'with JSON conversion' do
5
7
  before do
6
8
  module Test
7
9
  class BaseMapper
@@ -20,8 +22,8 @@ shared_context 'JSON conversion' do
20
22
  vat: 'VAT',
21
23
  url: '@url' # TODO: How to handle url attribute?
22
24
  }.freeze
23
- JSON_ENTITY_WRAPPER = 'Product'.freeze
24
- JSON_COLLECTION_WRAPPER = 'Products'.freeze
25
+ JSON_ENTITY_WRAPPER = 'Product'
26
+ JSON_COLLECTION_WRAPPER = 'Products'
25
27
  end
26
28
 
27
29
  class Category < Fortnox::API::Model::Base
@@ -38,19 +40,18 @@ shared_context 'JSON conversion' do
38
40
  attribute :url, 'strict.string'
39
41
  attribute :name, 'strict.string'
40
42
  attribute :vat, 'strict.float'
41
- attribute :categories, Dry::Types['coercible.array'].member( Test::Category )
43
+ attribute :categories, Dry::Types['coercible.array'].member(Test::Category)
42
44
  attribute :designer, Test::ProductDesigner
43
45
  end
44
46
  end
45
47
 
46
- def register_mapper( mapper_sym, mapper )
47
- unless Fortnox::API::Registry.key? mapper_sym
48
- Fortnox::API::Registry.register( mapper_sym, mapper )
49
- end
48
+ def register_mapper(mapper_sym, mapper)
49
+ return if Fortnox::API::Registry.key? mapper_sym
50
+ Fortnox::API::Registry.register(mapper_sym, mapper)
50
51
  end
51
52
 
52
- register_mapper( :category, Test::CategoryMapper)
53
- register_mapper( :productdesigner, Test::ProductDesignerMapper )
54
- register_mapper( :product, Test::ProductMapper )
53
+ register_mapper(:category, Test::CategoryMapper)
54
+ register_mapper(:productdesigner, Test::ProductDesignerMapper)
55
+ register_mapper(:product, Test::ProductMapper)
55
56
  end
56
57
  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/customer'
@@ -20,6 +22,6 @@ describe Fortnox::API::Mapper::Customer do
20
22
  json_entity_collection = 'Customers'
21
23
 
22
24
  it_behaves_like 'mapper', key_map, json_entity_type, json_entity_collection do
23
- let(:mapper){ described_class.new }
25
+ let(:mapper) { described_class.new }
24
26
  end
25
27
  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/default_delivery_types'
@@ -7,6 +9,6 @@ describe Fortnox::API::Mapper::DefaultDeliveryTypes do
7
9
  key_map = {}
8
10
 
9
11
  it_behaves_like 'mapper', key_map do
10
- let(:mapper){ described_class.new }
12
+ let(:mapper) { described_class.new }
11
13
  end
12
14
  end