my_john_deere_api 2.4.1
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 +7 -0
- data/README.md +813 -0
- data/Rakefile +9 -0
- data/lib/my_john_deere_api.rb +17 -0
- data/lib/my_john_deere_api/authorize.rb +69 -0
- data/lib/my_john_deere_api/client.rb +151 -0
- data/lib/my_john_deere_api/consumer.rb +90 -0
- data/lib/my_john_deere_api/errors.rb +7 -0
- data/lib/my_john_deere_api/errors/invalid_record_error.rb +29 -0
- data/lib/my_john_deere_api/errors/missing_contribution_definition_id_error.rb +12 -0
- data/lib/my_john_deere_api/errors/not_yet_implemented_error.rb +12 -0
- data/lib/my_john_deere_api/errors/type_mismatch_error.rb +12 -0
- data/lib/my_john_deere_api/errors/unsupported_environment_error.rb +18 -0
- data/lib/my_john_deere_api/helpers.rb +6 -0
- data/lib/my_john_deere_api/helpers/case_conversion.rb +37 -0
- data/lib/my_john_deere_api/helpers/environment_helper.rb +25 -0
- data/lib/my_john_deere_api/helpers/uri_helpers.rb +19 -0
- data/lib/my_john_deere_api/helpers/validate_contribution_definition.rb +18 -0
- data/lib/my_john_deere_api/model.rb +10 -0
- data/lib/my_john_deere_api/model/asset.rb +69 -0
- data/lib/my_john_deere_api/model/asset_location.rb +19 -0
- data/lib/my_john_deere_api/model/base.rb +97 -0
- data/lib/my_john_deere_api/model/contribution_definition.rb +15 -0
- data/lib/my_john_deere_api/model/contribution_product.rb +33 -0
- data/lib/my_john_deere_api/model/field.rb +40 -0
- data/lib/my_john_deere_api/model/flag.rb +36 -0
- data/lib/my_john_deere_api/model/organization.rb +43 -0
- data/lib/my_john_deere_api/net_http_retry.rb +2 -0
- data/lib/my_john_deere_api/net_http_retry/decorator.rb +53 -0
- data/lib/my_john_deere_api/net_http_retry/max_retries_exceeded_error.rb +20 -0
- data/lib/my_john_deere_api/request.rb +6 -0
- data/lib/my_john_deere_api/request/collection.rb +10 -0
- data/lib/my_john_deere_api/request/collection/asset_locations.rb +27 -0
- data/lib/my_john_deere_api/request/collection/assets.rb +34 -0
- data/lib/my_john_deere_api/request/collection/base.rb +91 -0
- data/lib/my_john_deere_api/request/collection/contribution_definitions.rb +26 -0
- data/lib/my_john_deere_api/request/collection/contribution_products.rb +26 -0
- data/lib/my_john_deere_api/request/collection/fields.rb +26 -0
- data/lib/my_john_deere_api/request/collection/flags.rb +33 -0
- data/lib/my_john_deere_api/request/collection/organizations.rb +26 -0
- data/lib/my_john_deere_api/request/create.rb +5 -0
- data/lib/my_john_deere_api/request/create/asset.rb +57 -0
- data/lib/my_john_deere_api/request/create/asset_location.rb +110 -0
- data/lib/my_john_deere_api/request/create/base.rb +67 -0
- data/lib/my_john_deere_api/request/individual.rb +8 -0
- data/lib/my_john_deere_api/request/individual/asset.rb +19 -0
- data/lib/my_john_deere_api/request/individual/base.rb +52 -0
- data/lib/my_john_deere_api/request/individual/contribution_definition.rb +19 -0
- data/lib/my_john_deere_api/request/individual/contribution_product.rb +19 -0
- data/lib/my_john_deere_api/request/individual/field.rb +19 -0
- data/lib/my_john_deere_api/request/individual/organization.rb +19 -0
- data/lib/my_john_deere_api/request/update.rb +4 -0
- data/lib/my_john_deere_api/request/update/asset.rb +40 -0
- data/lib/my_john_deere_api/request/update/base.rb +67 -0
- data/lib/my_john_deere_api/validators.rb +5 -0
- data/lib/my_john_deere_api/validators/asset.rb +35 -0
- data/lib/my_john_deere_api/validators/asset_location.rb +34 -0
- data/lib/my_john_deere_api/validators/base.rb +67 -0
- data/lib/my_john_deere_api/version.rb +3 -0
- data/test/lib/my_john_deere_api/authorize_test.rb +81 -0
- data/test/lib/my_john_deere_api/client_test.rb +225 -0
- data/test/lib/my_john_deere_api/consumer_test.rb +58 -0
- data/test/lib/my_john_deere_api/errors/invalid_record_error_test.rb +26 -0
- data/test/lib/my_john_deere_api/errors/max_retries_exceeded_error_test.rb +13 -0
- data/test/lib/my_john_deere_api/errors/missing_contribution_definition_id_error_test.rb +14 -0
- data/test/lib/my_john_deere_api/errors/not_yet_implemented_error_test.rb +13 -0
- data/test/lib/my_john_deere_api/errors/type_mismatch_error_test.rb +13 -0
- data/test/lib/my_john_deere_api/errors/unsupported_environment_error_test.rb +18 -0
- data/test/lib/my_john_deere_api/errors_test.rb +25 -0
- data/test/lib/my_john_deere_api/helpers/case_conversion_test.rb +100 -0
- data/test/lib/my_john_deere_api/helpers/environment_helper_test.rb +67 -0
- data/test/lib/my_john_deere_api/helpers/uri_helpers_test.rb +58 -0
- data/test/lib/my_john_deere_api/helpers/validate_contribution_definition_test.rb +74 -0
- data/test/lib/my_john_deere_api/helpers_test.rb +21 -0
- data/test/lib/my_john_deere_api/model/asset_location_test.rb +38 -0
- data/test/lib/my_john_deere_api/model/asset_test.rb +133 -0
- data/test/lib/my_john_deere_api/model/base_test.rb +76 -0
- data/test/lib/my_john_deere_api/model/contribution_definition_test.rb +52 -0
- data/test/lib/my_john_deere_api/model/contribution_product_test.rb +82 -0
- data/test/lib/my_john_deere_api/model/field_test.rb +65 -0
- data/test/lib/my_john_deere_api/model/flag_test.rb +48 -0
- data/test/lib/my_john_deere_api/model/organization_test.rb +84 -0
- data/test/lib/my_john_deere_api/model_test.rb +37 -0
- data/test/lib/my_john_deere_api/net_http_retry/decorator_test.rb +163 -0
- data/test/lib/my_john_deere_api/request/collection/asset_locations_test.rb +102 -0
- data/test/lib/my_john_deere_api/request/collection/assets_test.rb +99 -0
- data/test/lib/my_john_deere_api/request/collection/base_test.rb +27 -0
- data/test/lib/my_john_deere_api/request/collection/contribution_definitions_test.rb +88 -0
- data/test/lib/my_john_deere_api/request/collection/contribution_products_test.rb +88 -0
- data/test/lib/my_john_deere_api/request/collection/fields_test.rb +86 -0
- data/test/lib/my_john_deere_api/request/collection/flags_test.rb +92 -0
- data/test/lib/my_john_deere_api/request/collection/organizations_test.rb +87 -0
- data/test/lib/my_john_deere_api/request/collection_test.rb +37 -0
- data/test/lib/my_john_deere_api/request/create/asset_location_test.rb +163 -0
- data/test/lib/my_john_deere_api/request/create/asset_test.rb +182 -0
- data/test/lib/my_john_deere_api/request/create/base_test.rb +29 -0
- data/test/lib/my_john_deere_api/request/create_test.rb +17 -0
- data/test/lib/my_john_deere_api/request/individual/asset_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual/base_test.rb +18 -0
- data/test/lib/my_john_deere_api/request/individual/contribution_definition_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual/contribution_product_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual/field_test.rb +37 -0
- data/test/lib/my_john_deere_api/request/individual/organization_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual_test.rb +29 -0
- data/test/lib/my_john_deere_api/request/update/asset_test.rb +99 -0
- data/test/lib/my_john_deere_api/request/update/base_test.rb +60 -0
- data/test/lib/my_john_deere_api/request/update_test.rb +13 -0
- data/test/lib/my_john_deere_api/request_test.rb +21 -0
- data/test/lib/my_john_deere_api/validators/asset_location_test.rb +61 -0
- data/test/lib/my_john_deere_api/validators/asset_test.rb +93 -0
- data/test/lib/my_john_deere_api/validators/base_test.rb +92 -0
- data/test/lib/my_john_deere_api/validators_test.rb +17 -0
- data/test/lib/my_john_deere_api/version_test.rb +9 -0
- data/test/my_john_deere_api_test.rb +37 -0
- data/test/support/helper.rb +97 -0
- data/test/support/vcr/accessor/delete_failed.yml +327 -0
- data/test/support/vcr/accessor/delete_max_failed.yml +615 -0
- data/test/support/vcr/accessor/delete_retry.yml +191 -0
- data/test/support/vcr/accessor/delete_retry_too_soon.yml +191 -0
- data/test/support/vcr/accessor/get_failed.yml +390 -0
- data/test/support/vcr/accessor/get_max_failed.yml +734 -0
- data/test/support/vcr/accessor/get_retry.yml +226 -0
- data/test/support/vcr/accessor/get_retry_too_soon.yml +226 -0
- data/test/support/vcr/accessor/post_failed.yml +417 -0
- data/test/support/vcr/accessor/post_max_failed.yml +785 -0
- data/test/support/vcr/accessor/post_retry.yml +241 -0
- data/test/support/vcr/accessor/post_retry_too_soon.yml +241 -0
- data/test/support/vcr/accessor/put_failed.yml +372 -0
- data/test/support/vcr/accessor/put_max_failed.yml +700 -0
- data/test/support/vcr/accessor/put_retry.yml +216 -0
- data/test/support/vcr/accessor/put_retry_too_soon.yml +216 -0
- data/test/support/vcr/catalog.yml +89 -0
- data/test/support/vcr/delete_asset.yml +82 -0
- data/test/support/vcr/get_access_token.yml +41 -0
- data/test/support/vcr/get_asset.yml +144 -0
- data/test/support/vcr/get_asset_locations.yml +196 -0
- data/test/support/vcr/get_assets.yml +152 -0
- data/test/support/vcr/get_contribution_definition.yml +90 -0
- data/test/support/vcr/get_contribution_definitions.yml +91 -0
- data/test/support/vcr/get_contribution_product.yml +91 -0
- data/test/support/vcr/get_contribution_products.yml +91 -0
- data/test/support/vcr/get_field.yml +144 -0
- data/test/support/vcr/get_fields.yml +146 -0
- data/test/support/vcr/get_flags.yml +47 -0
- data/test/support/vcr/get_organization.yml +90 -0
- data/test/support/vcr/get_organizations.yml +149 -0
- data/test/support/vcr/get_request_token.yml +83 -0
- data/test/support/vcr/post_asset_locations.yml +244 -0
- data/test/support/vcr/post_assets.yml +192 -0
- data/test/support/vcr/put_asset.yml +87 -0
- data/test/support/vcr/warning.txt +28 -0
- data/test/support/vcr_setup.rb +488 -0
- metadata +277 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
describe 'MyJohnDeereApi::Request::Individual::Base' do
|
6
|
+
let(:object) { JD::Request::Individual::Base.new(client, asset_id) }
|
7
|
+
|
8
|
+
describe '#initialize(client, asset_id)' do
|
9
|
+
it 'accepts a client' do
|
10
|
+
assert_equal client, object.client
|
11
|
+
assert_equal accessor, object.accessor
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'accepts asset_id as id' do
|
15
|
+
assert_equal asset_id, object.id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
describe 'MyJohnDeereApi::Request::Individual::ContributionDefinition' do
|
6
|
+
let(:object) { JD::Request::Individual::ContributionDefinition.new(client, contribution_definition_id) }
|
7
|
+
|
8
|
+
inherits_from JD::Request::Individual::Base
|
9
|
+
|
10
|
+
describe '#initialize(client, contribution_definition_id)' do
|
11
|
+
it 'accepts a client' do
|
12
|
+
assert_equal client, object.client
|
13
|
+
assert_equal accessor, object.accessor
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'accepts contribution_definition_id as id' do
|
17
|
+
assert_equal contribution_definition_id, object.id
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#resource' do
|
22
|
+
it 'returns /contributionDefinitions/<definition_id>' do
|
23
|
+
assert_equal "/contributionDefinitions/#{contribution_definition_id}", object.resource
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#object' do
|
28
|
+
it 'returns all records' do
|
29
|
+
definition = VCR.use_cassette('get_contribution_definition') { object.object }
|
30
|
+
assert_kind_of JD::Model::ContributionDefinition, definition
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
describe 'MyJohnDeereApi::Request::Individual::ContributionProduct' do
|
6
|
+
let(:object) { JD::Request::Individual::ContributionProduct.new(client, contribution_product_id) }
|
7
|
+
|
8
|
+
inherits_from JD::Request::Individual::Base
|
9
|
+
|
10
|
+
describe '#initialize(client, contribution_product_id)' do
|
11
|
+
it 'accepts a client' do
|
12
|
+
assert_equal client, object.client
|
13
|
+
assert_equal accessor, object.accessor
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'accepts contribution_product_id as id' do
|
17
|
+
assert_equal contribution_product_id, object.id
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#resource' do
|
22
|
+
it 'returns /contributionProducts/<product_id>' do
|
23
|
+
assert_equal "/contributionProducts/#{contribution_product_id}", object.resource
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#object' do
|
28
|
+
it 'returns all records' do
|
29
|
+
product = VCR.use_cassette('get_contribution_product') { object.object }
|
30
|
+
assert_kind_of JD::Model::ContributionProduct, product
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
describe 'MyJohnDeereApi::Request::Individual::Field' do
|
6
|
+
let(:object) { JD::Request::Individual::Field.new(client, field_id, organization: organization_id) }
|
7
|
+
|
8
|
+
inherits_from JD::Request::Individual::Base
|
9
|
+
|
10
|
+
describe '#initialize(client, organization_id, field_id)' do
|
11
|
+
it 'accepts a client' do
|
12
|
+
assert_equal client, object.client
|
13
|
+
assert_equal accessor, object.accessor
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'accepts organization_id as organization_id' do
|
17
|
+
assert_equal organization_id, object.associations[:organization]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'accepts field_id as id' do
|
21
|
+
assert_equal field_id, object.id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#resource' do
|
26
|
+
it 'returns /organizations/<organization_id>/fields/<field_id>' do
|
27
|
+
assert_equal "/organizations/#{organization_id}/fields/#{field_id}", object.resource
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#object' do
|
32
|
+
it 'returns all records' do
|
33
|
+
field = VCR.use_cassette('get_field') { object.object }
|
34
|
+
assert_kind_of JD::Model::Field, field
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
describe 'MyJohnDeereApi::Request::Individual::Organization' do
|
6
|
+
let(:object) { JD::Request::Individual::Organization.new(client, organization_id) }
|
7
|
+
|
8
|
+
inherits_from JD::Request::Individual::Base
|
9
|
+
|
10
|
+
describe '#initialize(client, asset_id)' do
|
11
|
+
it 'accepts a client' do
|
12
|
+
assert_equal client, object.client
|
13
|
+
assert_equal accessor, object.accessor
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'accepts organization_id as id' do
|
17
|
+
assert_equal organization_id, object.id
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#resource' do
|
22
|
+
it 'returns /organizations/<organization_id>' do
|
23
|
+
assert_equal "/organizations/#{organization_id}", object.resource
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#object' do
|
28
|
+
it 'returns all records' do
|
29
|
+
organization = VCR.use_cassette('get_organization') { object.object }
|
30
|
+
assert_kind_of JD::Model::Organization, organization
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::Request::Individual' do
|
4
|
+
describe 'loading dependencies' do
|
5
|
+
it 'loads Request::Individual::Base' do
|
6
|
+
assert JD::Request::Individual::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'loads Request::Individual::Asset' do
|
10
|
+
assert JD::Request::Individual::Asset
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'loads Request::Individual::ContributionProduct' do
|
14
|
+
assert JD::Request::Individual::ContributionProduct
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'loads Request::Individual::ContributionDefinition' do
|
18
|
+
assert JD::Request::Individual::ContributionDefinition
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'loads Request::Individual::Field' do
|
22
|
+
assert JD::Request::Individual::Field
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'loads Request::Individual::Organization' do
|
26
|
+
assert JD::Request::Individual::Organization
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::Request::Update::Asset' do
|
4
|
+
let(:klass) { JD::Request::Update::Asset }
|
5
|
+
let(:object) { klass.new(client, item, attributes) }
|
6
|
+
let(:item) { JD::Model::Asset.new(client, record) }
|
7
|
+
|
8
|
+
let(:attributes) do
|
9
|
+
{
|
10
|
+
organization_id: organization_id,
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:record) do
|
15
|
+
{
|
16
|
+
'@type' => 'ContributedAsset',
|
17
|
+
'id' => asset_id,
|
18
|
+
'title' => 'Bob',
|
19
|
+
'assetCategory' => 'DEVICE',
|
20
|
+
'assetType' => 'SENSOR',
|
21
|
+
'assetSubType' => 'ENVIRONMENTAL',
|
22
|
+
'lastModifiedDate' => CONFIG.timestamp,
|
23
|
+
'links' => []
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
inherits_from MyJohnDeereApi::Request::Update::Base
|
28
|
+
|
29
|
+
describe '#initialize(client, item, attributes)' do
|
30
|
+
it 'accepts a client, item and attributes' do
|
31
|
+
assert_equal client, object.client
|
32
|
+
assert_equal accessor, object.accessor
|
33
|
+
assert_equal item, object.item
|
34
|
+
assert_equal item.attributes.merge(attributes), object.attributes
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'includes validation' do
|
38
|
+
[:validate!, :valid?].each do |method_name|
|
39
|
+
assert object.respond_to?(method_name)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#resource' do
|
45
|
+
it 'is /assets/<asset_id>' do
|
46
|
+
assert_equal "/assets/#{asset_id}", object.send(:resource)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#headers' do
|
51
|
+
it 'sets the accept and content-type headers' do
|
52
|
+
object = klass.new(client, item, attributes)
|
53
|
+
headers = object.send(:headers)
|
54
|
+
|
55
|
+
expected = 'application/vnd.deere.axiom.v3+json'
|
56
|
+
|
57
|
+
assert_kind_of Hash, headers
|
58
|
+
assert_equal expected, headers['Accept']
|
59
|
+
assert_equal expected, headers['Content-Type']
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#request_body' do
|
64
|
+
it 'properly forms the request body' do
|
65
|
+
body = object.send(:request_body)
|
66
|
+
|
67
|
+
assert_equal item.attributes[:title], body[:title]
|
68
|
+
assert_equal item.attributes[:asset_category], body[:assetCategory]
|
69
|
+
assert_equal item.attributes[:asset_type], body[:assetType]
|
70
|
+
assert_equal item.attributes[:asset_sub_type], body[:assetSubType]
|
71
|
+
|
72
|
+
assert_kind_of Array, body[:links]
|
73
|
+
assert_equal 1, body[:links].size
|
74
|
+
|
75
|
+
assert_kind_of Hash, body[:links].first
|
76
|
+
assert_equal 'Link', body[:links].first['@type']
|
77
|
+
assert_equal 'contributionDefinition', body[:links].first['rel']
|
78
|
+
assert_equal "#{base_url}/contributionDefinitions/#{contribution_definition_id}",
|
79
|
+
body[:links].first['uri']
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'raises an exception when contribution_definition_id is not set' do
|
83
|
+
client.contribution_definition_id = nil
|
84
|
+
object = klass.new(client, item, attributes)
|
85
|
+
|
86
|
+
assert_raises(JD::MissingContributionDefinitionIdError) do
|
87
|
+
object.send(:request_body)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#request' do
|
93
|
+
it 'makes the request' do
|
94
|
+
VCR.use_cassette('put_asset') { object.request }
|
95
|
+
|
96
|
+
assert_kind_of Net::HTTPNoContent, object.response
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class UpdateBaseItem
|
6
|
+
attr_reader :attributes
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@attributes = {
|
10
|
+
name: 'Bob',
|
11
|
+
age: 21
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'MyJohnDeereApi::Request::Update::Base' do
|
17
|
+
let(:klass) { JD::Request::Update::Base }
|
18
|
+
let(:object) { klass.new(client, item, attributes) }
|
19
|
+
let(:item) { UpdateBaseItem.new }
|
20
|
+
let(:attributes) { {} }
|
21
|
+
|
22
|
+
describe '#initialize(client, item, attributes)' do
|
23
|
+
it 'accepts a client, item and attributes' do
|
24
|
+
assert_equal client, object.client
|
25
|
+
assert_equal accessor, object.accessor
|
26
|
+
assert_equal item, object.item
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'when a new attribute (ie, name) is passed in' do
|
30
|
+
let(:attributes) { {name: 'John'} }
|
31
|
+
|
32
|
+
it 'merges name with item attributes' do
|
33
|
+
assert_equal attributes[:name], object.attributes[:name]
|
34
|
+
assert_equal item.attributes[:age], object.attributes[:age]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'when a new attribute (ie, age) is passed in' do
|
39
|
+
let(:attributes) { {age: 99} }
|
40
|
+
|
41
|
+
it 'merges name with item attributes' do
|
42
|
+
assert_equal item.attributes[:name], object.attributes[:name]
|
43
|
+
assert_equal attributes[:age], object.attributes[:age]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#headers' do
|
49
|
+
it 'sets the accept and content-type headers' do
|
50
|
+
object = klass.new(client, item, attributes)
|
51
|
+
headers = object.send(:headers)
|
52
|
+
|
53
|
+
expected = 'application/vnd.deere.axiom.v3+json'
|
54
|
+
|
55
|
+
assert_kind_of Hash, headers
|
56
|
+
assert_equal expected, headers['Accept']
|
57
|
+
assert_equal expected, headers['Content-Type']
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::Request::Update' do
|
4
|
+
describe 'loading dependencies' do
|
5
|
+
it 'loads Request::Update::Base' do
|
6
|
+
assert JD::Request::Update::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'loads Request::Update::Asset' do
|
10
|
+
assert JD::Request::Update::Asset
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::Request' do
|
4
|
+
describe 'loading dependencies' do
|
5
|
+
it 'loads Request::Collection' do
|
6
|
+
assert JD::Request::Collection
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'loads Request::Create' do
|
10
|
+
assert JD::Request::Create
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'loads Request::Individuaal' do
|
14
|
+
assert JD::Request::Individual
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'loads Request::Update' do
|
18
|
+
assert JD::Request::Update
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
class AssetLocationValidatorTest
|
4
|
+
include JD::Validators::AssetLocation
|
5
|
+
|
6
|
+
attr_reader :attributes
|
7
|
+
|
8
|
+
def initialize(attributes)
|
9
|
+
@attributes = attributes
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'MyJohnDeereApi::Validators::AssetLocation' do
|
14
|
+
let(:klass) { AssetLocationValidatorTest }
|
15
|
+
let(:object) { klass.new(attributes) }
|
16
|
+
let(:attributes) { valid_attributes }
|
17
|
+
|
18
|
+
let(:valid_attributes) do
|
19
|
+
{
|
20
|
+
asset_id: asset_id,
|
21
|
+
timestamp: CONFIG.timestamp,
|
22
|
+
coordinates: CONFIG.coordinates,
|
23
|
+
measurement_data: CONFIG.measurement_data
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'exists' do
|
28
|
+
assert JD::Validators::AssetLocation
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'inherits from MyJohnDeereApi::Validators::Base' do
|
32
|
+
[:validate!, :valid?].each{ |method_name| assert object.respond_to?(method_name) }
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'requires several attributes' do
|
36
|
+
[:asset_id, :timestamp, :geometry, :measurement_data].each do |attr|
|
37
|
+
object = klass.new(valid_attributes.merge(attr => nil))
|
38
|
+
|
39
|
+
refute object.valid?
|
40
|
+
exception = assert_raises(JD::InvalidRecordError) { object.validate! }
|
41
|
+
|
42
|
+
assert_includes exception.message, "#{attr} is required"
|
43
|
+
assert_includes object.errors[attr], 'is required'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'requires measurement_data to have the right keys' do
|
48
|
+
[:name, :value, :unit].each do |key|
|
49
|
+
attributes = Marshal.load(Marshal.dump(valid_attributes))
|
50
|
+
attributes[:measurement_data].first.delete(key)
|
51
|
+
|
52
|
+
object = klass.new(attributes)
|
53
|
+
|
54
|
+
refute object.valid?
|
55
|
+
exception = assert_raises(JD::InvalidRecordError) { object.validate! }
|
56
|
+
|
57
|
+
assert_includes exception.message, "measurement_data must include #{key}"
|
58
|
+
assert_includes object.errors[:measurement_data], "must include #{key}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|