test/zeppelin_test.rb in zeppelin-0.3.0 vs test/zeppelin_test.rb in zeppelin-0.4.0
- old
+ new
@@ -13,10 +13,16 @@
assert_includes @client.connection.builder.handlers, Faraday::Adapter::NetHttp
assert_includes @client.connection.builder.handlers, Faraday::Request::JSON
assert_equal 'Basic YXBwIGtleTphcHAgbWFzdGVyIHNlY3JldA==', @client.connection.headers['Authorization']
end
+ test '#initialize with custom options' do
+ ssl_options = { :ca_path => '/dev/null' }
+ @client = Zeppelin.new('app key', 'app master secret', :ssl => ssl_options)
+ assert_equal(ssl_options, @client.connection.ssl)
+ end
+
test '#register_device_token without a payload' do
stub_requests @client.connection do |stub|
stub.put("/api/device_tokens/#{@device_token}") do [201, {}, '']
end
end
@@ -302,10 +308,37 @@
response = @client.feedback(since)
assert_nil response
end
+ test '#tags' do
+ response_body = { 'tags' => ['green', 'eggs'] }
+
+ stub_requests @client.connection do |stub|
+ stub.get('/api/tags/') do
+ [200, {}, Yajl::Encoder.encode(response_body)]
+ end
+ end
+
+ response = @client.tags
+ assert_equal response_body, response
+ end
+
+ test '#modify_device_token_on_tag' do
+ tag_name = 'jimmy.page'
+ device_token = 'CAFEBABE'
+
+ stub_requests @client.connection do |stub|
+ stub.post("/api/tags/#{tag_name}") do
+ [200, {}, 'OK']
+ end
+ end
+
+ response = @client.modify_device_tokens_on_tag(tag_name, { 'device_tokens' => { 'add' => [device_token] } })
+ assert response
+ end
+
test '#add_tag' do
tag_name = 'chunky.bacon'
stub_requests @client.connection do |stub|
stub.put("/api/tags/#{tag_name}") do
@@ -338,9 +371,36 @@
[404, {}, 'Not Found']
end
end
response = @client.remove_tag(tag_name)
+ refute response
+ end
+
+ test '#device_tags with existing device' do
+ device_token = 'CAFEBABE'
+ response_body = { 'tags' => ['tag1', 'some_tag'] }
+
+ stub_requests @client.connection do |stub|
+ stub.get("/api/device_tokens/#{device_token}/tags/") do
+ [200, {}, Yajl::Encoder.encode(response_body)]
+ end
+ end
+
+ response = @client.device_tags(device_token)
+ assert_equal response_body, response
+ end
+
+ test '#device_tags with non-existant device' do
+ device_token = 'CAFEBABE'
+
+ stub_requests @client.connection do |stub|
+ stub.get("/api/device_tokens/#{device_token}/tags/") do
+ [404, {}, 'Not Found']
+ end
+ end
+
+ response = @client.device_tags(device_token)
refute response
end
test '#add_tag_to_device' do
tag_name = 'radio.head'