some
[appoyo.git] / vendor / plugins / facebooker / test / facebooker / admin_test.rb
blobe1df18d672c80de3ef47a2eefe5d85957bbe697d
1 require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
3 class Facebooker::AdminTest < Test::Unit::TestCase
4   def setup
5     @session = Facebooker::Session.create('apikey', 'secretkey')
6     Facebooker.use_curl=false
7   end
8   
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))
13   end
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))
19   end
20     
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))
25   end
26   
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
34   end
35   
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))
40   end
41   
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
48   end
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
55   end
57   private
58   def example_set_properties_xml
59     <<-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>
63     XML
64   end
66   def example_get_properties_xml
67     <<-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         {&quot;application_name&quot;:&quot;Video Jukebox&quot;,&quot;callback_url&quot;:&quot;http:\/\/67.207.144.245\/&quot;,&quot;dev_mode&quot;:0,&quot;canvas_name&quot;:&quot;my_canvas&quot;}
74     </admin_getAppProperties_response>
75     XML
76   end
77   
78   def example_get_restriction_info_xml
79     <<-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         {&quot;age&quot;:&quot;21&quot;,&quot;location&quot;:&quot;&quot;,&quot;age_distribution&quot;:&quot;&quot;,&quot;type&quot;:&quot;alcohol&quot;}
86     </admin_getRestrictionInfo_response>
87     XML
88   end
89   
90   def example_get_allocation_xml
91     <<-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">
97         40
98     </admin_getAllocation_response>
99     XML
100   end
101