fortnox-api 0.5.2 → 0.6.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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +9 -1104
- data/.travis.yml +22 -2
- data/Gemfile +3 -1
- data/Guardfile +4 -2
- data/README.md +2 -2
- data/Rakefile +3 -1
- data/bin/console +17 -3
- data/fortnox-api.gemspec +32 -27
- data/lib/fortnox/api.rb +17 -16
- data/lib/fortnox/api/circular_queue.rb +13 -7
- data/lib/fortnox/api/mappers.rb +29 -25
- data/lib/fortnox/api/mappers/article.rb +7 -6
- data/lib/fortnox/api/mappers/base.rb +18 -16
- data/lib/fortnox/api/mappers/base/from_json.rb +37 -30
- data/lib/fortnox/api/mappers/base/to_json.rb +39 -37
- data/lib/fortnox/api/mappers/customer.rb +7 -7
- data/lib/fortnox/api/mappers/default_delivery_types.rb +4 -2
- data/lib/fortnox/api/mappers/default_templates.rb +5 -4
- data/lib/fortnox/api/mappers/edi_information.rb +5 -4
- data/lib/fortnox/api/mappers/email_information.rb +5 -4
- data/lib/fortnox/api/mappers/invoice.rb +10 -8
- data/lib/fortnox/api/mappers/invoice_row.rb +12 -7
- data/lib/fortnox/api/mappers/order.rb +10 -7
- data/lib/fortnox/api/mappers/order_row.rb +13 -6
- data/lib/fortnox/api/mappers/project.rb +6 -4
- data/lib/fortnox/api/mappers/terms_of_payments.rb +17 -0
- data/lib/fortnox/api/mappers/unit.rb +17 -0
- data/lib/fortnox/api/models.rb +9 -5
- data/lib/fortnox/api/models/article.rb +68 -67
- data/lib/fortnox/api/models/base.rb +52 -36
- data/lib/fortnox/api/models/customer.rb +95 -94
- data/lib/fortnox/api/models/document.rb +186 -0
- data/lib/fortnox/api/models/invoice.rb +44 -44
- data/lib/fortnox/api/models/label.rb +5 -3
- data/lib/fortnox/api/models/order.rb +8 -8
- data/lib/fortnox/api/models/project.rb +10 -8
- data/lib/fortnox/api/models/terms_of_payments.rb +28 -0
- data/lib/fortnox/api/models/unit.rb +24 -0
- data/lib/fortnox/api/repositories.rb +9 -5
- data/lib/fortnox/api/repositories/article.rb +6 -4
- data/lib/fortnox/api/repositories/base.rb +49 -46
- data/lib/fortnox/api/repositories/base/loaders.rb +32 -36
- data/lib/fortnox/api/repositories/base/savers.rb +23 -21
- data/lib/fortnox/api/repositories/customer.rb +6 -4
- data/lib/fortnox/api/repositories/invoice.rb +6 -4
- data/lib/fortnox/api/repositories/order.rb +6 -4
- data/lib/fortnox/api/repositories/project.rb +6 -4
- data/lib/fortnox/api/repositories/terms_of_payments.rb +17 -0
- data/lib/fortnox/api/repositories/unit.rb +17 -0
- data/lib/fortnox/api/request_handling.rb +12 -12
- data/lib/fortnox/api/types.rb +62 -11
- data/lib/fortnox/api/types/default_delivery_types.rb +5 -3
- data/lib/fortnox/api/types/default_templates.rb +3 -1
- data/lib/fortnox/api/types/defaulted.rb +2 -2
- data/lib/fortnox/api/types/document_row.rb +41 -42
- data/lib/fortnox/api/types/edi_information.rb +10 -8
- data/lib/fortnox/api/types/email_information.rb +10 -8
- data/lib/fortnox/api/types/enums.rb +60 -47
- data/lib/fortnox/api/types/invoice_row.rb +8 -8
- data/lib/fortnox/api/types/model.rb +14 -10
- data/lib/fortnox/api/types/nullable.rb +7 -7
- data/lib/fortnox/api/types/order_row.rb +5 -5
- data/lib/fortnox/api/types/required.rb +5 -5
- data/lib/fortnox/api/types/sized.rb +14 -6
- data/lib/fortnox/api/version.rb +3 -1
- data/spec/fortnox/api/mappers/article_spec.rb +3 -1
- data/spec/fortnox/api/mappers/base/from_json_spec.rb +15 -13
- data/spec/fortnox/api/mappers/base/to_json_spec.rb +4 -3
- data/spec/fortnox/api/mappers/base_spec.rb +40 -35
- data/spec/fortnox/api/mappers/contexts/json_conversion.rb +12 -11
- data/spec/fortnox/api/mappers/customer_spec.rb +3 -1
- data/spec/fortnox/api/mappers/default_delivery_types_spec.rb +3 -1
- data/spec/fortnox/api/mappers/edi_information_spec.rb +4 -2
- data/spec/fortnox/api/mappers/email_information_spec.rb +4 -2
- data/spec/fortnox/api/mappers/examples/mapper.rb +17 -9
- data/spec/fortnox/api/mappers/invoice_row_spec.rb +8 -3
- data/spec/fortnox/api/mappers/invoice_spec.rb +4 -1
- data/spec/fortnox/api/mappers/order_row_spec.rb +9 -2
- data/spec/fortnox/api/mappers/order_spec.rb +4 -1
- data/spec/fortnox/api/mappers/project_spec.rb +3 -1
- data/spec/fortnox/api/mappers/terms_of_payments_spec.rb +16 -0
- data/spec/fortnox/api/mappers/unit_spec.rb +57 -0
- data/spec/fortnox/api/models/article_spec.rb +2 -0
- data/spec/fortnox/api/models/base_spec.rb +46 -38
- data/spec/fortnox/api/models/customer_spec.rb +2 -0
- data/spec/fortnox/api/models/examples/document_base.rb +5 -3
- data/spec/fortnox/api/models/examples/model.rb +12 -9
- data/spec/fortnox/api/models/invoice_spec.rb +2 -0
- data/spec/fortnox/api/models/order_spec.rb +2 -0
- data/spec/fortnox/api/models/project_spec.rb +2 -0
- data/spec/fortnox/api/models/terms_of_payments_spec.rb +9 -0
- data/spec/fortnox/api/models/unit_spec.rb +31 -0
- data/spec/fortnox/api/repositories/article_spec.rb +7 -5
- data/spec/fortnox/api/repositories/base_spec.rb +121 -100
- data/spec/fortnox/api/repositories/customer_spec.rb +7 -5
- data/spec/fortnox/api/repositories/examples/all.rb +5 -4
- data/spec/fortnox/api/repositories/examples/find.rb +50 -41
- data/spec/fortnox/api/repositories/examples/only.rb +14 -13
- data/spec/fortnox/api/repositories/examples/save.rb +23 -29
- data/spec/fortnox/api/repositories/examples/save_with_nested_model.rb +11 -11
- data/spec/fortnox/api/repositories/examples/save_with_specially_named_attribute.rb +11 -10
- data/spec/fortnox/api/repositories/examples/search.rb +15 -15
- data/spec/fortnox/api/repositories/invoice_spec.rb +8 -6
- data/spec/fortnox/api/repositories/order_spec.rb +8 -6
- data/spec/fortnox/api/repositories/project_spec.rb +7 -5
- data/spec/fortnox/api/repositories/terms_of_payments_spec.rb +30 -0
- data/spec/fortnox/api/repositories/unit_spec.rb +34 -0
- data/spec/fortnox/api/types/account_number_spec.rb +12 -9
- data/spec/fortnox/api/types/default_delivery_types_spec.rb +6 -4
- data/spec/fortnox/api/types/edi_information_spec.rb +9 -7
- data/spec/fortnox/api/types/email_information_spec.rb +8 -6
- data/spec/fortnox/api/types/email_spec.rb +27 -14
- data/spec/fortnox/api/types/enums_spec.rb +3 -1
- data/spec/fortnox/api/types/examples/document_row.rb +10 -8
- data/spec/fortnox/api/types/examples/enum.rb +29 -22
- data/spec/fortnox/api/types/examples/types.rb +8 -4
- data/spec/fortnox/api/types/housework_types_spec.rb +68 -0
- data/spec/fortnox/api/types/invoice_row_spec.rb +3 -1
- data/spec/fortnox/api/types/model_spec.rb +12 -9
- data/spec/fortnox/api/types/nullable_spec.rb +8 -6
- data/spec/fortnox/api/types/order_row_spec.rb +4 -2
- data/spec/fortnox/api/types/required_spec.rb +4 -2
- data/spec/fortnox/api/types/sized_spec.rb +18 -16
- data/spec/fortnox/api_spec.rb +45 -43
- data/spec/spec_helper.rb +9 -6
- data/spec/support/helpers.rb +3 -1
- data/spec/support/helpers/configuration_helper.rb +2 -0
- data/spec/support/helpers/dummy_class_helper.rb +7 -8
- data/spec/support/helpers/repository_helper.rb +2 -0
- data/spec/support/helpers/when_performing_helper.rb +3 -1
- data/spec/support/matchers.rb +2 -0
- data/spec/support/matchers/type.rb +3 -1
- data/spec/support/matchers/type/attribute_matcher.rb +15 -14
- data/spec/support/matchers/type/enum_matcher.rb +9 -7
- data/spec/support/matchers/type/have_account_number_matcher.rb +11 -9
- data/spec/support/matchers/type/have_country_code_matcher.rb +6 -4
- data/spec/support/matchers/type/have_currency_matcher.rb +4 -2
- data/spec/support/matchers/type/have_customer_type_matcher.rb +6 -4
- data/spec/support/matchers/type/have_default_delivery_type_matcher.rb +4 -2
- data/spec/support/matchers/type/have_discount_type_matcher.rb +4 -2
- data/spec/support/matchers/type/have_email_matcher.rb +11 -9
- data/spec/support/matchers/type/have_housework_type_matcher.rb +9 -0
- data/spec/support/matchers/type/have_nullable_date_matcher.rb +29 -29
- data/spec/support/matchers/type/have_nullable_matcher.rb +23 -21
- data/spec/support/matchers/type/have_nullable_string_matcher.rb +30 -32
- data/spec/support/matchers/type/have_sized_float_matcher.rb +4 -2
- data/spec/support/matchers/type/have_sized_integer_matcher.rb +4 -2
- data/spec/support/matchers/type/have_sized_string_matcher.rb +16 -15
- data/spec/support/matchers/type/have_vat_type_matcher.rb +4 -2
- data/spec/support/matchers/type/numeric_matcher.rb +25 -23
- data/spec/support/matchers/type/require_attribute_matcher.rb +36 -37
- data/spec/support/matchers/type/type_matcher.rb +18 -16
- data/spec/support/vcr_setup.rb +2 -0
- data/spec/vcr_cassettes/orders/{house_work_type_babysitting.yml → housework_type_babysitting.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_cleaning.yml → housework_type_cleaning.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_construction.yml → housework_type_construction.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_cooking.yml → housework_type_cooking.yml} +7 -7
- data/spec/vcr_cassettes/orders/{house_work_type_electricity.yml → housework_type_electricity.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_gardening.yml → housework_type_gardening.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_glassmetalwork.yml → housework_type_glassmetalwork.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_grounddrainagework.yml → housework_type_grounddrainagework.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_hvac.yml → housework_type_hvac.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_masonry.yml → housework_type_masonry.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_othercare.yml → housework_type_othercare.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_othercosts.yml → housework_type_othercosts.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_paintingwallpapering.yml → housework_type_paintingwallpapering.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_snowplowing.yml → housework_type_snowplowing.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_textileclothing.yml → housework_type_textileclothing.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_tutoring.yml → housework_type_tutoring.yml} +7 -7
- data/spec/vcr_cassettes/termsofpayments/all.yml +51 -0
- data/spec/vcr_cassettes/termsofpayments/find_failure.yml +45 -0
- data/spec/vcr_cassettes/termsofpayments/find_id_1.yml +46 -0
- data/spec/vcr_cassettes/termsofpayments/find_new.yml +46 -0
- data/spec/vcr_cassettes/termsofpayments/save_new.yml +45 -0
- data/spec/vcr_cassettes/termsofpayments/save_old.yml +46 -0
- data/spec/vcr_cassettes/units/all.yml +48 -0
- data/spec/vcr_cassettes/units/find_failure.yml +45 -0
- data/spec/vcr_cassettes/units/find_id_1.yml +46 -0
- data/spec/vcr_cassettes/units/find_new.yml +48 -0
- data/spec/vcr_cassettes/units/save_new.yml +47 -0
- data/spec/vcr_cassettes/units/save_old.yml +48 -0
- data/spec/vcr_cassettes/units/save_with_specially_named_attribute.yml +47 -0
- metadata +127 -88
- data/docs/account.rb +0 -59
- data/docs/extraction_script.js +0 -23
- data/docs/generation_script.rb +0 -43
- data/docs/json/account.json +0 -77
- data/lib/fortnox/api/models/document_base.rb +0 -189
- data/spec/fortnox/api/types/house_work_types_spec.rb +0 -64
- data/spec/support/matchers/type/have_house_work_type_matcher.rb +0 -7
@@ -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'
|
@@ -13,9 +15,9 @@ require 'fortnox/api/repositories/examples/only'
|
|
13
15
|
describe Fortnox::API::Repository::Invoice, order: :defined, integration: true do
|
14
16
|
include Helpers::Configuration
|
15
17
|
|
16
|
-
before{ set_api_test_configuration }
|
18
|
+
before { set_api_test_configuration }
|
17
19
|
|
18
|
-
subject(:repository){ described_class.new }
|
20
|
+
subject(:repository) { described_class.new }
|
19
21
|
|
20
22
|
required_hash = { customer_number: '1' }
|
21
23
|
|
@@ -26,7 +28,7 @@ describe Fortnox::API::Repository::Invoice, order: :defined, integration: true d
|
|
26
28
|
required_hash,
|
27
29
|
:invoice_rows,
|
28
30
|
nested_model_hash,
|
29
|
-
[
|
31
|
+
[Fortnox::API::Types::InvoiceRow.new(nested_model_hash)]
|
30
32
|
|
31
33
|
include_examples '.save with specially named attribute',
|
32
34
|
required_hash,
|
@@ -38,12 +40,12 @@ describe Fortnox::API::Repository::Invoice, order: :defined, integration: true d
|
|
38
40
|
include_examples '.all', 60
|
39
41
|
|
40
42
|
include_examples '.find', 1 do
|
41
|
-
let(
|
43
|
+
let(:find_by_hash_failure) { { yourreference: 'Not found' } }
|
42
44
|
|
43
|
-
let(
|
45
|
+
let(:single_param_find_by_hash) do
|
44
46
|
{ find_hash: { yourreference: 'Gandalf the Grey' }, matches: 2 }
|
45
47
|
end
|
46
|
-
let(
|
48
|
+
let(:multi_param_find_by_hash) do
|
47
49
|
{ find_hash: { yourreference: 'Gandalf the Grey', ourreference: 'Radagast the Brown' },
|
48
50
|
matches: 1 }
|
49
51
|
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'
|
@@ -12,9 +14,9 @@ require 'fortnox/api/repositories/examples/search'
|
|
12
14
|
describe Fortnox::API::Repository::Order, order: :defined, integration: true do
|
13
15
|
include Helpers::Configuration
|
14
16
|
|
15
|
-
before{ set_api_test_configuration }
|
17
|
+
before { set_api_test_configuration }
|
16
18
|
|
17
|
-
subject(:repository){ described_class.new }
|
19
|
+
subject(:repository) { described_class.new }
|
18
20
|
|
19
21
|
required_hash = { customer_number: '1' }
|
20
22
|
|
@@ -25,19 +27,19 @@ describe Fortnox::API::Repository::Order, order: :defined, integration: true do
|
|
25
27
|
required_hash,
|
26
28
|
:order_rows,
|
27
29
|
nested_model_hash,
|
28
|
-
[
|
30
|
+
[Fortnox::API::Types::OrderRow.new(nested_model_hash)]
|
29
31
|
|
30
32
|
# It is not possible to delete Orders. Therefore, expected nr of Orders
|
31
33
|
# when running .all will continue to increase (until 100, which is max by default).
|
32
34
|
include_examples '.all', 100
|
33
35
|
|
34
36
|
include_examples '.find', 1 do
|
35
|
-
let(
|
37
|
+
let(:find_by_hash_failure) { { ourreference: 'Not found' } }
|
36
38
|
|
37
|
-
let(
|
39
|
+
let(:single_param_find_by_hash) do
|
38
40
|
{ find_hash: { ourreference: 'Belladonna Took' }, matches: 2 }
|
39
41
|
end
|
40
|
-
let(
|
42
|
+
let(:multi_param_find_by_hash) do
|
41
43
|
{ find_hash: { ourreference: 'Belladonna Took', yourreference: 'Bodo Proudfoot' },
|
42
44
|
matches: 1 }
|
43
45
|
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'
|
@@ -9,9 +11,9 @@ require 'fortnox/api/repositories/examples/save'
|
|
9
11
|
describe Fortnox::API::Repository::Project, order: :defined, integration: true do
|
10
12
|
include Helpers::Configuration
|
11
13
|
|
12
|
-
before{ set_api_test_configuration }
|
14
|
+
before { set_api_test_configuration }
|
13
15
|
|
14
|
-
subject(
|
16
|
+
subject(:repository) { described_class.new }
|
15
17
|
|
16
18
|
include_examples '.save',
|
17
19
|
:comments,
|
@@ -23,10 +25,10 @@ describe Fortnox::API::Repository::Project, order: :defined, integration: true d
|
|
23
25
|
include_examples '.all', 8
|
24
26
|
|
25
27
|
include_examples '.find', '1' do
|
26
|
-
let(
|
27
|
-
let(
|
28
|
+
let(:find_by_hash_failure) { { offset: 10_000 } }
|
29
|
+
let(:single_param_find_by_hash) { { find_hash: { limit: 1 }, matches: 1 } }
|
28
30
|
|
29
|
-
let(
|
31
|
+
let(:multi_param_find_by_hash) do
|
30
32
|
{ find_hash: { limit: 2, offset: 2 }, matches: 2 }
|
31
33
|
end
|
32
34
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'fortnox/api'
|
5
|
+
require 'fortnox/api/mappers'
|
6
|
+
require 'fortnox/api/repositories/terms_of_payments'
|
7
|
+
require 'fortnox/api/repositories/examples/all'
|
8
|
+
require 'fortnox/api/repositories/examples/find'
|
9
|
+
require 'fortnox/api/repositories/examples/save'
|
10
|
+
require 'fortnox/api/repositories/examples/save_with_specially_named_attribute'
|
11
|
+
require 'fortnox/api/repositories/examples/search'
|
12
|
+
|
13
|
+
describe Fortnox::API::Repository::TermsOfPayments, order: :defined, integration: true do
|
14
|
+
include Helpers::Configuration
|
15
|
+
|
16
|
+
subject(:repository) { described_class.new }
|
17
|
+
|
18
|
+
before { set_api_test_configuration }
|
19
|
+
|
20
|
+
required_hash = { code: '15DAYS' }
|
21
|
+
|
22
|
+
include_examples '.save', :description, additional_attrs: required_hash
|
23
|
+
|
24
|
+
include_examples '.all', 9
|
25
|
+
|
26
|
+
include_examples '.find', '15DAYS', find_by_hash: false do
|
27
|
+
let(:find_by_hash_failure) { { code: '15days' } }
|
28
|
+
let(:single_param_find_by_hash) { { find_hash: { code: '30days' }, matches: 1 } }
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'fortnox/api'
|
5
|
+
require 'fortnox/api/mappers'
|
6
|
+
require 'fortnox/api/repositories/unit'
|
7
|
+
require 'fortnox/api/repositories/examples/all'
|
8
|
+
require 'fortnox/api/repositories/examples/find'
|
9
|
+
require 'fortnox/api/repositories/examples/save'
|
10
|
+
require 'fortnox/api/repositories/examples/save_with_specially_named_attribute'
|
11
|
+
|
12
|
+
describe Fortnox::API::Repository::Unit, order: :defined, integration: true do
|
13
|
+
include Helpers::Configuration
|
14
|
+
|
15
|
+
before { set_api_test_configuration }
|
16
|
+
|
17
|
+
subject(:repository) { described_class.new }
|
18
|
+
|
19
|
+
include_examples '.save',
|
20
|
+
:description,
|
21
|
+
additional_attrs: { code: 'blarg' }
|
22
|
+
|
23
|
+
include_examples '.save with specially named attribute',
|
24
|
+
{ description: 'Happy clouds' },
|
25
|
+
:code,
|
26
|
+
'woooh'
|
27
|
+
|
28
|
+
include_examples '.all', 6
|
29
|
+
|
30
|
+
include_examples '.find', 'blarg', find_by_hash: false do
|
31
|
+
let(:find_by_hash_failure) { { code: 'notfound' } }
|
32
|
+
let(:single_param_find_by_hash) { { find_hash: { code: 'blarg' }, matches: 1 } }
|
33
|
+
end
|
34
|
+
end
|
@@ -1,28 +1,31 @@
|
|
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 do
|
6
|
-
let(
|
8
|
+
let(:klass) { Fortnox::API::Types::AccountNumber }
|
9
|
+
|
10
|
+
context 'when AccountNumber created with nil' do
|
11
|
+
subject { klass[nil] }
|
7
12
|
|
8
|
-
|
9
|
-
subject{ klass[ nil ] }
|
10
|
-
it{ is_expected.to be_nil }
|
13
|
+
it { is_expected.to be_nil }
|
11
14
|
end
|
12
15
|
|
13
|
-
context 'AccountNumber created with empty string' do
|
16
|
+
context 'when AccountNumber created with empty string' do
|
14
17
|
include_examples 'raises ConstraintError', ''
|
15
18
|
end
|
16
19
|
|
17
|
-
context 'AccountNumber created with valid number' do
|
20
|
+
context 'when AccountNumber created with valid number' do
|
18
21
|
include_examples 'equals input', 1234
|
19
22
|
end
|
20
23
|
|
21
|
-
context 'AccountNumber created with a too large number' do
|
22
|
-
include_examples 'raises ConstraintError',
|
24
|
+
context 'when AccountNumber created with a too large number' do
|
25
|
+
include_examples 'raises ConstraintError', 10_000
|
23
26
|
end
|
24
27
|
|
25
|
-
context 'AccountNumber created with a negative number' do
|
28
|
+
context 'when AccountNumber created with a negative number' do
|
26
29
|
include_examples 'raises ConstraintError', -1
|
27
30
|
end
|
28
31
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'fortnox/api/types/default_delivery_types'
|
3
5
|
|
4
6
|
RSpec.describe Fortnox::API::Types::DefaultDeliveryTypes, type: :type do
|
5
|
-
subject{ described_class }
|
7
|
+
subject { described_class }
|
6
8
|
|
7
|
-
it{ is_expected.to have_default_delivery_type(
|
8
|
-
it{ is_expected.to have_default_delivery_type(
|
9
|
-
it{ is_expected.to have_default_delivery_type(
|
9
|
+
it { is_expected.to have_default_delivery_type(:invoice) }
|
10
|
+
it { is_expected.to have_default_delivery_type(:order) }
|
11
|
+
it { is_expected.to have_default_delivery_type(:offer) }
|
10
12
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'fortnox/api/types/edi_information'
|
3
5
|
|
4
6
|
RSpec.describe Fortnox::API::Types::EDIInformation, type: :type do
|
5
|
-
subject{ described_class }
|
7
|
+
subject { described_class }
|
6
8
|
|
7
|
-
it{ is_expected.to have_nullable_string(
|
8
|
-
it{ is_expected.to have_nullable_string(
|
9
|
-
it{ is_expected.to have_nullable_string(
|
10
|
-
it{ is_expected.to have_nullable_string(
|
11
|
-
it{ is_expected.to have_nullable_string(
|
12
|
-
it{ is_expected.to have_nullable_string(
|
9
|
+
it { is_expected.to have_nullable_string(:edi_global_location_number) }
|
10
|
+
it { is_expected.to have_nullable_string(:edi_global_location_number_delivery) }
|
11
|
+
it { is_expected.to have_nullable_string(:edi_invoice_extra1) }
|
12
|
+
it { is_expected.to have_nullable_string(:edi_invoice_extra2) }
|
13
|
+
it { is_expected.to have_nullable_string(:edi_our_electronic_reference) }
|
14
|
+
it { is_expected.to have_nullable_string(:edi_your_electronic_reference) }
|
13
15
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'fortnox/api/types/email_information'
|
3
5
|
|
4
6
|
RSpec.describe Fortnox::API::Types::EmailInformation, type: :type do
|
5
|
-
subject{ described_class }
|
7
|
+
subject { described_class }
|
6
8
|
|
7
|
-
it{ is_expected.to have_email(
|
8
|
-
it{ is_expected.to have_email(
|
9
|
-
it{ is_expected.to have_email(
|
9
|
+
it { is_expected.to have_email(:email_address_to) }
|
10
|
+
it { is_expected.to have_email(:email_address_cc) }
|
11
|
+
it { is_expected.to have_email(:email_address_bcc) }
|
10
12
|
|
11
|
-
it{ is_expected.to have_sized_string(
|
12
|
-
it{ is_expected.to have_sized_string(
|
13
|
+
it { is_expected.to have_sized_string(:email_subject, 100) }
|
14
|
+
it { is_expected.to have_sized_string(:email_body, 20_000) }
|
13
15
|
end
|
@@ -1,28 +1,41 @@
|
|
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
|
-
describe Fortnox::API::Types do
|
6
|
-
let(
|
7
|
+
describe Fortnox::API::Types::Email do
|
8
|
+
let(:klass) { described_class }
|
9
|
+
|
10
|
+
context 'when created with nil' do
|
11
|
+
subject { described_class[nil] }
|
7
12
|
|
8
|
-
|
9
|
-
subject{ klass[ nil ] }
|
10
|
-
it{ is_expected.to be_nil }
|
13
|
+
it { is_expected.to be_nil }
|
11
14
|
end
|
12
15
|
|
13
|
-
context '
|
14
|
-
subject{
|
15
|
-
|
16
|
+
context 'when created with empty string' do
|
17
|
+
subject { described_class[''] }
|
18
|
+
|
19
|
+
it { is_expected.to eq('') }
|
20
|
+
end
|
21
|
+
|
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 }
|
30
|
+
end
|
16
31
|
end
|
17
32
|
|
18
|
-
context '
|
19
|
-
|
20
|
-
let( :input ){ 'test@example.com' }
|
21
|
-
it{ is_expected.to eq input }
|
33
|
+
context 'when created with invalid email' do
|
34
|
+
include_examples 'raises ConstraintError', 'te$£@st@example.com'
|
22
35
|
end
|
23
36
|
|
24
|
-
context '
|
25
|
-
legal_characters = '
|
37
|
+
context 'when created with more than 1024 characters' do
|
38
|
+
legal_characters = 'abcdefghijklmnopqrstuvwxyz0123456789.-_+'.split('')
|
26
39
|
too_long_email = (legal_characters * 35).shuffle.join + '@example.com'
|
27
40
|
include_examples 'raises ConstraintError', too_long_email
|
28
41
|
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/examples/enum'
|
@@ -8,7 +10,7 @@ describe Fortnox::API::Types do
|
|
8
10
|
it_behaves_like 'enum', 'Currency', 'Currencies', auto_crop: true
|
9
11
|
it_behaves_like 'enum', 'CustomerType', 'CustomerTypes'
|
10
12
|
it_behaves_like 'enum', 'DiscountType', 'DiscountTypes'
|
11
|
-
it_behaves_like 'enum', '
|
13
|
+
it_behaves_like 'enum', 'HouseworkType', 'HouseworkTypes'
|
12
14
|
it_behaves_like 'enum', 'VATType', 'VATTypes'
|
13
15
|
it_behaves_like 'enum', 'DefaultDeliveryType', 'DefaultDeliveryTypeValues'
|
14
16
|
it_behaves_like 'enum', 'ProjectStatusType', 'ProjectStatusTypes'
|
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
shared_examples_for 'DocumentRow' do |valid_hash|
|
2
|
-
it{ is_expected.to have_account_number(
|
4
|
+
it { is_expected.to have_account_number(:account_number, valid_hash) }
|
3
5
|
|
4
|
-
it{ is_expected.to have_sized_string(
|
5
|
-
it{ is_expected.to have_sized_string(
|
6
|
+
it { is_expected.to have_sized_string(:article_number, 50, valid_hash) }
|
7
|
+
it { is_expected.to have_sized_string(:description, 50, valid_hash) }
|
6
8
|
|
7
|
-
it{ is_expected.to have_sized_float(
|
8
|
-
it{ is_expected.to have_sized_float(
|
9
|
+
it { is_expected.to have_sized_float(:delivered_quantity, 0.0, 9_999_999_999_999.9, valid_hash) }
|
10
|
+
it { is_expected.to have_sized_float(:price, 0.0, 99_999_999_999.9, valid_hash) }
|
9
11
|
|
10
|
-
it{ is_expected.to have_discount_type(
|
12
|
+
it { is_expected.to have_discount_type(:discount_type, valid_hash) }
|
11
13
|
|
12
|
-
it{ is_expected.to have_sized_integer(
|
14
|
+
it { is_expected.to have_sized_integer(:housework_hours_to_report, 0, 99_999, valid_hash) }
|
13
15
|
|
14
|
-
it{ is_expected.to
|
16
|
+
it { is_expected.to have_housework_type(:housework_type, valid_hash) }
|
15
17
|
end
|
@@ -1,47 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'fortnox/api/types/examples/types'
|
2
4
|
|
3
5
|
shared_examples_for 'enum' do |name, values, auto_crop: false|
|
4
6
|
describe name do
|
5
|
-
let(
|
7
|
+
let(:klass) { Fortnox::API::Types.const_get(name) }
|
8
|
+
|
9
|
+
context 'when created with nil' do
|
10
|
+
subject { klass[nil] }
|
6
11
|
|
7
|
-
|
8
|
-
subject{ klass[ nil ] }
|
9
|
-
it{ is_expected.to be_nil }
|
12
|
+
it { is_expected.to be_nil }
|
10
13
|
end
|
11
14
|
|
12
|
-
context 'created
|
13
|
-
subject{ klass[
|
15
|
+
context 'when created' do
|
16
|
+
subject { klass[input] }
|
17
|
+
|
18
|
+
let(:enum_value) { Fortnox::API::Types.const_get(values).values.sample }
|
14
19
|
|
15
|
-
|
20
|
+
context 'with a random member from then enum' do
|
21
|
+
let(:input) { enum_value }
|
16
22
|
|
17
|
-
|
18
|
-
let(:input){ enum_value }
|
19
|
-
it{ is_expected.to eq enum_value }
|
23
|
+
it { is_expected.to eq enum_value }
|
20
24
|
end
|
21
25
|
|
22
|
-
context 'a symoblised, random member from the enum' do
|
23
|
-
let(
|
24
|
-
|
26
|
+
context 'with a symoblised, random member from the enum' do
|
27
|
+
let(:input) { enum_value.to_sym }
|
28
|
+
|
29
|
+
it { is_expected.to eq enum_value }
|
25
30
|
end
|
26
31
|
|
27
|
-
context 'a lower case, random member from the enum' do
|
28
|
-
let(
|
29
|
-
|
32
|
+
context 'with a lower case, random member from the enum' do
|
33
|
+
let(:input) { enum_value.downcase }
|
34
|
+
|
35
|
+
it { is_expected.to eq enum_value }
|
30
36
|
end
|
31
37
|
|
32
|
-
context 'a string that starts like a random member from the enum' do
|
33
|
-
let(
|
38
|
+
context 'with a string that starts like a random member from the enum' do
|
39
|
+
let(:input) { enum_value.downcase + 'more string' }
|
34
40
|
|
35
41
|
if auto_crop
|
36
|
-
it{ is_expected.to eq enum_value }
|
42
|
+
it { is_expected.to eq enum_value }
|
37
43
|
else
|
38
|
-
subject{ ->{ klass[
|
39
|
-
|
44
|
+
subject { -> { klass[input] } }
|
45
|
+
|
46
|
+
it { is_expected.to raise_error(Dry::Types::ConstraintError) }
|
40
47
|
end
|
41
48
|
end
|
42
49
|
end
|
43
50
|
|
44
|
-
context 'created with invalid input' do
|
51
|
+
context 'when created with invalid input' do
|
45
52
|
include_examples 'raises ConstraintError', 'r4nd0m'
|
46
53
|
end
|
47
54
|
end
|