test/client_test.rb in vault-usage-client-0.0.1 vs test/client_test.rb in vault-usage-client-0.0.4
- old
+ new
@@ -45,11 +45,12 @@
# usage of a product began at a particular time.
def test_open_usage_event
Excon.stub(method: :put) do |request|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
request[:headers]['Authorization'])
- assert_equal('vault-usage.herokuapp.com:443', request[:host_port])
+ assert_equal('vault-usage.herokuapp.com', request[:host])
+ assert_equal('443', request[:port])
assert_equal("/products/#{@product_name}/usage/#{@app_hid}" +
"/events/#{@event_id}/open/#{iso_format(@start_time)}",
request[:path])
Excon.stubs.pop
{status: 201}
@@ -101,11 +102,12 @@
# that usage of a product ended at a particular time.
def test_close_usage_event
Excon.stub(method: :put) do |request|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
request[:headers]['Authorization'])
- assert_equal('vault-usage.herokuapp.com:443', request[:host_port])
+ assert_equal('vault-usage.herokuapp.com', request[:host])
+ assert_equal('443', request[:port])
assert_equal("/products/#{@product_name}/usage/#{@app_hid}" +
"/events/#{@event_id}/close/#{iso_format(@stop_time)}",
request[:path])
Excon.stubs.pop
{status: 201}
@@ -142,16 +144,17 @@
# period of time.
def test_usage_for_user
Excon.stub(method: :get) do |request|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
request[:headers]['Authorization'])
- assert_equal('vault-usage.herokuapp.com:443', request[:host_port])
+ assert_equal('vault-usage.herokuapp.com', request[:host])
+ assert_equal('443', request[:port])
assert_equal("/users/#{@user_hid}/usage/#{iso_format(@start_time)}/" +
"#{iso_format(@stop_time)}",
request[:path])
Excon.stubs.pop
- {status: 200, body: JSON.generate([])}
+ {status: 200, body: JSON.generate({events: []})}
end
assert_equal([], @client.usage_for_user(@user_hid, @start_time,
@stop_time))
end
@@ -159,38 +162,48 @@
# They're passed to the server using query string arguments.
def test_usage_for_user_with_exclude
Excon.stub(method: :get) do |request|
assert_equal({exclude: 'platform:dyno:physical'}, request[:query])
Excon.stubs.pop
- {status: 200, body: JSON.generate([])}
+ {status: 200, body: JSON.generate({events: []})}
end
assert_equal([], @client.usage_for_user(@user_hid, @start_time, @stop_time,
['platform:dyno:physical']))
end
+ def test_usage_for_user_with_callback_url
+ Excon.stub(method: :get) do |request|
+ assert_equal({callback_url: 'http://example.com'}, request[:query])
+ Excon.stubs.pop
+ {status: 200, body: JSON.generate({job_id: 'DEADBEEF'})}
+ end
+ assert_equal('DEADBEEF',
+ @client.usage_for_user(@user_hid, @start_time, @stop_time, nil,'http://example.com'))
+ end
+
# Client.usage_for_user comma-separates product names, when many are
# provided in the exclusion list, and passes them to the server using a
# single query argument.
def test_usage_for_user_with_many_excludes
Excon.stub(method: :get) do |request|
assert_equal({exclude: 'platform:dyno:physical,addons:memcache:100mb'},
request[:query])
Excon.stubs.pop
- {status: 200, body: JSON.generate([])}
+ {status: 200, body: JSON.generate({events: []})}
end
assert_equal([], @client.usage_for_user(@user_hid, @start_time, @stop_time,
['platform:dyno:physical',
'addons:memcache:100mb']))
end
# Client.usage_for_user with an empty product exclusion list is the same as
# not passing one at all.
def test_usage_for_user_with_empty_exclude
Excon.stub(method: :get) do |request|
- assert_equal(nil, request[:query])
+ assert_equal({}, request[:query])
Excon.stubs.pop
- {status: 200, body: JSON.generate([])}
+ {status: 200, body: JSON.generate({events: []})}
end
assert_equal([], @client.usage_for_user(@user_hid, @start_time, @stop_time,
[]))
end
@@ -203,11 +216,11 @@
product: @product_name,
consumer: @app_hid,
start_time: iso_format(@start_time),
stop_time: iso_format(@stop_time),
detail: {}}]
- {status: 200, body: JSON.generate(events)}
+ {status: 200, body: JSON.generate({events: events})}
end
assert_equal([{id: @event_id,
product: @product_name,
consumer: @app_hid,
start_time: @start_time,
@@ -254,11 +267,12 @@
# particular time.
def test_open_app_ownership_event
Excon.stub(method: :put) do |request|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
request[:headers]['Authorization'])
- assert_equal('vault-usage.herokuapp.com:443', request[:host_port])
+ assert_equal('vault-usage.herokuapp.com', request[:host])
+ assert_equal('443', request[:port])
assert_equal("/users/#{@user_hid}/apps/#{@app_hid}/open/#{@event_id}" +
"/#{iso_format(@start_time)}",
request[:path])
Excon.stubs.pop
{status: 201}
@@ -298,10 +312,11 @@
# particular time.
def test_close_app_ownership_event
Excon.stub(method: :put) do |request|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
request[:headers]['Authorization'])
- assert_equal('vault-usage.herokuapp.com:443', request[:host_port])
+ assert_equal('vault-usage.herokuapp.com', request[:host])
+ assert_equal('443', request[:port])
assert_equal("/users/#{@user_hid}/apps/#{@app_hid}/close/#{@event_id}" +
"/#{iso_format(@stop_time)}",
request[:path])
Excon.stubs.pop
{status: 201}