test/client_test.rb in vault-usage-client-0.0.8 vs test/client_test.rb in vault-usage-client-0.0.9

- old
+ new

@@ -46,11 +46,11 @@ def test_open_usage_event Excon.stub(method: :put) do |request| assert_equal('Basic dXNlcm5hbWU6c2VjcmV0', request[:headers]['Authorization']) assert_equal('vault-usage.herokuapp.com', request[:host]) - assert_equal('443', request[:port]) + 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} @@ -104,11 +104,11 @@ def test_close_usage_event Excon.stub(method: :put) do |request| assert_equal('Basic dXNlcm5hbWU6c2VjcmV0', request[:headers]['Authorization']) assert_equal('vault-usage.herokuapp.com', request[:host]) - assert_equal('443', request[:port]) + 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} @@ -145,11 +145,11 @@ def test_open_close_usage_event Excon.stub(method: :put) do |request| assert_equal('Basic dXNlcm5hbWU6c2VjcmV0', request[:headers]['Authorization']) assert_equal('vault-usage.herokuapp.com', request[:host]) - assert_equal('443', request[:port]) + assert_equal(443, request[:port]) assert_equal("/products/#{@product_name}/usage/#{@app_hid}" + "/events/#{@event_id}/open/#{iso_format(@start_time)}" + "/close/#{iso_format(@stop_time)}", request[:path]) Excon.stubs.pop @@ -219,11 +219,11 @@ def test_usage_for_user Excon.stub(method: :get) do |request| assert_equal('Basic dXNlcm5hbWU6c2VjcmV0', request[:headers]['Authorization']) assert_equal('vault-usage.herokuapp.com', request[:host]) - assert_equal('443', request[:port]) + 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: MultiJson.dump({events: []})} @@ -342,11 +342,11 @@ 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', request[:host]) - assert_equal('443', request[:port]) + 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} @@ -387,11 +387,11 @@ 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', request[:host]) - assert_equal('443', request[:port]) + 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} @@ -431,13 +431,29 @@ def test_usage_for_user Excon.stub(method: :get) do |request| assert_equal('Basic dXNlcm5hbWU6c2VjcmV0', request[:headers]['Authorization']) assert_equal('vault-usage.herokuapp.com', request[:host]) - assert_equal('443', request[:port]) + assert_equal(443, request[:port]) assert_equal("/apps/#{@app_hid}/ps/open", request[:path]) Excon.stubs.pop {status: 200, body: MultiJson.dump({events: []})} end assert_equal([], @client.open_dynos_for_app(@app_hid)) + end + + # Client.usage_for_user_by_product makes a GET request to the Vault::Usage HTTP API, + # passing the supplied credentials using HTTP basic auth, to retrieve the + # usage events specific to a product + def test_usage_for_user_by_product + Excon.stub(method: :get) do |request| + assert_equal('Basic dXNlcm5hbWU6c2VjcmV0', + request[:headers]['Authorization']) + assert_equal('vault-usage.herokuapp.com', request[:host]) + assert_equal(443, request[:port]) + assert_equal("/users/#{@user_hid}/usage/product/#{@product_name}", request[:path]) + Excon.stubs.pop + {status: 200, body: MultiJson.dump({events: []})} + end + assert_equal([], @client.usage_for_user_by_product(@user_hid, @product_name)) end end