test/client_test.rb in 3scale_client-2.9.0 vs test/client_test.rb in 3scale_client-2.10.0
- old
+ new
@@ -265,11 +265,11 @@
def test_hierarchy
# Hierarchies can be retrieved in authorize, authrep, and oauth_authorize
# calls.
urls = [:authorize, :authrep, :oauth_authorize].inject({}) do |acc, method|
acc[method] = "http://#{@host}/transactions/#{method}.xml?"\
- "provider_key=1234abcd&app_id=foo&hierarchy=1"
+ "provider_key=1234abcd&app_id=foo"
acc[method] << "&%5Busage%5D%5Bhits%5D=1" if method == :authrep
acc
end
body = '<status>
@@ -315,11 +315,11 @@
</hierarchy>
</status>'
urls.each do |method, url|
FakeWeb.register_uri(:get, url, :status => ['200', 'OK'], :body => body)
- response = @client.send(method, :app_id => 'foo', :hierarchy => 1)
+ response = @client.send(method, :app_id => 'foo', extensions: { :hierarchy => 1 })
assert_equal response.hierarchy, { 'parent1' => ['child1', 'child2'],
'parent2' => ['child3'] }
end
end
@@ -698,9 +698,68 @@
assert response.success?
assert !response.limits_exceeded?
request = FakeWeb.last_request
assert_equal "plugin-ruby-v#{version}", request["X-3scale-User-Agent"]
assert_equal "su1.3scale.net", request["host"]
+ end
+
+ EXTENSIONS_HASH = {
+ 'a special &=key' => 'a special =&value',
+ 'ary' => [1,2],
+ 'a hash' => { one: 'one', two: 'two' },
+ 'combined' =>
+ { v: 'v', nested: [1, { h: [ { hh: [ { hhh: :deep }, 'val' ] } ], h2: :h2 } ] }
+ }
+ private_constant :EXTENSIONS_HASH
+ EXTENSIONS_STR = "a+special+%26%3Dkey=a+special+%3D%26value&ary[]=1&ary[]=2&" \
+ "a+hash[one]=one&a+hash[two]=two&combined[v]=v&" \
+ "combined[nested][]=1&combined[nested][][h][][hh][][hhh]=deep&" \
+ "combined[nested][][h][][hh][]=val&combined[nested][][h2]=h2".freeze
+ private_constant :EXTENSIONS_STR
+
+ def test_authorize_with_extensions
+ body = '<status>
+ <authorized>true</authorized>
+ <plan>Ultimate</plan>
+ </status>'
+ FakeWeb.register_uri(:get,
+ "http://#{@host}/transactions/authorize.xml?provider_key=1234abcd&app_id=foo",
+ :status => ['200', 'OK'], body: body)
+
+ @client.authorize(:app_id => 'foo', extensions: EXTENSIONS_HASH)
+
+ request = FakeWeb.last_request
+ assert_equal EXTENSIONS_STR, request[ThreeScale::Client.const_get('EXTENSIONS_HEADER')]
+ end
+
+ def test_authrep_with_extensions
+ body = '<status>
+ <authorized>true</authorized>
+ <plan>Ultimate</plan>
+ </status>'
+ FakeWeb.register_uri(:get,
+ "http://#{@host}/transactions/authrep.xml?provider_key=1234abcd&app_id=foo&%5Busage%5D%5Bhits%5D=1",
+ :status => ['200', 'OK'], body: body)
+
+ @client.authrep(:app_id => 'foo', extensions: EXTENSIONS_HASH)
+
+ request = FakeWeb.last_request
+ assert_equal EXTENSIONS_STR, request['3scale-options']
+ end
+
+ def test_report_with_extensions
+ FakeWeb.register_uri(:post, "http://#{@host}/transactions.xml",
+ :status => ['200', 'OK'])
+
+ transactions = [{ :app_id => 'app_id_1',
+ :usage => { 'hits' => 1 },
+ :timestamp => '2016-07-18 15:42:17 0200' }]
+
+ @client.report(transactions: transactions, service_id: 'a_service_id',
+ extensions: EXTENSIONS_HASH)
+
+ request = FakeWeb.last_request
+ assert_equal EXTENSIONS_STR, request['3scale-options']
end
private
#OPTIMIZE this tricky test helper relies on fakeweb catching the urls requested by the client