spec/authy/api_spec.rb in authy-2.7.0 vs spec/authy/api_spec.rb in authy-2.7.1
- old
+ new
@@ -1,8 +1,20 @@
require 'spec_helper'
describe "Authy::API" do
+
+ describe "request headers" do
+
+ it "contains api key in header" do
+ url = "protected/json/foo/2"
+
+ HTTPClient.any_instance.should_receive(:request).twice.with( any_args, hash_including(:header=> { "X-Authy-API-Key" => Authy.api_key }) ) { double(:ok? => true, :body => "", :status => 200) }
+ response = Authy::API.get_request(url, {})
+ response = Authy::API.post_request(url, {})
+ end
+ end
+
describe "Registering users" do
it "should find or create a user" do
user = Authy::API.register_user(
:email => generate_email,
@@ -120,10 +132,10 @@
end
it "should request a #{title} token" do
uri_param = kind == "phone_call" ? "call" : kind
url = "#{Authy.api_uri}/protected/json/#{uri_param}/#{Authy::API.escape_for_url(@user.id)}"
- HTTPClient.any_instance.should_receive(:request).with(:get, url, {:query=>{:api_key=> Authy.api_key}, :header=>nil, :follow_redirect=>nil}) { double(:ok? => true, :body => "", :status => 200) }
+ HTTPClient.any_instance.should_receive(:request).with(:get, url, {:query=>{}, :header=>{ "X-Authy-API-Key" => Authy.api_key }, :follow_redirect=>nil}) { double(:ok? => true, :body => "", :status => 200) }
response = Authy::API.send("request_#{kind}", :id => @user.id)
response.should be_ok
end
it "should allow to override the API key" do