1 require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
3 class Facebooker::AdminTest < Test::Unit::TestCase
5 @session = Facebooker::Session.create('apikey', 'secretkey')
6 Facebooker.use_curl=false
9 def test_can_ask_facebook_to_set_app_properties
10 expect_http_posts_with_responses(example_set_properties_xml)
11 properties = { :application_name => "Video Jukebox", :dev_mode => 0 }
12 assert(@session.admin.set_app_properties(properties))
15 def test_set_app_properties_json_conversion
16 properties = { :application_name => "Video Jukebox", :dev_mode => 0 }
17 flexmock(@session).should_receive(:post).with('facebook.admin.setAppProperties', :properties => properties.to_json).and_return('1').once
18 assert(@session.admin.set_app_properties(properties))
21 def test_can_ask_facebook_to_get_app_properties
22 expect_http_posts_with_responses(example_get_properties_xml)
23 properties = [ :application_name, :dev_mode ]
24 assert(@session.admin.get_app_properties(properties))
27 def test_can_get_properties
28 mock_http = establish_session
29 mock_http.should_receive(:post_form).and_return(example_get_properties_xml).once.ordered(:posts)
30 p = @session.admin.get_app_properties(:application_name, :dev_mode, :canvas_name)
31 assert_equal 'Video Jukebox', p.application_name
32 assert_equal 0, p.dev_mode
33 assert_equal 'my_canvas', p.canvas_name
36 def test_can_set_restriction_info
37 restrictions = {:age => '21', :type => 'alcohol'}
38 flexmock(@session).should_receive(:post).with('facebook.admin.setRestrictionInfo', :restriction_str => restrictions.to_json).and_return('1').once
39 assert(@session.admin.set_restriction_info(restrictions))
42 def test_can_get_restriction_info
43 mock_http = establish_session
44 mock_http.should_receive(:post_form).and_return(example_get_restriction_info_xml).once.ordered(:posts)
45 r = @session.admin.get_restriction_info
46 assert_equal 'alcohol', r.type
47 assert_equal '21', r.age
50 def test_can_get_allocation
51 mock_http = establish_session
52 mock_http.should_receive(:post_form).and_return(example_get_allocation_xml).once.ordered(:posts)
53 alloc = @session.admin.get_allocation(:notifications_per_day)
54 assert_equal 40, alloc
58 def example_set_properties_xml
60 <?xml version="1.0" encoding="UTF-8"?>
61 <admin_setAppProperties_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
62 xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</admin_setAppProperties_response>
66 def example_get_properties_xml
68 <?xml version="1.0" encoding="UTF-8"?>
69 <admin_getAppProperties_response
70 xmlns="http://api.facebook.com/1.0/"
71 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
72 xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
73 {"application_name":"Video Jukebox","callback_url":"http:\/\/67.207.144.245\/","dev_mode":0,"canvas_name":"my_canvas"}
74 </admin_getAppProperties_response>
78 def example_get_restriction_info_xml
80 <?xml version="1.0" encoding="UTF-8"?>
81 <admin_getRestrictionInfo_response
82 xmlns="http://api.facebook.com/1.0/"
83 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
84 xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
85 {"age":"21","location":"","age_distribution":"","type":"alcohol"}
86 </admin_getRestrictionInfo_response>
90 def example_get_allocation_xml
92 <?xml version="1.0" encoding="UTF-8"?>
93 <admin_getAllocation_response
94 xmlns="http://api.facebook.com/1.0/"
95 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
96 xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
98 </admin_getAllocation_response>