lws 8.1.0 → 9.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,205 +0,0 @@
1
- #
2
- # Copyright © 2016–2021 LeftClick Web Services B.V.
3
- #
4
- # This software is property of LeftClick Web Services B.V. and cannot be
5
- # redistributed and/or modified without permission. The software or any
6
- # of its parts cannot be used for any other purposes than the LeftClick
7
- # services and only during a valid license subscription. For more
8
- # information, please contact LeftClick Web Services B.V. at:
9
- # Schootense Dreef 20A, 5708 HZ Helmond, The Netherlands,
10
- # info@leftclick.eu, +3185-4444-004.
11
-
12
-
13
- require "test_helper"
14
-
15
- class TestPresenceAppointment < MiniTest::Test
16
-
17
- include LWS::Presence
18
-
19
- def setup
20
- @location = Location.where(includes: "appointments.*").find(1)
21
- @appointment = @location.appointments.first
22
- end
23
-
24
- def test_valid
25
- refute_nil(@appointment)
26
- assert_instance_of(Appointment, @appointment)
27
- refute_nil(@appointment.id)
28
- end
29
-
30
- def test_valid_associations
31
- assert_instance_of(Location, @appointment.location)
32
- assert_equal(@location, @appointment.location)
33
- assert_instance_of(Person, @appointment.organiser)
34
- assert_instance_of(Person, @appointment.people.first)
35
- end
36
-
37
- end
38
-
39
- class TestPresenceJournal < MiniTest::Test
40
- include LWS::Presence
41
-
42
- def setup
43
- @location = Location.find(1)
44
- # Journals only exist as child objects of a location
45
- @journal = @location.journals.first
46
- end
47
-
48
- def test_valid
49
- refute_nil(@journal)
50
- assert_instance_of(Journal, @journal)
51
- refute_nil(@journal.id)
52
- end
53
-
54
- def test_valid_associations
55
- assert_instance_of(LWS::Auth::Company, @journal.company)
56
- assert_instance_of(Location, @journal.location)
57
- assert_equal(@location, @journal.location)
58
- assert_instance_of(Person, @journal.person)
59
- end
60
- end
61
-
62
- class TestPresenceLocation < MiniTest::Test
63
-
64
- include LWS::Presence
65
-
66
- def setup
67
- @location = Location.where(includes: "appointments.*").find(1)
68
- end
69
-
70
- def test_valid
71
- refute_nil(@location)
72
- assert_instance_of(Location, @location)
73
- refute_nil(@location.id)
74
- end
75
-
76
- def test_valid_associations
77
- assert_instance_of(Appointment, @location.appointments.first)
78
- assert_instance_of(LWS::Auth::Company, @location.company)
79
- assert_instance_of(Location::Map::Position, @location.map_positions.first)
80
- assert_instance_of(Location::Map, @location.maps.first)
81
- assert_instance_of(Person, @location.owner)
82
- assert_instance_of(Person, @location.people.first)
83
- assert_instance_of(Reader, @location.readers.first)
84
- loc = Location.where(includes: "people_tree").find(1)
85
- assert_instance_of(Person, loc.people_tree.first)
86
-
87
- child_loc = Location.where(parent_id: 1).first
88
- assert_instance_of(Location, child_loc)
89
- assert_instance_of(Location, child_loc.parent)
90
- assert_instance_of(Location, child_loc.checkout_location)
91
- end
92
-
93
- end
94
-
95
- class TestPresenceLocationMap < MiniTest::Test
96
-
97
- include LWS::Presence
98
-
99
- def setup
100
- @location = Location.find(1)
101
- # Location maps only exist as child objects of a location
102
- @map = @location.maps.first
103
- end
104
-
105
- def test_valid
106
- refute_nil(@map)
107
- assert_instance_of(Location::Map, @map)
108
- refute_nil(@map.id)
109
- end
110
-
111
- def test_valid_associations
112
- assert_instance_of(Location, @map.location)
113
- assert_equal(@location, @map.location)
114
- assert_instance_of(Location::Map::Position, @map.positions.first)
115
- end
116
-
117
- end
118
-
119
- class TestPresenceLocationMapPosition < MiniTest::Test
120
-
121
- include LWS::Presence
122
-
123
- def setup
124
- @location = Location.find(1)
125
- # Location maps only exist as child objects of a location
126
- @map = @location.maps.first
127
- # Location map position only exist as child objects of a location map
128
- @position = @map.positions.first
129
- end
130
-
131
- def test_valid
132
- refute_nil(@position)
133
- assert_instance_of(Location::Map::Position, @position)
134
- refute_nil(@position.id)
135
- end
136
-
137
- def test_valid_associations
138
- # FIXME: Chained associations don't work yet in Spyke (#89)
139
- #assert_instance_of(Location::Map, @position.location_map)
140
- #assert_equal(@map, @position.location_map)
141
- assert_instance_of(Location, @position.tracking_location)
142
- end
143
-
144
- end
145
-
146
- class TestPresenceNotification < MiniTest::Test
147
-
148
- include LWS::Presence
149
-
150
- def setup
151
- @notification = Notification.create(location_id: 1,
152
- receiver_id: 1,
153
- sender_id: 1)
154
- end
155
-
156
- def test_valid
157
- refute_nil(@notification)
158
- end
159
-
160
- end
161
-
162
- class TestPresencePerson < MiniTest::Test
163
-
164
- include LWS::Presence
165
-
166
- def setup
167
- @person = Person.where(includes: "appointments.*").find(1)
168
- end
169
-
170
- def test_valid
171
- refute_nil(@person)
172
- assert_instance_of(Person, @person)
173
- refute_nil(@person.id)
174
- end
175
-
176
- def test_valid_associations
177
- assert_instance_of(Appointment, @person.appointments.first)
178
- assert_instance_of(LWS::Auth::Company, @person.company)
179
- assert_instance_of(Location, @person.location)
180
- # FIXME: The list of people responsible for is not included in the serializer.
181
- #assert_instance_of(Person, @person.people_responsible_for.first)
182
- assert_instance_of(Person, @person.person_responsible)
183
- end
184
-
185
- end
186
-
187
- class TestPresenceReader < MiniTest::Test
188
-
189
- include LWS::Presence
190
-
191
- def setup
192
- @reader = Reader.find(1)
193
- end
194
-
195
- def test_valid
196
- refute_nil(@reader)
197
- assert_instance_of(Reader, @reader)
198
- refute_nil(@reader.id)
199
- end
200
-
201
- def test_valid_associations
202
- assert_instance_of(Location, @reader.location)
203
- end
204
-
205
- end
@@ -1,91 +0,0 @@
1
- #
2
- # Copyright © 2016–2021 LeftClick Web Services B.V.
3
- #
4
- # This software is property of LeftClick Web Services B.V. and cannot be
5
- # redistributed and/or modified without permission. The software or any
6
- # of its parts cannot be used for any other purposes than the LeftClick
7
- # services and only during a valid license subscription. For more
8
- # information, please contact LeftClick Web Services B.V. at:
9
- # Schootense Dreef 20A, 5708 HZ Helmond, The Netherlands,
10
- # info@leftclick.eu, +3185-4444-004.
11
-
12
-
13
- require "test_helper"
14
-
15
- # FIXME: Cannot reach the following classes yet:
16
- # * Collection::Feed
17
- # * Collection::Feed::Post
18
- # * Collection::Image
19
- # * Collection::Post
20
- # * Collection::Video
21
- # * Collection::WeatherLocation
22
- # * Collection::WeatherLocation::Forecast
23
-
24
- class TestResourceCollection < MiniTest::Test
25
-
26
- include LWS::Resource
27
-
28
- def setup
29
- @collection = Collection.find(1)
30
- end
31
-
32
- def test_valid
33
- refute_nil(@collection)
34
- assert_instance_of(Collection, @collection)
35
- refute_nil(@collection.id)
36
- end
37
-
38
- def test_valid_associations
39
- assert_instance_of(LWS::Auth::Account, @collection.account)
40
- assert_instance_of(LWS::Auth::Company, @collection.company)
41
- assert_instance_of(Folder, @collection.folder)
42
- # FIXME: Test the collection item relations based on @collection.kind
43
- end
44
-
45
- end
46
-
47
- class TestResourceCollectionItem < MiniTest::Test
48
-
49
- include LWS::Resource
50
-
51
- def setup
52
- @collection = Collection.where(includes: "items").find(1)
53
- @collection_item = @collection.items.first
54
- end
55
-
56
- def test_valid
57
- refute_nil(@collection_item)
58
- assert_instance_of(Collection::Item, @collection_item)
59
- refute_nil(@collection_item.id)
60
- end
61
-
62
- def test_valid_associations
63
- assert_instance_of(Collection, @collection_item.collection)
64
- assert_equal(@collection, @collection_item.collection)
65
- end
66
-
67
- end
68
-
69
- class TestResourceFolder < MiniTest::Test
70
-
71
- include LWS::Resource
72
-
73
- def setup
74
- @folder = Folder.find(1)
75
- end
76
-
77
- def test_valid
78
- refute_nil(@folder)
79
- assert_instance_of(Folder, @folder)
80
- refute_nil(@folder.id)
81
- end
82
-
83
- def test_valid_associations
84
- assert_instance_of(LWS::Auth::Account, @folder.account)
85
- assert_instance_of(Collection, @folder.collections.first)
86
- assert_instance_of(LWS::Auth::Company, @folder.company)
87
- # FIXME: Not available as data yet
88
- #assert_instance_of(Folder, @folder.folders.first)
89
- end
90
-
91
- end
data/test/setup_test.rb DELETED
@@ -1,177 +0,0 @@
1
- #
2
- # Copyright © 2016–2021 LeftClick Web Services B.V.
3
- #
4
- # This software is property of LeftClick Web Services B.V. and cannot be
5
- # redistributed and/or modified without permission. The software or any
6
- # of its parts cannot be used for any other purposes than the LeftClick
7
- # services and only during a valid license subscription. For more
8
- # information, please contact LeftClick Web Services B.V. at:
9
- # Schootense Dreef 20A, 5708 HZ Helmond, The Netherlands,
10
- # info@leftclick.eu, +3185-4444-004.
11
-
12
- require "test_helper"
13
-
14
- class TestSetup < MiniTest::Test
15
-
16
- def setup
17
- @test_config_dir = File.expand_path("../config", __FILE__)
18
- end
19
-
20
- def teardown
21
- # Restore the configuration
22
- reconfigure
23
- end
24
-
25
- def test_cannot_leave_out_api_token
26
- assert_raises do
27
- LWS.setup {}
28
- end
29
- end
30
-
31
- def test_get_environment_from_environment
32
- with_env("LC_LWS_ENV" => "production") do
33
- reconfigure
34
- end
35
- assert_equal(:production, LWS.config.environment)
36
-
37
- with_env("LC_LWS_ENV" => "production") do
38
- LWS.setup do |config|
39
- config.api_token = ENV["LC_LWS_TEST_TOKEN"]
40
- end
41
- end
42
- assert_equal(:production, LWS.config.environment)
43
-
44
- with_env("LC_LWS_API_TOKEN" => "test-token") do
45
- reconfigure
46
- end
47
- assert_equal("test-token", LWS.config.api_token)
48
- end
49
-
50
- def test_environment_writer
51
- LWS.config.environment = "prod"
52
- assert_equal(:production, LWS.config.environment)
53
- LWS.config.environment = "production"
54
- assert_equal(:production, LWS.config.environment)
55
- LWS.config.environment = :production
56
- assert_equal(:production, LWS.config.environment)
57
-
58
- LWS.config.environment = "dev"
59
- assert_equal(:development, LWS.config.environment)
60
- LWS.config.environment = "development"
61
- assert_equal(:development, LWS.config.environment)
62
- LWS.config.environment = :development
63
- assert_equal(:development, LWS.config.environment)
64
-
65
- assert_raises do
66
- LWS.config.environment = "doesnotexist"
67
- end
68
- end
69
-
70
- def test_http_logging_without_logger
71
- reconfigure(logger: nil,
72
- http_debug: true,
73
- http_debug_headers: true,
74
- json_debug: false)
75
-
76
- assert_raises LWS::Errors::ConfigError do
77
- LWS::Auth::Token.find(0)
78
- end
79
- end
80
-
81
- def test_json_logging_without_logger
82
- reconfigure(logger: nil,
83
- http_debug: false,
84
- http_debug_headers: false,
85
- json_debug: true)
86
-
87
- assert_raises LWS::Errors::ConfigError do
88
- LWS::Auth::Token.find(0)
89
- end
90
- end
91
-
92
- def test_load_config_files
93
- orig_config = LWS.config.dup
94
- reconfigure do |config|
95
- assert config.load_config_file(File.join(@test_config_dir, "empty.yml"))
96
- end
97
- assert_equal(orig_config, LWS.config)
98
-
99
- reconfigure do |config|
100
- refute config.load_config_file(File.join(@test_config_dir, "does_not_exist.yml"))
101
- end
102
-
103
- reconfigure do |config|
104
- config.api_token = nil
105
- assert config.load_config_file(File.join(@test_config_dir, "tokens.yml"))
106
- end
107
- assert_equal("dev-token", LWS.config.api_token)
108
-
109
- reconfigure do |config|
110
- assert config.load_config_file(File.join(@test_config_dir, "switch_env.yml"))
111
- end
112
- assert_equal(:production, LWS.config.environment)
113
-
114
- reconfigure do |config|
115
- assert config.load_config_file(File.join(@test_config_dir, "endpoints.yml"))
116
- end
117
- assert_equal({ maps: "http://maps.leftclick.cloud" }, LWS.config.endpoints)
118
-
119
- assert_raises do
120
- reconfigure do |config|
121
- assert config.load_config_file(File.join(@test_config_dir, "invalid.yml"))
122
- end
123
- end
124
-
125
- reconfigure do |config|
126
- config.api_token = nil
127
- assert config.load_config_file(File.join(@test_config_dir, "full.yml"))
128
- end
129
- assert_equal("dev-token", LWS.config.api_token)
130
- assert_equal({ maps: "http://maps.leftclick.cloud" }, LWS.config.endpoints)
131
- assert_equal(:development, LWS.config.environment)
132
- assert_equal(true, LWS.config.http_debug)
133
- assert_equal(true, LWS.config.http_debug_headers)
134
- assert_equal(true, LWS.config.json_debug)
135
- assert_equal("http://user:password@proxyserver:8080", LWS.config.proxy)
136
-
137
- with_env("LC_LWS_ENV" => "production") do
138
- reconfigure do |config|
139
- assert config.load_config_file(File.join(@test_config_dir, "empty.yml"),
140
- :development)
141
- end
142
- assert_equal(:development, LWS.config.environment)
143
- end
144
-
145
- reconfigure do |config|
146
- assert config.load_config_file(File.join(@test_config_dir, "switch_env.yml"),
147
- :development)
148
- end
149
- assert_equal(:development, LWS.config.environment)
150
- end
151
-
152
- def test_proxy
153
- proxy_url = "http://user:password@proxyserver:8080"
154
- reconfigure do |config|
155
- config.proxy = proxy_url
156
- end
157
-
158
- assert_equal(proxy_url, LWS.config.proxy)
159
- assert_equal("http://user:password@proxyserver:8080", LWS::Auth.api.proxy.uri.to_s)
160
- assert_equal("user", LWS::Auth.api.proxy.user)
161
- assert_equal("password", LWS::Auth.api.proxy.password)
162
-
163
- proxy_options =
164
- { uri: Addressable::URI.parse("http://proxyserver:8080"),
165
- user: "user",
166
- password: "password" }
167
- reconfigure do |config|
168
- config.proxy = proxy_options
169
- end
170
-
171
- assert_equal(proxy_options, LWS.config.proxy)
172
- assert_equal("http://proxyserver:8080", LWS::Auth.api.proxy.uri.to_s)
173
- assert_equal("user", LWS::Auth.api.proxy.user)
174
- assert_equal("password", LWS::Auth.api.proxy.password)
175
- end
176
-
177
- end
@@ -1,74 +0,0 @@
1
- #
2
- # Copyright © 2016–2021 LeftClick Web Services B.V.
3
- #
4
- # This software is property of LeftClick Web Services B.V. and cannot be
5
- # redistributed and/or modified without permission. The software or any
6
- # of its parts cannot be used for any other purposes than the LeftClick
7
- # services and only during a valid license subscription. For more
8
- # information, please contact LeftClick Web Services B.V. at:
9
- # Schootense Dreef 20A, 5708 HZ Helmond, The Netherlands,
10
- # info@leftclick.eu, +3185-4444-004.
11
-
12
-
13
- require "test_helper"
14
-
15
- class TestStubbing < MiniTest::Test
16
-
17
- def setup
18
- # Redo LWS setup with stubbing enabled and persistent HTTP connections
19
- # disabled.
20
- reconfigure(http_persistent: false,
21
- stubbing: File.expand_path("../fixtures", __FILE__))
22
- end
23
-
24
- def teardown
25
- reconfigure
26
- end
27
-
28
- def test_not_working_stubbing
29
- assert_raises LWS::Errors::ConfigError do
30
- reconfigure(stubbing: "/fixtures/doesnotexist")
31
- end
32
- end
33
-
34
- def test_working_stubbing
35
- assert_raises WebMock::NetConnectNotAllowedError do
36
- LWS::Auth::Token.find("not_stubbed")
37
- end
38
- assert LWS.stubbing
39
- assert LWS::Auth::Token.find("test")
40
- end
41
-
42
- def test_working_stubbing_with_status
43
- LWS.stubbing.replace(:get, :auth, "/tokens/does_not_exist", :default, 404)
44
- assert_raises LWS::Errors::ResourceNotFound do
45
- LWS::Auth::Token.find("does_not_exist")
46
- end
47
- end
48
-
49
- def test_replace_stub
50
- assert LWS.stubbing.replace(:get, :auth, "/accounts/1/apps", :generic)
51
- assert LWS.stubbing.replace(:get, :auth, "/tokens/1", nil)
52
- end
53
-
54
- def test_failed_replace_stub
55
- assert_raises LWS::Errors::StubError do
56
- LWS.stubbing.replace(:get, :auth, "/some/nonexisting/path", :not_here)
57
- end
58
- end
59
-
60
- def test_remove_stub
61
- stub = LWS.stubbing.remove(:get, :auth, "/accounts/1/devices/1")
62
- assert_nil stub
63
- assert_raises LWS::Errors::StubError do
64
- LWS.stubbing.remove(:get, :auth, "/accounts/1/devices/1")
65
- end
66
- end
67
-
68
- def test_failed_remove_stub
69
- assert_raises LWS::Errors::StubError do
70
- LWS.stubbing.remove(:get, :auth, "/some/nonexisting/path")
71
- end
72
- end
73
-
74
- end
@@ -1,25 +0,0 @@
1
- #
2
- # Copyright © 2016–2021 LeftClick Web Services B.V.
3
- #
4
- # This software is property of LeftClick Web Services B.V. and cannot be
5
- # redistributed and/or modified without permission. The software or any
6
- # of its parts cannot be used for any other purposes than the LeftClick
7
- # services and only during a valid license subscription. For more
8
- # information, please contact LeftClick Web Services B.V. at:
9
- # Schootense Dreef 20A, 5708 HZ Helmond, The Netherlands,
10
- # info@leftclick.eu, +3185-4444-004.
11
-
12
-
13
- class Minitest::Test
14
-
15
- def with_env(settings)
16
- old_env = {}
17
- settings.each { |k, v| old_env[k], ENV[k] = ENV[k], v }
18
- begin
19
- yield
20
- ensure
21
- settings.each { |k, v| ENV[k] = old_env[k] }
22
- end
23
- end
24
-
25
- end
data/test/test_helper.rb DELETED
@@ -1,77 +0,0 @@
1
- #
2
- # Copyright © 2016–2021 LeftClick Web Services B.V.
3
- #
4
- # This software is property of LeftClick Web Services B.V. and cannot be
5
- # redistributed and/or modified without permission. The software or any
6
- # of its parts cannot be used for any other purposes than the LeftClick
7
- # services and only during a valid license subscription. For more
8
- # information, please contact LeftClick Web Services B.V. at:
9
- # Schootense Dreef 20A, 5708 HZ Helmond, The Netherlands,
10
- # info@leftclick.eu, +3185-4444-004.
11
-
12
-
13
- require 'simplecov'
14
- require 'simplecov-rcov'
15
- SimpleCov.formatters = [
16
- SimpleCov::Formatter::HTMLFormatter,
17
- SimpleCov::Formatter::RcovFormatter
18
- ]
19
- SimpleCov.start do
20
- add_filter "/test/"
21
- end
22
- SimpleCov.at_exit do
23
- result = SimpleCov.result
24
- result.format!
25
- simplecov_test_suites = ['minitest']
26
- parallel_offset = ENV['PARALLEL_TEST_GROUPS'] ? ENV['PARALLEL_TEST_GROUPS'].to_i - 1 : 0
27
- minimum_coverage = 95
28
- # Count the number of commas in the command name to figure out how many result groups were combined into this result
29
- if result.command_name.scan(/,/).size + 1 >= simplecov_test_suites.size + (parallel_offset * 2) # two parallel suites
30
- # We only want to enforce minimum coverage after all test suites finish
31
- if result.covered_percent < minimum_coverage
32
- puts "Coverage percentage has dropped below the minimum threshold of #{minimum_coverage}%"
33
- exit(1)
34
- end
35
- end
36
- end
37
-
38
- require "logger"
39
- require "lws"
40
- require "minitest/autorun"
41
- require "minitest/reporters"
42
-
43
- # Select the Minitest reporter
44
- Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
45
-
46
- # Load the support libraries
47
- Dir[File.expand_path("../support/**.rb", __FILE__)].each { |f| require f }
48
-
49
- raise "Test token not set" if ENV["LC_LWS_TEST_TOKEN"].blank?
50
-
51
- def reconfigure(options = {}, &block)
52
- LWS.setup do |config|
53
- if ENV["LC_LWS_API_TOKEN"].blank?
54
- config.api_token = ENV["LC_LWS_TEST_TOKEN"]
55
- end
56
- if ENV["LC_LWS_TEST_DEBUG"].present?
57
- config.logger = Logger.new($stdout)
58
- config.http_debug = true
59
- config.http_debug_headers = false
60
- config.json_debug = true
61
- end
62
- if ENV["LC_LWS_ENV"].blank?
63
- config.environment = :development
64
- end
65
-
66
- # Override the config with the given options.
67
- options.each do |key, value|
68
- config[key] = value
69
- end
70
-
71
- # Finally, yield the block
72
- yield config if block_given?
73
- end
74
- end
75
-
76
- # Perform initial configuration.
77
- reconfigure