require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class Facebooker::ApplicationTest < Test::Unit::TestCase
def setup
@session = Facebooker::Session.create('apikey', 'secretkey')
Facebooker.use_curl=false
end
def test_can_get_public_info
mock_http = establish_session
mock_http.should_receive(:post_form).and_return(example_get_public_info_xml).once.ordered(:posts)
info = @session.application.get_public_info(:app_id => 2413267546)
assert_equal '2413267546', info["app_id"]
assert_equal 'ilike', info["canvas_name"]
end
def test_can_add_global_news
@session.expects(:post).with('facebook.dashboard.addGlobalNews', {:news => [{:message => 'Hi all users', :action_link => {:text => 'Hi application', :href => 'http://facebook.er/'}}], :image => 'http://facebook.er/icon.png'})
@session.application.add_global_news [{ :message => 'Hi all users', :action_link => { :text => "Hi application", :href => 'http://facebook.er/' }}], 'http://facebook.er/icon.png'
end
def test_parse_add_global_news
expect_http_posts_with_responses(add_global_news_xml)
assert_equal("342345290762", @session.application.add_global_news([{ :message => 'Hi user', :action_link => { :text => "Uh hey there app", :href => 'http://facebook.er/' }}], 'http://facebook.er/icon.png'))
end
def test_can_get_global_news
@session.expects(:post).with('facebook.dashboard.getGlobalNews', { :news_ids => ['310354202543'] })
@session.application.get_global_news '310354202543'
end
def test_parse_get_global_news
expect_http_posts_with_responses(get_global_news_xml)
assert_equal({"342345290762"=>{"fbid"=>"342345290762", "time"=>"1266609698761", "news"=>[{"action_link"=>{"href"=>"http://facebook.er/", "text"=>"Hi application"}, "message"=>"Hi all users"}], "image"=>"http://facebook.er/icon.png"}}, @session.application.get_global_news('342345290762'))
end
def test_can_clear_global_news
@session.expects(:post).with('facebook.dashboard.clearGlobalNews', { :news_ids => ['310354202543'] })
@session.application.clear_global_news '310354202543'
end
def test_can_parse_global_news
expect_http_posts_with_responses(clear_global_news_xml)
assert_equal({"342345290762"=>true}, @session.application.clear_global_news('342345290762'))
end
private
def example_get_public_info_xml
<<-XML
2413267546
c756401cb800e295f21d723b7842ea83
ilike
iLike
http://photos-c.ak.facebook.com/photos-ak-sctm/v43/130/2413267546/app_2_2413267546_6706.gif
http://photos-c.ak.facebook.com/photos-ak-sctm/v43/130/2413267546/app_1_2413267546_2324.gif
iLike, inc
iLike lets you add music to your profile and find your favorite concerts (not to mention see who else is going!). Bonus: Use it to get free mp3's that match your tastes and try to beat your friends at the Music Challenge.
392008
1341749
3922784
XML
end
def add_global_news_xml
<<-XML
342345290762
XML
end
def get_global_news_xml
<<-XML
http://facebook.er/icon.png
Hi all users
http://facebook.er/
Hi application
1266609698761
342345290762
XML
end
def clear_global_news_xml
<<-XML
1
XML
end
end