Permalink
Browse files

Expanded/tweaked tests

  • Loading branch information...
arsduo committed Feb 8, 2012
1 parent c4e0a84 commit 61935d40b19df8b97e8cc204c6406f6651634ca3
View
@@ -466,28 +466,36 @@
end
describe "exchange_access_token_info" do
- it "properly gets and parses an app's access token as a hash" do
- result = @oauth.exchange_access_token_info(KoalaTest.oauth_token)
- result.should be_a(Hash)
- end
+ if KoalaTest.mock_interface? || KoalaTest.oauth_token
+ it "properly gets and parses an app's access token as a hash" do
+ result = @oauth.exchange_access_token_info(KoalaTest.oauth_token)
+ result.should be_a(Hash)
+ end
- it "includes the access token" do
- result = @oauth.exchange_access_token_info(KoalaTest.oauth_token)
- result["access_token"].should
+ it "includes the access token" do
+ result = @oauth.exchange_access_token_info(KoalaTest.oauth_token)
+ result["access_token"].should
+ end
+ else
+ pending "Some OAuth token exchange tests will not be run since the access token field in facebook_data.yml is blank."
end
it "passes on any options provided to make_request" do
options = {:a => 2}
Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
@oauth.exchange_access_token_info(KoalaTest.oauth_token, options)
end
+
+ it "raises an error when exchange_access_token_info is called with a bad code" do
+ lambda { @oauth.exchange_access_token_info("foo") }.should raise_error(Koala::Facebook::APIError)
+ end
end
describe "exchange_access_token" do
it "uses get_access_token_info to get and parse an access token token results" do
- result = @oauth.exchange_access_token(KoalaTest.oauth_token)
- original = @oauth.exchange_access_token_info(KoalaTest.oauth_token)
- result.should == original["access_token"]
+ hash = {"access_token" => Time.now.to_i * rand}
+ @oauth.stub(:exchange_access_token_info).and_return(hash)
+ @oauth.exchange_access_token(KoalaTest.oauth_token).should == hash["access_token"]
end
it "passes on any options provided to make_request" do
@@ -498,7 +506,6 @@
end
describe "protected methods" do
-
# protected methods
# since these are pretty fundamental and pretty testable, we want to test them
@@ -23,7 +23,6 @@ oauth_test_data:
app_id: 119908831367602
secret: e45e55a333eec232d4206d2703de1307
callback_url: http://oauth.twoalex.com/
- access_token: "119908831367602|2.6GneoQbnEqtSiPppZzDU4Q__.3600.1273366800-2905623|3OLa3w0x1K4C1S5cOgbs07TytAk."
app_access_token: 119908831367602|o3wswWQ88LYjEC9-ukR_gjRIOMw.
raw_token_string: "access_token=119908831367602|2.6GneoQbnEqtSiPppZzDU4Q__.3600.1273366800-2905623|3OLa3w0x1K4C1S5cOgbs07TytAk.&expires=6621"
raw_offline_access_token_string: access_token=119908831367602|2.6GneoQbnEqtSiPppZzDU4Q__.3600.1273366800-2905623|3OLa3w0x1K4C1S5cOgbs07TytAk.
@@ -34,7 +33,7 @@ oauth_test_data:
offline_access_cookies:
# note: I've revoked the offline access for security reasons, so you can't make calls against this :)
fbs_119908831367602: '"access_token=119908831367602|08170230801eb225068e7a70-2905623|Q3LDCYYF8CX9cstxnZLsxiR0nwg.&expires=0&secret=78abaee300b392e275072a9f2727d436&session_key=08170230801eb225068e7a70-2905623&sig=423b8aa4b6fa1f9a571955f8e929d567&uid=2905623"'
- valid_signed_cookies:
+ valid_signed_cookies:
"fbsr_119908831367602": "f1--LHwjHVCxfs97hRHL-4cF-0jNxZRc6MGzo1qHLb0.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiIyLkFRQm90a0pBWlhVY1l3RkMuMzYwMC4xMzE0ODEzNjAwLjEtMjkwNTYyM3x4V2xya0d0UmJIZlpIclRnVWwxQmxJcVhRbjQiLCJpc3N1ZWRfYXQiOjEzMTQ4MDY2NTUsInVzZXJfaWQiOiIyOTA1NjIzIn0"
@@ -311,6 +311,9 @@ graph_api:
client_id=<%= APP_ID %>&client_secret=<%= SECRET %>&fb_exchange_token=<%= ACCESS_TOKEN %>&grant_type=fb_exchange_token:
post:
no_token: access_token=<%= ACCESS_TOKEN %>&expires=5184000
+ client_id=<%= APP_ID %>&client_secret=<%= SECRET %>&fb_exchange_token=foo&grant_type=fb_exchange_token:
+ post:
+ <<: *oauth_error
/oauth/exchange_sessions:
client_id=<%= APP_ID %>&client_secret=<%= SECRET %>&sessions=<%= OAUTH_DATA["session_key"] %>&type=client_cred:
post:
@@ -19,7 +19,7 @@ module MockHTTPService
TEST_DATA.merge!('oauth_token' => Koala::MockHTTPService::ACCESS_TOKEN)
TEST_DATA['oauth_test_data'].merge!('code' => Koala::MockHTTPService::OAUTH_CODE)
TEST_DATA['search_time'] = (Time.now - 3600).to_s
-
+
# Useful in mock_facebook_responses.yml
OAUTH_DATA = TEST_DATA['oauth_test_data']
OAUTH_DATA.merge!({
@@ -40,7 +40,6 @@ def self.make_request(path, args, verb, options = {})
verb ||= 'get'
server = options[:rest_api] ? 'rest_api' : 'graph_api'
token = args.delete('access_token')
- args[:fb_exchange_token] = ACCESS_TOKEN if args.has_key?(:fb_exchange_token)
with_token = (token == ACCESS_TOKEN || token == APP_ACCESS_TOKEN) ? 'with_token' : 'no_token'
# Assume format is always JSON

0 comments on commit 61935d4

Please sign in to comment.