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,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_examples_for 'equals input' do |input|
2
- subject{ klass[ input ] }
3
- it{ is_expected.to eq input }
4
+ subject { klass[input] }
5
+
6
+ it { is_expected.to eq input }
4
7
  end
5
8
 
6
9
  shared_examples_for 'raises ConstraintError' do |input|
7
- subject{ ->{ klass[ input ] } }
8
- it{ is_expected.to raise_error(Dry::Types::ConstraintError) }
10
+ subject { -> { klass[input] } }
11
+
12
+ it { is_expected.to raise_error(Dry::Types::ConstraintError) }
9
13
  end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'fortnox/api'
5
+ require 'fortnox/api/types'
6
+ require 'fortnox/api/repositories/order'
7
+ require 'fortnox/api/models/order'
8
+ require 'fortnox/api/types/order_row'
9
+
10
+ # rubocop:disable RSpec/DescribeClass
11
+ describe 'HouseworkTypes', integration: true do
12
+ include Helpers::Configuration
13
+
14
+ before { set_api_test_configuration }
15
+
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
+
26
+ shared_examples_for 'housework type' do |type, legacy: false|
27
+ subject do
28
+ lambda do
29
+ VCR.use_cassette("orders/housework_type_#{type.downcase}") do
30
+ repository.save(valid_model)
31
+ end
32
+ end
33
+ end
34
+
35
+ let(:error_message) { 'Skattereduktion för den valda typen av husarbete har upphört.' }
36
+ let(:housework_type) { Fortnox::API::Types::HouseworkTypes[type] }
37
+
38
+ context "when creating an OrderRow with housework_type set to #{type}" do
39
+ if legacy
40
+ it 'raises an error' do
41
+ is_expected.to raise_error(Fortnox::API::RemoteServerError, error_message)
42
+ end
43
+ else
44
+ it { is_expected.not_to raise_error }
45
+ end
46
+ end
47
+ end
48
+
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
67
+ end
68
+ # rubocop:enable RSpec/DescribeClass
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api/types/invoice_row'
3
5
  require 'fortnox/api/types/examples/document_row'
4
6
 
5
7
  RSpec.describe Fortnox::API::Types::InvoiceRow, type: :type do
6
- subject{ described_class }
8
+ subject { described_class }
7
9
 
8
10
  it_behaves_like 'DocumentRow', {}
9
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'dry-struct'
3
5
  require 'fortnox/api/types/model'
@@ -8,7 +10,7 @@ RSpec.describe Fortnox::API::Types::Model do
8
10
  module Types
9
11
  include Dry::Types.module
10
12
 
11
- Age = Int.constrained(gt: 18).with(required: true)
13
+ Age = Int.constrained(gt: 18).is(:required)
12
14
  end
13
15
 
14
16
  class TypesModelUser < Fortnox::API::Types::Model
@@ -16,16 +18,16 @@ RSpec.describe Fortnox::API::Types::Model do
16
18
  end
17
19
  end
18
20
 
19
- describe "User inheriting from #{ described_class }" do
20
- subject{ ->{ TypesModelUser.new(args) } }
21
+ describe "User inheriting from #{described_class}" do
22
+ subject { -> { TypesModelUser.new(args) } }
21
23
 
22
- it{ is_expected.to raise_error(error) }
24
+ it { is_expected.to raise_error(error) }
23
25
  end
24
26
  end
25
27
 
26
28
  context 'without required keys' do
27
29
  include_examples 'raises error', Fortnox::API::MissingAttributeError do
28
- let(:args){ {} }
30
+ let(:args) { {} }
29
31
  end
30
32
  end
31
33
 
@@ -44,13 +46,14 @@ RSpec.describe Fortnox::API::Types::Model do
44
46
  end
45
47
  end
46
48
 
47
- subject{ ->{ User.new() } }
49
+ subject { -> { User.new } }
48
50
 
49
- it{ is_expected.not_to raise_error }
51
+ it { is_expected.not_to raise_error }
50
52
 
51
53
  describe 'optional attribute' do
52
- subject{ User.new().optional_string }
53
- it{ is_expected.to be nil }
54
+ subject { User.new.optional_string }
55
+
56
+ it { is_expected.to be nil }
54
57
  end
55
58
  end
56
59
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'dry-struct'
3
5
  require 'fortnox/api/types'
4
6
 
5
7
  describe Fortnox::API::Types::Nullable, type: :type do
6
- subject{ TestStruct }
8
+ subject { TestStruct }
7
9
 
8
10
  describe 'String' do
9
11
  using_test_class do
@@ -12,7 +14,7 @@ describe Fortnox::API::Types::Nullable, type: :type do
12
14
  end
13
15
  end
14
16
 
15
- it{ is_expected.to have_nullable(:string, 'A simple message', 0, '0') }
17
+ it { is_expected.to have_nullable(:string, 'A simple message', 0, '0') }
16
18
  end
17
19
 
18
20
  describe 'Float' do
@@ -22,7 +24,7 @@ describe Fortnox::API::Types::Nullable, type: :type do
22
24
  end
23
25
  end
24
26
 
25
- it{ is_expected.to have_nullable(:float, 14.0, 'Not a Float!', 0.0) }
27
+ it { is_expected.to have_nullable(:float, 14.0, 'Not a Float!', 0.0) }
26
28
  end
27
29
 
28
30
  describe 'Integer' do
@@ -32,7 +34,7 @@ describe Fortnox::API::Types::Nullable, type: :type do
32
34
  end
33
35
  end
34
36
 
35
- it{ is_expected.to have_nullable(:integer, 14, 14.0, 14) }
37
+ it { is_expected.to have_nullable(:integer, 14, 14.0, 14) }
36
38
  end
37
39
 
38
40
  describe 'Boolean' do
@@ -42,7 +44,7 @@ describe Fortnox::API::Types::Nullable, type: :type do
42
44
  end
43
45
  end
44
46
 
45
- it{ is_expected.to have_nullable(:boolean, true, 'Not a Boolean!', false) }
47
+ it { is_expected.to have_nullable(:boolean, true, 'Not a Boolean!', false) }
46
48
  end
47
49
 
48
50
  describe 'Date' do
@@ -52,6 +54,6 @@ describe Fortnox::API::Types::Nullable, type: :type do
52
54
  end
53
55
  end
54
56
 
55
- it{ is_expected.to have_nullable_date(:date, Date.new(2016, 1, 1), 'Not a Date!') }
57
+ it { is_expected.to have_nullable_date(:date, Date.new(2016, 1, 1), 'Not a Date!') }
56
58
  end
57
59
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api/types/order_row'
3
5
  require 'fortnox/api/types/examples/document_row'
@@ -5,9 +7,9 @@ require 'fortnox/api/types/examples/document_row'
5
7
  RSpec.describe Fortnox::API::Types::OrderRow, type: :type do
6
8
  valid_hash = { ordered_quantity: 10.5 }
7
9
 
8
- subject{ described_class }
10
+ subject { described_class }
9
11
 
10
- it{ is_expected.to require_attribute( :ordered_quantity, valid_hash ) }
12
+ it { is_expected.to require_attribute(:ordered_quantity, valid_hash) }
11
13
 
12
14
  it_behaves_like 'DocumentRow', valid_hash
13
15
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api/types'
3
5
  require 'fortnox/api/types/required'
@@ -9,10 +11,10 @@ describe Fortnox::API::Types::Required, type: :type do
9
11
  end
10
12
 
11
13
  shared_examples_for 'required attribute' do |_type|
12
- subject{ ->{ TestClass.new({}) } }
14
+ subject { -> { TestClass.new({}) } }
13
15
 
14
16
  let(:error_message) do
15
- "[#{ TestClass }.new] #{ :required_attribute.inspect } is missing in Hash input"
17
+ "[#{TestClass}.new] #{:required_attribute.inspect} is missing in Hash input"
16
18
  end
17
19
 
18
20
  it 'raises an error' do
@@ -1,65 +1,67 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api/types'
3
5
  require 'fortnox/api/types/examples/types'
4
6
 
5
7
  describe Fortnox::API::Types::Sized do
6
-
7
8
  shared_examples_for 'Sized Types' do
8
- context 'created with nil' do
9
- subject{ klass[ nil ] }
10
- it{ is_expected.to be_nil }
9
+ context 'when created with nil' do
10
+ subject { klass[nil] }
11
+
12
+ it { is_expected.to be_nil }
11
13
  end
12
14
  end
13
15
 
14
16
  describe 'String' do
15
17
  max_size = 5
16
- let( :klass ){ described_class::String[ max_size ] }
18
+ let(:klass) { described_class::String[max_size] }
17
19
 
18
20
  it_behaves_like 'Sized Types'
19
21
 
20
- context 'created with empty string' do
22
+ context 'when created with empty string' do
21
23
  include_examples 'equals input', ''
22
24
  end
23
25
 
24
- context 'created with fewer characters than the limit' do
26
+ context 'when created with fewer characters than the limit' do
25
27
  include_examples 'equals input', 'a' * (max_size - 1)
26
28
  end
27
29
 
28
- context 'created with valid string' do
30
+ context 'when created with valid string' do
29
31
  include_examples 'equals input', 'a' * max_size
30
32
  end
31
33
 
32
- context 'created with more characters than the limit' do
34
+ context 'when created with more characters than the limit' do
33
35
  include_examples 'raises ConstraintError', 'a' * (max_size + 1)
34
36
  end
35
37
  end
36
38
 
37
39
  shared_examples_for 'Sized Numeric' do |type, min, max, step|
38
- let( :klass ){ described_class.const_get(type)[ min, max ] }
40
+ let(:klass) { described_class.const_get(type)[min, max] }
39
41
 
40
42
  it_behaves_like 'Sized Types'
41
43
 
42
- context 'created with value below the lower limit' do
44
+ context 'when created with value below the lower limit' do
43
45
  include_examples 'raises ConstraintError', min - step
44
46
  end
45
47
 
46
- context 'created with value at the lower limit' do
48
+ context 'when created with value at the lower limit' do
47
49
  include_examples 'equals input', min
48
50
  end
49
51
 
50
- context 'created with valid number near lower limit' do
52
+ context 'when created with valid number near lower limit' do
51
53
  include_examples 'equals input', min + step
52
54
  end
53
55
 
54
- context 'created with valid number near upper limit' do
56
+ context 'when created with valid number near upper limit' do
55
57
  include_examples 'equals input', max - step
56
58
  end
57
59
 
58
- context 'created with value at the upper limit' do
60
+ context 'when created with value at the upper limit' do
59
61
  include_examples 'equals input', max
60
62
  end
61
63
 
62
- context 'created with value above the upper limit' do
64
+ context 'when created with value above the upper limit' do
63
65
  include_examples 'raises ConstraintError', max + step
64
66
  end
65
67
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fortnox/api'
3
5
 
@@ -12,144 +14,144 @@ describe Fortnox::API do
12
14
  end
13
15
 
14
16
  describe 'configuration defaults' do
15
- subject(:config_value){ described_class.config[config_key] }
17
+ subject(:config_value) { described_class.config[config_key] }
16
18
 
17
- before{ Fortnox::API::TestBase.new }
19
+ before { Fortnox::API::TestBase.new }
18
20
 
19
21
  describe 'base_url' do
20
- let( :config_key ){ :base_url }
22
+ let(:config_key) { :base_url }
21
23
 
22
- it{ is_expected.to eql 'https://api.fortnox.se/3/' }
24
+ it { is_expected.to eql 'https://api.fortnox.se/3/' }
23
25
  end
24
26
 
25
27
  describe 'client_secret' do
26
- let( :config_key ){ :client_secret }
28
+ let(:config_key) { :client_secret }
27
29
 
28
- it{ is_expected.to be_nil }
30
+ it { is_expected.to be_nil }
29
31
  end
30
32
 
31
33
  describe 'access_token' do
32
- let( :config_key ){ :access_token }
34
+ let(:config_key) { :access_token }
33
35
 
34
- it{ is_expected.to be_nil }
36
+ it { is_expected.to be_nil }
35
37
  end
36
38
 
37
39
  describe 'access_tokens' do
38
- let( :config_key ){ :access_tokens }
40
+ let(:config_key) { :access_tokens }
39
41
 
40
- it{ is_expected.to be_nil }
42
+ it { is_expected.to be_nil }
41
43
  end
42
44
 
43
45
  describe 'token_store' do
44
- let( :config_key ){ :token_store }
46
+ let(:config_key) { :token_store }
45
47
 
46
- it{ is_expected.to eql( {} ) }
48
+ it { is_expected.to eql({}) }
47
49
  end
48
50
 
49
51
  describe 'debugging' do
50
- let( :config_key ){ :debugging }
52
+ let(:config_key) { :debugging }
51
53
 
52
- it{ is_expected.to be false }
54
+ it { is_expected.to be false }
53
55
  end
54
56
 
55
57
  describe 'logger' do
56
- let( :config_key ){ :logger }
58
+ let(:config_key) { :logger }
57
59
 
58
- it{ is_expected.to be_a Logger }
60
+ it { is_expected.to be_a Logger }
59
61
 
60
62
  describe 'level' do
61
- subject{ config_value.level }
63
+ subject { config_value.level }
62
64
 
63
- it{ is_expected.to be Logger::WARN }
65
+ it { is_expected.to be Logger::WARN }
64
66
  end
65
67
  end
66
68
  end
67
69
 
68
70
  describe 'access_token' do
69
71
  context 'when set to a String' do
70
- subject{ described_class.config.access_token }
72
+ subject { described_class.config.access_token }
71
73
 
72
- before{ described_class.configure{ |config| config.access_token = value } }
73
- let( :value ){ '12345' }
74
+ before { described_class.configure { |config| config.access_token = value } }
75
+ let(:value) { '12345' }
74
76
 
75
- it{ is_expected.to eql value }
77
+ it { is_expected.to eql value }
76
78
  end
77
79
 
78
80
  shared_examples_for 'invalid argument' do
79
- subject{ ->{ described_class.configure{ |config| config.access_token = value } } }
81
+ subject { -> { described_class.configure { |config| config.access_token = value } } }
80
82
 
81
- it{ is_expected.to raise_error(ArgumentError, /expected a String/) }
83
+ it { is_expected.to raise_error(ArgumentError, /expected a String/) }
82
84
  end
83
85
 
84
86
  context 'when set to a Hash' do
85
87
  include_examples 'invalid argument' do
86
- let( :value ){ { a: '123' } }
88
+ let(:value) { { a: '123' } }
87
89
  end
88
90
  end
89
91
 
90
92
  context 'when set to an Array' do
91
93
  include_examples 'invalid argument' do
92
- let( :value ){ ['123', '456'] }
94
+ let(:value) { %w[123 456] }
93
95
  end
94
96
  end
95
97
  end
96
98
 
97
99
  describe 'access_tokens' do
98
100
  context 'when set to a String' do
99
- subject{ ->{ described_class.configure{ |config| config.access_tokens = '12345' } } }
101
+ subject { -> { described_class.configure { |config| config.access_tokens = '12345' } } }
100
102
 
101
- it{ is_expected.to raise_error(ArgumentError, /expected a Hash or an Array/) }
103
+ it { is_expected.to raise_error(ArgumentError, /expected a Hash or an Array/) }
102
104
  end
103
105
 
104
106
  shared_examples_for 'valid argument' do
105
- subject{ described_class.configure{ |config| config.access_tokens = value } }
107
+ subject { described_class.configure { |config| config.access_tokens = value } }
106
108
 
107
- it{ is_expected.to eql( value ) }
109
+ it { is_expected.to eql(value) }
108
110
  end
109
111
 
110
112
  context 'when set to a Hash' do
111
113
  include_examples 'valid argument' do
112
- let( :value ){ { a: '123', b: '456' } }
114
+ let(:value) { { a: '123', b: '456' } }
113
115
  end
114
116
  end
115
117
 
116
118
  context 'when set to an Array' do
117
119
  include_examples 'valid argument' do
118
- let( :value ){ ['123', '456'] }
120
+ let(:value) { %w[123 456] }
119
121
  end
120
122
  end
121
123
  end
122
124
 
123
125
  describe 'token_store' do
124
- subject{ described_class.config[:token_store] }
126
+ subject { described_class.config[:token_store] }
125
127
 
126
128
  context 'when access_token set' do
127
- before{ described_class.configure{ |config| config.access_token = access_token } }
128
- let( :access_token ){ '12345' }
129
+ before { described_class.configure { |config| config.access_token = access_token } }
130
+ let(:access_token) { '12345' }
129
131
 
130
- it{ is_expected.to eql(default: access_token) }
132
+ it { is_expected.to eql(default: access_token) }
131
133
  end
132
134
 
133
135
  context 'when access_tokens is' do
134
- before{ described_class.configure{ |config| config.access_tokens = access_tokens } }
136
+ before { described_class.configure { |config| config.access_tokens = access_tokens } }
135
137
 
136
138
  describe 'a Hash' do
137
- let( :access_tokens ){ { a: '123', b: '456' } }
139
+ let(:access_tokens) { { a: '123', b: '456' } }
138
140
 
139
- it{ is_expected.to eql( access_tokens ) }
141
+ it { is_expected.to eql(access_tokens) }
140
142
  end
141
143
 
142
144
  describe 'an Array' do
143
- let( :access_tokens ){ ['123', '456'] }
145
+ let(:access_tokens) { %w[123 456] }
144
146
 
145
- it{ is_expected.to eql( default: access_tokens ) }
147
+ it { is_expected.to eql(default: access_tokens) }
146
148
  end
147
149
  end
148
150
  end
149
151
 
150
152
  describe 'readers for' do
151
153
  describe 'debugging' do
152
- subject{ described_class.debugging }
154
+ subject { described_class.debugging }
153
155
 
154
156
  it 'is available' do
155
157
  is_expected.to be false
@@ -157,7 +159,7 @@ describe Fortnox::API do
157
159
  end
158
160
 
159
161
  describe 'logger' do
160
- subject{ described_class.logger }
162
+ subject { described_class.logger }
161
163
 
162
164
  it 'is available' do
163
165
  is_expected.to be_a Logger