myjohndeere 0.0.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/.gitignore +52 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +37 -0
- data/LICENSE +21 -0
- data/README.md +109 -0
- data/Rakefile +8 -0
- data/lib/myjohndeere.rb +132 -0
- data/lib/myjohndeere/access_token.rb +79 -0
- data/lib/myjohndeere/api_support_item.rb +27 -0
- data/lib/myjohndeere/boundary.rb +18 -0
- data/lib/myjohndeere/core_ext/string.rb +9 -0
- data/lib/myjohndeere/errors.rb +10 -0
- data/lib/myjohndeere/field.rb +28 -0
- data/lib/myjohndeere/file_resource.rb +61 -0
- data/lib/myjohndeere/hash_utils.rb +33 -0
- data/lib/myjohndeere/json_attributes.rb +39 -0
- data/lib/myjohndeere/list_object.rb +94 -0
- data/lib/myjohndeere/map_layer.rb +41 -0
- data/lib/myjohndeere/map_layer_summary.rb +40 -0
- data/lib/myjohndeere/map_legend_item.rb +10 -0
- data/lib/myjohndeere/metadata_item.rb +8 -0
- data/lib/myjohndeere/organization.rb +16 -0
- data/lib/myjohndeere/organization_owned_resource.rb +17 -0
- data/lib/myjohndeere/requestable.rb +36 -0
- data/lib/myjohndeere/response.rb +31 -0
- data/lib/myjohndeere/rest_methods.rb +64 -0
- data/lib/myjohndeere/single_resource.rb +13 -0
- data/lib/myjohndeere/util.rb +54 -0
- data/lib/myjohndeere/version.rb +3 -0
- data/myjohndeere.gemspec +23 -0
- data/spec/fixtures.json +778 -0
- data/test/api_fixtures.rb +29 -0
- data/test/test_access_token.rb +60 -0
- data/test/test_boundary.rb +37 -0
- data/test/test_field.rb +47 -0
- data/test/test_file_resource.rb +48 -0
- data/test/test_helper.rb +36 -0
- data/test/test_list_object.rb +74 -0
- data/test/test_map_layer.rb +52 -0
- data/test/test_map_layer_summary.rb +52 -0
- data/test/test_myjohndeere.rb +56 -0
- data/test/test_organization.rb +42 -0
- data/test/test_requestable.rb +15 -0
- data/test/test_rest_methods.rb +34 -0
- data/test/test_util.rb +86 -0
- metadata +118 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
class APIFixtures
|
2
|
+
def initialize
|
3
|
+
@fixtures = ::JSON.parse(File.read("#{PROJECT_ROOT}/spec/fixtures.json"))
|
4
|
+
freeze_recursively(@fixtures)
|
5
|
+
end
|
6
|
+
|
7
|
+
def [](name)
|
8
|
+
@fixtures[name]
|
9
|
+
end
|
10
|
+
|
11
|
+
def fetch(*args)
|
12
|
+
@fixtures.fetch(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate_json(name)
|
16
|
+
JSON.generate(self.fetch(name))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def freeze_recursively(data)
|
22
|
+
data.each do |k, v|
|
23
|
+
if v.is_a?(Hash)
|
24
|
+
freeze_recursively(v)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
data.freeze
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class TestAccessToken < Minitest::Test
|
4
|
+
def test_get_request_token
|
5
|
+
expected_secret = "v8gWA1cxT1Gfx1nkxi01R8xy6uHbMLw/9cMzYTl9bqqTPJWQkRpZr5WmMQA0S4clamix2tGMD5rlfvXis7DxGKcxA6ZIMGXLK1mMOegnM78="
|
6
|
+
expected_token = "12ac3ff0-a13e-4c61-83f4-5cf9bd532341"
|
7
|
+
|
8
|
+
stub_request(:get, "#{MyJohnDeere.configuration.endpoint}/oauth/request_token").
|
9
|
+
to_return(status: 200, body: "oauth_token=#{expected_token}&oauth_token_secret=#{expected_secret}&oauth_callback_confirmed=true")
|
10
|
+
rt = MyJohnDeere::AccessToken.get_request_token()
|
11
|
+
|
12
|
+
assert_equal expected_token, rt.token
|
13
|
+
assert_equal expected_secret, rt.secret
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_initialize_without_exact_options
|
17
|
+
assert_raises ArgumentError do
|
18
|
+
MyJohnDeere::AccessToken.new()
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_initialize_access_token_with_request_token
|
23
|
+
expected_secret = "1Of2eWDVM2x90j1kjxVgxlz091kjmnndsa0912FYwz7ZxlVgPcPmFGb1RtBWLXGVw3k"
|
24
|
+
expected_token = "2f05ab26-1879-4bfe-9129-b9b0144d1610"
|
25
|
+
|
26
|
+
stub_request(:post, "#{MyJohnDeere.configuration.endpoint}/oauth/access_token").
|
27
|
+
to_return(status: 200, body: "oauth_token=#{expected_token}&oauth_token_secret=#{expected_secret}", headers: {})
|
28
|
+
at = MyJohnDeere::AccessToken.new(
|
29
|
+
request_token_token: "12ac3ff0-a13e-4c61-83f4-5cf9bd532341",
|
30
|
+
request_token_secret: "v8gWA1cxT1Gfx1nkxi01R8xy6uHbMLw/9cMzYTl9bqqTPJWQkRpZr5WmMQA0S4clamix2tGMD5rlfvXis7DxGKcxA6ZIMGXLK1mMOegnM78=",
|
31
|
+
verifier_code: "blah"
|
32
|
+
)
|
33
|
+
|
34
|
+
assert_equal expected_token, at.token
|
35
|
+
assert_equal expected_secret, at.secret
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_initialize_access_token_with_access_token_options
|
39
|
+
expected_secret = "1Of2eWDVM2x90j1kjxVgxlz091kjmnndsa0912FYwz7ZxlVgPcPmFGb1RtBWLXGVw3k"
|
40
|
+
expected_token = "2f05ab26-1879-4bfe-9129-b9b0144d1610"
|
41
|
+
|
42
|
+
at = MyJohnDeere::AccessToken.new(
|
43
|
+
oauth_access_token_token: expected_token,
|
44
|
+
oauth_access_token_secret: expected_secret,
|
45
|
+
)
|
46
|
+
assert_equal expected_token, at.token
|
47
|
+
assert_equal expected_secret, at.secret
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_send_get_request
|
51
|
+
at = default_access_token()
|
52
|
+
expected_json = API_FIXTURES.fetch("api_catalog")
|
53
|
+
stub_request(:get, "https://sandboxapi.deere.com/platform/").
|
54
|
+
to_return(status: 200, body: JSON.generate(expected_json), headers: {})
|
55
|
+
|
56
|
+
response = at.execute_request(:get, "/")
|
57
|
+
assert_equal 200, response.http_status
|
58
|
+
assert_equal expected_json.to_json, response.data.to_json
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class TestBoundary < Minitest::Test
|
4
|
+
FIXTURE = API_FIXTURES.fetch("boundary")
|
5
|
+
FIXTURE_FOR_LIST = API_FIXTURES.fetch("boundaries")
|
6
|
+
ORGANIZATION_FIXTURE = API_FIXTURES.fetch("organization")
|
7
|
+
|
8
|
+
def test_retrieve()
|
9
|
+
expected_organization_id = ORGANIZATION_FIXTURE["id"]
|
10
|
+
expected_boundary_id = FIXTURE["id"]
|
11
|
+
stub_request(:get, /\/organizations\/#{expected_organization_id}\/boundaries\/#{expected_boundary_id}/).
|
12
|
+
to_return(status: 200, body: FIXTURE.to_json)
|
13
|
+
|
14
|
+
boundary = MyJohnDeere::Boundary.retrieve(default_access_token,
|
15
|
+
expected_boundary_id, organization_id: expected_organization_id)
|
16
|
+
|
17
|
+
assert_equal expected_boundary_id, boundary.id
|
18
|
+
assert_equal expected_organization_id, boundary.organization_id
|
19
|
+
assert_nil boundary.field_id
|
20
|
+
assert_equal true, boundary.active
|
21
|
+
assert_equal "2/25/2015 6:01:19 PM", boundary.name
|
22
|
+
assert_equal 1, boundary.multipolygons.length
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_list
|
26
|
+
organization_id = "1234"
|
27
|
+
field_id = "6232611a-0303-0234-8g7d-e1e1e11871b8"
|
28
|
+
stub_request(:get, /organizations\/#{organization_id}\/fields\/#{field_id}\/boundaries/).
|
29
|
+
to_return(status: 200, body: FIXTURE_FOR_LIST.to_json)
|
30
|
+
|
31
|
+
boundaries = MyJohnDeere::Boundary.list(default_access_token, count: 1,
|
32
|
+
organization_id: organization_id, field_id: field_id)
|
33
|
+
|
34
|
+
assert_equal 1, boundaries.data.length
|
35
|
+
assert_equal MyJohnDeere::Boundary, boundaries.data[0].class
|
36
|
+
end
|
37
|
+
end
|
data/test/test_field.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class TestField < Minitest::Test
|
4
|
+
FIXTURE = API_FIXTURES.fetch("field")
|
5
|
+
FIXTURE_FOR_LIST = API_FIXTURES.fetch("fields")
|
6
|
+
ORGANIZATION_FIXTURE = API_FIXTURES["organization"]
|
7
|
+
|
8
|
+
def test_retrieve()
|
9
|
+
expected_organization_id = ORGANIZATION_FIXTURE["id"]
|
10
|
+
expected_field_id = FIXTURE["id"]
|
11
|
+
stub_request(:get, /\/organizations\/#{expected_organization_id}\/fields\/#{expected_field_id}/).
|
12
|
+
to_return(status: 200, body: FIXTURE.to_json)
|
13
|
+
|
14
|
+
field = MyJohnDeere::Field.retrieve(default_access_token,
|
15
|
+
expected_field_id, organization_id: expected_organization_id)
|
16
|
+
|
17
|
+
assert_equal expected_field_id, field.id
|
18
|
+
assert_equal expected_organization_id, field.organization_id
|
19
|
+
assert_equal "Nautilus", field.name
|
20
|
+
assert_equal FIXTURE["links"].length, field.links.length
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_retrieve_with_embedded_boudnary
|
24
|
+
fixture = API_FIXTURES["field_with_embedded_boundary"]
|
25
|
+
stub_request(:get, /\/organizations\/#{ORGANIZATION_FIXTURE["id"]}\/fields\/#{fixture["id"]}/).
|
26
|
+
with(query: {embed: "boundaries"}).
|
27
|
+
to_return(status: 200, body: fixture.to_json)
|
28
|
+
|
29
|
+
field = MyJohnDeere::Field.retrieve(default_access_token,
|
30
|
+
fixture["id"], organization_id: ORGANIZATION_FIXTURE["id"],
|
31
|
+
body: {embed: "boundaries"})
|
32
|
+
|
33
|
+
assert field.instance_variable_get(:@boundary)
|
34
|
+
assert_equal fixture["boundaries"][0]["id"], field.boundary.id
|
35
|
+
assert_equal field.id, field.boundary.field_id
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_list()
|
39
|
+
stub_request(:get, /organizations\/#{ORGANIZATION_FIXTURE["id"]}\/fields/).
|
40
|
+
to_return(status: 200, body: FIXTURE_FOR_LIST.to_json)
|
41
|
+
|
42
|
+
fields = MyJohnDeere::Field.list(default_access_token, count: 1, organization_id: ORGANIZATION_FIXTURE["id"])
|
43
|
+
|
44
|
+
assert_equal 1, fields.data.length
|
45
|
+
assert_equal MyJohnDeere::Field, fields.data[0].class
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class TestFileResource < Minitest::Test
|
4
|
+
FIXTURE = API_FIXTURES.fetch("file_resource")
|
5
|
+
FIXTURE_FOR_LIST = API_FIXTURES.fetch("file_resources")
|
6
|
+
FILE_RESOURCE_ID = FIXTURE["id"]
|
7
|
+
ORGANIZATION_ID = "1234"
|
8
|
+
MAP_LAYER_ID = "83ks9gh3-29fj-9302-837j-92jlsk92jd095kd"
|
9
|
+
|
10
|
+
def test_retrieve()
|
11
|
+
stub_request(:get, /\/fileResources\/#{FILE_RESOURCE_ID}/).
|
12
|
+
to_return(status: 200, body: FIXTURE.to_json)
|
13
|
+
|
14
|
+
file_resource = MyJohnDeere::FileResource.retrieve(default_access_token, FILE_RESOURCE_ID)
|
15
|
+
assert_equal FILE_RESOURCE_ID, file_resource.id
|
16
|
+
assert_equal ORGANIZATION_ID, file_resource.organization_id
|
17
|
+
assert_equal "image/png", file_resource.mime_type
|
18
|
+
assert_equal [{"name"=>"The Name", "value"=>"The Value"}], file_resource.metadata
|
19
|
+
assert_equal Time, file_resource.timestamp.class
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_list
|
23
|
+
stub_request(:get, /mapLayers\/#{MAP_LAYER_ID}\/fileResources/).
|
24
|
+
to_return(status: 200, body: FIXTURE_FOR_LIST.to_json)
|
25
|
+
|
26
|
+
file_resources = MyJohnDeere::FileResource.list(default_access_token, count: 1,
|
27
|
+
map_layer_id: MAP_LAYER_ID)
|
28
|
+
|
29
|
+
assert_equal 1, file_resources.data.length
|
30
|
+
assert_equal MyJohnDeere::FileResource, file_resources.data[0].class
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_create
|
34
|
+
expected_body = "{\"links\":[{\"rel\":\"owningOrganization\",\"uri\":\"https://sandboxapi.deere.com/platform/organizations/1234\"}],\"mimeType\":\"application/zip\",\"metadata\":[{\"key\":\"key\",\"value\":\"value\"}]}"
|
35
|
+
stub_request(:post, /mapLayers\/#{MAP_LAYER_ID}\/fileResources/).
|
36
|
+
with(body: expected_body,
|
37
|
+
headers: {'Accept'=>'application/vnd.deere.axiom.v3+json', 'Content-Length'=>expected_body.length, 'Content-Type'=>'application/vnd.deere.axiom.v3+json'}).
|
38
|
+
to_return(status: 201, headers: {"Location"=>"https://sandboxapi.deere.com/platform/fileResources/#{MAP_LAYER_ID}"})
|
39
|
+
response = MyJohnDeere::FileResource.create(default_access_token,
|
40
|
+
ORGANIZATION_ID,
|
41
|
+
MAP_LAYER_ID,
|
42
|
+
file_type: :zip,
|
43
|
+
metadata: [MyJohnDeere::MetadataItem.new("key", "value")]
|
44
|
+
)
|
45
|
+
assert_equal MAP_LAYER_ID, response.id
|
46
|
+
assert_equal ORGANIZATION_ID, response.organization_id
|
47
|
+
end
|
48
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'myjohndeere'
|
3
|
+
require 'byebug'
|
4
|
+
require 'webmock/minitest'
|
5
|
+
|
6
|
+
PROJECT_ROOT = File.expand_path("../../", __FILE__)
|
7
|
+
require File.expand_path('../api_fixtures', __FILE__)
|
8
|
+
|
9
|
+
class Minitest::Test
|
10
|
+
# Fixtures are available in tests using something like:
|
11
|
+
#
|
12
|
+
# API_FIXTURES[:fields][:id]
|
13
|
+
#
|
14
|
+
API_FIXTURES = APIFixtures.new
|
15
|
+
|
16
|
+
def setup
|
17
|
+
MyJohnDeere.configure do |config|
|
18
|
+
config.app_id = "Dontcare"
|
19
|
+
config.shared_secret = "somesecret"
|
20
|
+
config.environment = :sandbox
|
21
|
+
config.contribution_definition_id = "foobar"
|
22
|
+
#config.log_level = :info
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown
|
27
|
+
WebMock.reset!
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_access_token
|
31
|
+
MyJohnDeere::AccessToken.new(
|
32
|
+
oauth_access_token_token: "1Of2eWDVM2x90j1kjxVgxlz091kjmnndsa0912FYwz7ZxlVgPcPmFGb1RtBWLXGVw3k",
|
33
|
+
oauth_access_token_secret: "2f05ab26-1879-4bfe-9129-b9b0144d1610",
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class TestListObject < Minitest::Test
|
4
|
+
def test_each_loop
|
5
|
+
data = Array.new(3, API_FIXTURES["organization"])
|
6
|
+
list = MyJohnDeere::ListObject.new(MyJohnDeere::Organization,
|
7
|
+
default_access_token,
|
8
|
+
{"values" => data})
|
9
|
+
|
10
|
+
list.each_with_index do |x, i|
|
11
|
+
assert_equal data[i]["id"], x.id
|
12
|
+
end
|
13
|
+
|
14
|
+
assert_equal data.length, list.total
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_has_more
|
18
|
+
expected_total = 3
|
19
|
+
list = MyJohnDeere::ListObject.new(MyJohnDeere::Organization,
|
20
|
+
default_access_token, {
|
21
|
+
"total" => expected_total,
|
22
|
+
"values" => Array.new(1, API_FIXTURES["organization"])
|
23
|
+
}, options: {start: 0})
|
24
|
+
assert list.has_more?
|
25
|
+
|
26
|
+
list.start = expected_total
|
27
|
+
assert !list.has_more?
|
28
|
+
|
29
|
+
list = MyJohnDeere::ListObject.new(MyJohnDeere::Organization,
|
30
|
+
default_access_token, {"values" =>[]}, options: {start: 0})
|
31
|
+
assert !list.has_more?, "The data is equal to the total"
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_get_next_page_with_etag
|
35
|
+
# etag behavior gets the entire list.
|
36
|
+
test_json = API_FIXTURES["organizations"]
|
37
|
+
existing_data = Array.new(test_json["total"]-1, test_json["values"][0])
|
38
|
+
list = MyJohnDeere::ListObject.new(MyJohnDeere::Organization, default_access_token,
|
39
|
+
{"values" => existing_data}, options: {
|
40
|
+
start: 0, count: existing_data.length, etag: ""})
|
41
|
+
assert list.using_etag?
|
42
|
+
assert !list.has_more?
|
43
|
+
assert_equal list.data.length, list.data.length
|
44
|
+
assert_equal 0, list.start
|
45
|
+
|
46
|
+
# Validate that the etag header is getting propagated to the next request
|
47
|
+
list.next_page!()
|
48
|
+
|
49
|
+
assert_equal list.data.length, list.data.length, "shouldn't have changed"
|
50
|
+
assert_equal 0, list.start, "shouldn't have changed"
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_get_next_page
|
54
|
+
test_json = API_FIXTURES["organizations"]
|
55
|
+
existing_data = (1..(test_json["total"]-1)).to_a
|
56
|
+
list = MyJohnDeere::ListObject.new(MyJohnDeere::Organization, default_access_token,
|
57
|
+
test_json, options: {start: 0,
|
58
|
+
count: existing_data.length})
|
59
|
+
assert list.has_more?
|
60
|
+
assert !list.using_etag?
|
61
|
+
|
62
|
+
# Validate that the etag header is getting propagated to the next request
|
63
|
+
stub_request(:get, /organizations;start=#{existing_data.count};count=#{existing_data.count}/).
|
64
|
+
with(headers: {'Accept'=>'application/vnd.deere.axiom.v3+json'}).
|
65
|
+
to_return(status: 200, body: test_json.to_json())
|
66
|
+
|
67
|
+
list.next_page!()
|
68
|
+
|
69
|
+
assert_equal 1, list.data.length
|
70
|
+
assert_equal existing_data.length, list.start
|
71
|
+
assert_equal test_json["values"].first["id"], list.data.first.id
|
72
|
+
assert !list.has_more?()
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class TestMapLayer < Minitest::Test
|
4
|
+
FIXTURE = API_FIXTURES.fetch("map_layer")
|
5
|
+
FIXTURE_FOR_LIST = API_FIXTURES.fetch("map_layers")
|
6
|
+
ORGANIZATION_ID = "1234"
|
7
|
+
MAP_LAYER_ID = "83ks9gh3-29fj-9302-837j-92jlsk92jd095kd"
|
8
|
+
MLS_ID = "2516aa2c-1c0d-4dae-ba63-5c44ff172a01"
|
9
|
+
FIELD_ID = "2516aa2c-2c0d-4dae-ba63-5c44ff172a01"
|
10
|
+
|
11
|
+
def test_retrieve()
|
12
|
+
stub_request(:get, /\/mapLayers\/#{FIXTURE["id"]}/).
|
13
|
+
to_return(status: 200, body: FIXTURE.to_json)
|
14
|
+
|
15
|
+
ml = MyJohnDeere::MapLayer.retrieve(default_access_token, FIXTURE["id"])
|
16
|
+
assert_equal MAP_LAYER_ID, ml.id
|
17
|
+
assert_equal ORGANIZATION_ID, ml.organization_id
|
18
|
+
assert_equal "The title on the map layer", ml.title
|
19
|
+
assert_equal 4, ml.extent.length
|
20
|
+
assert_equal "seeds1ha-1", ml.legends["unitId"]
|
21
|
+
assert_equal 1, ml.legends["ranges"].length
|
22
|
+
assert_equal MyJohnDeere::MapLegendItem, ml.legends["ranges"][0].class, "Should be a map legend item"
|
23
|
+
assert_equal({:label=>"Some Label", :minimum=>87300, :maximum=>87300, :hexColor=>"#0BA74A", :percent=>0.13},
|
24
|
+
ml.legends["ranges"][0].to_hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_list
|
28
|
+
stub_request(:get, /mapLayerSummaries\/#{MLS_ID}\/mapLayers/).
|
29
|
+
to_return(status: 200, body: FIXTURE_FOR_LIST.to_json)
|
30
|
+
|
31
|
+
map_layers = MyJohnDeere::MapLayer.list(default_access_token, count: 1,
|
32
|
+
map_layer_summary_id: MLS_ID)
|
33
|
+
|
34
|
+
assert_equal 1, map_layers.data.length
|
35
|
+
assert_equal MyJohnDeere::MapLayer, map_layers.data[0].class
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_create
|
39
|
+
expected_body = "{\"links\":[{\"rel\":\"owningOrganization\",\"uri\":\"https://sandboxapi.deere.com/platform/organizations/1234\"}],\"title\":\"The title on the map layer\",\"extent\":{\"minimumLatitude\":0,\"maximumLatitude\":1,\"minimumLongitude\":0,\"maximumLongitude\":1},\"legends\":{\"unitId\":\"foo\",\"ranges\":[{\"label\":\"bar\",\"minimum\":1,\"maximum\":2,\"hexColor\":\"#0BA74A\",\"percent\":15.0}]}}"
|
40
|
+
stub_request(:post, /mapLayerSummaries\/#{MLS_ID}\/mapLayers/).
|
41
|
+
with(body: expected_body,
|
42
|
+
headers: {'Accept'=>'application/vnd.deere.axiom.v3+json', 'Content-Length'=>expected_body.length, 'Content-Type'=>'application/vnd.deere.axiom.v3+json'}).
|
43
|
+
to_return(status: 201, headers: {"Location"=>"https://sandboxapi.deere.com/platform/mapLayers/#{MAP_LAYER_ID}"})
|
44
|
+
response = MyJohnDeere::MapLayer.create(default_access_token,
|
45
|
+
MLS_ID,
|
46
|
+
ORGANIZATION_ID,
|
47
|
+
minimum_latitude: 0, minimum_longitude: 0, maximum_latitude: 1, maximum_longitude: 1,
|
48
|
+
map_layer_id: "foo", map_legend_items: [MyJohnDeere::MapLegendItem.new("bar", 1, 2, "#0BA74A", 15.0)]
|
49
|
+
)
|
50
|
+
assert_equal MAP_LAYER_ID, response
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class TestMapLayerSummary < Minitest::Test
|
4
|
+
FIXTURE = API_FIXTURES.fetch("map_layer_summary")
|
5
|
+
FIXTURE_FOR_LIST = API_FIXTURES.fetch("map_layer_summaries")
|
6
|
+
ORGANIZATION_ID = "1234"
|
7
|
+
MLS_ID = "2516aa2c-1c0d-4dae-ba63-5c44ff172a01"
|
8
|
+
FIELD_ID = "2516aa2c-2c0d-4dae-ba63-5c44ff172a01"
|
9
|
+
|
10
|
+
def test_retrieve()
|
11
|
+
stub_request(:get, /\/mapLayerSummaries\/#{FIXTURE["id"]}/).
|
12
|
+
to_return(status: 200, body: FIXTURE.to_json)
|
13
|
+
|
14
|
+
mls = MyJohnDeere::MapLayerSummary.retrieve(default_access_token, FIXTURE["id"])
|
15
|
+
assert_equal MLS_ID, mls.id
|
16
|
+
assert_equal ORGANIZATION_ID, mls.organization_id
|
17
|
+
assert_equal "some title", mls.title
|
18
|
+
assert_equal "description of the map layers", mls.text
|
19
|
+
assert_equal [{"name"=>"The Name", "value"=>"The Value"}], mls.metadata
|
20
|
+
assert_equal Time, mls.date_created.class
|
21
|
+
assert_equal Time, mls.last_modified_date.class
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_list
|
25
|
+
stub_request(:get, /organizations\/#{ORGANIZATION_ID}\/fields\/#{FIELD_ID}\/mapLayerSummaries/).
|
26
|
+
to_return(status: 200, body: FIXTURE_FOR_LIST.to_json)
|
27
|
+
|
28
|
+
mlss = MyJohnDeere::MapLayerSummary.list(default_access_token, count: 1,
|
29
|
+
organization_id: ORGANIZATION_ID, field_id: FIELD_ID)
|
30
|
+
|
31
|
+
assert_equal 1, mlss.data.length
|
32
|
+
assert_equal MyJohnDeere::MapLayerSummary, mlss.data[0].class
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_create
|
36
|
+
expected_body = "{\"title\":\"Test number 2\",\"text\":\"Hello from farm lens again\",\"links\":[{\"rel\":\"owningOrganization\",\"uri\":\"https://sandboxapi.deere.com/platform/organizations/1234\"},{\"rel\":\"contributionDefinition\",\"uri\":\"https://sandboxapi.deere.com/platform/foobar\"}],\"metadata\":[{\"key\":\"key\",\"value\":\"val\"}],\"dateCreated\":\"2016-01-02T16:14:23.421Z\"}"
|
37
|
+
stub_request(:post, /\/organizations\/#{ORGANIZATION_ID}\/fields\/#{FIELD_ID}\/mapLayerSummaries/).
|
38
|
+
with(body: expected_body,
|
39
|
+
headers: {'Accept'=>'application/vnd.deere.axiom.v3+json', 'Content-Length'=>expected_body.length, 'Content-Type'=>'application/vnd.deere.axiom.v3+json'}).
|
40
|
+
to_return(status: 201, headers: {"Location"=>"https://sandboxapi.deere.com/platform/mapLayerSummaries/#{MLS_ID}"})
|
41
|
+
response = MyJohnDeere::MapLayerSummary.create(default_access_token,
|
42
|
+
ORGANIZATION_ID,
|
43
|
+
FIELD_ID,
|
44
|
+
"Test number 2",
|
45
|
+
"Hello from farm lens again",
|
46
|
+
[MyJohnDeere::MetadataItem.new("key", "val")],
|
47
|
+
Time.parse("2016-01-02T16:14:23.421Z")
|
48
|
+
)
|
49
|
+
assert_equal MLS_ID, response.id
|
50
|
+
assert_equal ORGANIZATION_ID, response.organization_id
|
51
|
+
end
|
52
|
+
end
|