spec/provisioning_spec.rb in connfu-client-0.1.2 vs spec/provisioning_spec.rb in connfu-client-0.1.3

- old
+ new

@@ -16,15 +16,15 @@ # Matcher that helps to test if a Voice channel is well defined after retrieving data using prov API RSpec::Matchers.define :be_well_defined_as_voice do |uid, phones| match do |actual| # actual should be the Connfu::Provisioning::Voice instance actual.should be_instance_of(Connfu::Provisioning::Voice) - ["uid", "type", "phones"].each { |key| + ["uid", "channel_type", "phones"].each { |key| actual.to_hash.should have_key(key) } actual.uid.should eql(uid) - actual.type.should eql("voice") + actual.channel_type.should eql("voice") actual.should respond_to("topic") actual.should respond_to("welcome_message") actual.should respond_to("rejected_message") actual.should respond_to("privacy") @@ -44,16 +44,16 @@ # Matcher that helps to test if a Twitter channel is well defined after retrieving data using prov API RSpec::Matchers.define :be_well_defined_as_twitter do |uid, twitter_accounts| match do |actual| # actual should be the Connfu::Provisioning::Twitter instance actual.should be_instance_of(Connfu::Provisioning::Twitter) - ["uid", "type", "accounts"].each { |key| + ["uid", "channel_type", "accounts"].each { |key| actual.to_hash.should have_key(key) } actual.uid.should eql(uid) - actual.type.should eql("twitter") + actual.channel_type.should eql("twitter") actual.accounts.should be_instance_of(Array) actual.accounts.length.should eql(twitter_accounts.length) actual.accounts.each_with_index { |account, index| @@ -83,60 +83,61 @@ context "twitter" do it "should create a Twitter channel application with one origin speficied as array" do stub_request(:post, "#{ENDPOINT}/channels/twitter"). with(:body => create_twitter_channel_request(["juan"]), :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). - to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"}) + to_return(:status => 201, :body => "{'accounts':[{'name':'juan'}],'created_at':'2011-09-06T05:33:39+00:00','filter':'','uid':'#{TWITTER_KEY}','updated_at':'2011-09-06T05:33:39+00:00'}", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"}) response = @application.create_twitter_channel(TWITTER_KEY, ["juan"]) - response.should eql("#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}") + response.should be_well_defined_as_twitter(TWITTER_KEY, ['juan']) end it "should create a Twitter channel application with one origins speficied as hash (string)" do stub_request(:post, "#{ENDPOINT}/channels/twitter"). with(:body => create_twitter_channel_request(["juan"]), :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). - to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"}) + to_return(:status => 201, :body => "{'accounts':[{'name':'juan'}],'created_at':'2011-09-06T05:33:39+00:00','filter':'','uid':'#{TWITTER_KEY}','updated_at':'2011-09-06T05:33:39+00:00'}", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"}) response = @application.create_twitter_channel(TWITTER_KEY, {:origin => "juan"}) - response.should eql("#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}") + response.should be_well_defined_as_twitter(TWITTER_KEY, ['juan']) end it "should create a Twitter channel application with one origins speficied as hash (array)" do stub_request(:post, "#{ENDPOINT}/channels/twitter"). with(:body => create_twitter_channel_request(["juan"]), :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). - to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"}) + to_return(:status => 201, :body => "{'accounts':[{'name':'juan'}],'created_at':'2011-09-06T05:33:39+00:00','filter':'','uid':'#{TWITTER_KEY}','updated_at':'2011-09-06T05:33:39+00:00'}", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"}) response = @application.create_twitter_channel(TWITTER_KEY, {:origin => ["juan"]}) - response.should eql("#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}") + response.should be_well_defined_as_twitter(TWITTER_KEY, ['juan']) end it "should create a Twitter channel application with two origins speficied as Hash" do stub_request(:post, "#{ENDPOINT}/channels/twitter"). with(:body => create_twitter_channel_request(["juan", "connfu"]), :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). - to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"}) + to_return(:status => 201, :body => "{'accounts':[{'name':'juan'},{'name':'connfu'}],'created_at':'2011-09-06T05:33:39+00:00','filter':'','uid':'#{TWITTER_KEY}','updated_at':'2011-09-06T05:33:39+00:00'}", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"}) response = @application.create_twitter_channel(TWITTER_KEY, {:origin => ["juan", "connfu"]}) - response.should eql("#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}") + response.should be_well_defined_as_twitter(TWITTER_KEY, ['juan', 'connfu']) end it "should create a Twitter channel application with two origins speficied as Array" do stub_request(:post, "#{ENDPOINT}/channels/twitter"). with(:body => create_twitter_channel_request(["juan", "connfu"]), :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). - to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"}) + to_return(:status => 201, :body => "{'accounts':[{'name':'juan'},{'name':'connfu'}],'created_at':'2011-09-06T05:33:39+00:00','filter':'','uid':'#{TWITTER_KEY}','updated_at':'2011-09-06T05:33:39+00:00'}", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"}) response = @application.create_twitter_channel(TWITTER_KEY, ["juan", "connfu"]) - response.should eql("#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}") + response.should be_well_defined_as_twitter(TWITTER_KEY, ['juan', 'connfu']) end it "should create a Twitter channel application with one mention" do stub_request(:post, "#{ENDPOINT}/channels/twitter"). with(:body => create_twitter_channel_request(["juan"], TWITTER_KEY, "(recipients:juan)"), :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). - to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"}) + to_return(:status => 201, :body => "{'accounts':[{'name':'juan'}],'created_at':'2011-09-06T05:33:39+00:00','filter':'','uid':'#{TWITTER_KEY}','updated_at':'2011-09-06T05:33:39+00:00'}", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"}) response = @application.create_twitter_channel(TWITTER_KEY, {:mentions => ["juan"]}) - response.should be_kind_of(Array) - response[0].should eql("#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}") + response.should be_instance_of(Array) + response.length.should be(1) + response[0].should be_well_defined_as_twitter(TWITTER_KEY, ["juan"]) end it "should retrieve a channel information when the channel exists" do stub_request(:get, "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}?"). with(:headers => {'Accept'=>'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). @@ -178,33 +179,36 @@ context "voice" do it "should create a Voice channel application with the default privacy attribute" do stub_request(:post, "#{ENDPOINT}/channels/voice"). - with(:body => "{\"uid\":\"#{VOICE_KEY}\",\"country\":\"de\",\"privacy\":\"whitelisted\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). - to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}"}) + with(:body => "{\"uid\":\"#{VOICE_KEY}\",\"country\":\"#{COUNTRY}\",\"privacy\":\"whitelisted\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). + to_return(:status => 201, :body => "{'created_at':'2011-08-25T14:16:44+03:00','rejected_message':'You are not allowed to join this conference','privacy':'whitelisted','topic':'hello_man','uid':'#{VOICE_KEY}','updated_at':'2011-08-25T15:10:12+03:00','welcome_message':'Welcome to connFu, you are going to join the conference','phones':[{'country':'#{COUNTRY}','phone_number':'#{PHONE_NUMBER}'}]}", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}"}) - response = @application.create_voice_channel(VOICE_KEY, "de") - response.should eql("#{ENDPOINT}/channels/voice/#{VOICE_KEY}") + response = @application.create_voice_channel(VOICE_KEY, COUNTRY) + response.should be_well_defined_as_voice(VOICE_KEY, [{:phone_number => PHONE_NUMBER, :country => COUNTRY}]) + response.privacy.should eql("whitelisted") end it "should create a Voice channel application with a privacy attribute (public)" do stub_request(:post, "#{ENDPOINT}/channels/voice"). - with(:body => "{\"uid\":\"#{VOICE_KEY}\",\"country\":\"de\",\"privacy\":\"public\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). - to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}"}) + with(:body => "{\"uid\":\"#{VOICE_KEY}\",\"country\":\"#{COUNTRY}\",\"privacy\":\"public\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). + to_return(:status => 201, :body => "{'created_at':'2011-08-25T14:16:44+03:00','rejected_message':'You are not allowed to join this conference','privacy':'public','topic':'hello_man','uid':'#{VOICE_KEY}','updated_at':'2011-08-25T15:10:12+03:00','welcome_message':'Welcome to connFu, you are going to join the conference','phones':[{'country':'#{COUNTRY}','phone_number':'#{PHONE_NUMBER}'}]}", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}"}) - response = @application.create_voice_channel(VOICE_KEY, "de", Connfu::Provisioning::Voice::Privacy::PUBLIC) - response.should eql("#{ENDPOINT}/channels/voice/#{VOICE_KEY}") + response = @application.create_voice_channel(VOICE_KEY, COUNTRY, Connfu::Provisioning::Voice::Privacy::PUBLIC) + response.should be_well_defined_as_voice(VOICE_KEY, [{:phone_number => PHONE_NUMBER, :country => COUNTRY}]) + response.privacy.should eql("public") end it "should create a Voice channel application with a privacy attribute (whitelisted)" do stub_request(:post, "#{ENDPOINT}/channels/voice"). - with(:body => "{\"uid\":\"#{VOICE_KEY}\",\"country\":\"de\",\"privacy\":\"whitelisted\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). - to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}"}) + with(:body => "{\"uid\":\"#{VOICE_KEY}\",\"country\":\"#{COUNTRY}\",\"privacy\":\"whitelisted\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). + to_return(:status => 201, :body => "{'created_at':'2011-08-25T14:16:44+03:00','rejected_message':'You are not allowed to join this conference','privacy':'whitelisted','topic':'hello_man','uid':'#{VOICE_KEY}','updated_at':'2011-08-25T15:10:12+03:00','welcome_message':'Welcome to connFu, you are going to join the conference','phones':[{'country':'#{COUNTRY}','phone_number':'#{PHONE_NUMBER}'}]}", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}"}) - response = @application.create_voice_channel(VOICE_KEY, "de", Connfu::Provisioning::Voice::Privacy::WHITELIST) - response.should eql("#{ENDPOINT}/channels/voice/#{VOICE_KEY}") + response = @application.create_voice_channel(VOICE_KEY, COUNTRY, Connfu::Provisioning::Voice::Privacy::WHITELIST) + response.should be_well_defined_as_voice(VOICE_KEY, [{:phone_number => PHONE_NUMBER, :country => COUNTRY}]) + response.privacy.should eql("whitelisted") end it "should retrieve a channel information when the channel exists" do stub_request(:get, "#{ENDPOINT}/channels/voice/#{VOICE_KEY}?"). with(:headers => {'Accept'=>'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). @@ -417,26 +421,28 @@ it "should create a whitelist number with 2 parameters (name, phone)" do stub_request(:post, "#{ENDPOINT}/channels/voice/#{VOICE_KEY}/whitelisted"). with(:body => "{\"name\":\"juan\",\"phone\":\"#{PHONE_NUMBER}\"}", :headers => {'Accept'=>'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). - to_return(:status => 200, :body => "", :headers => {}) + to_return(:status => 200, :body => "{\"name\":\"juan\",\"phone\":\"#{PHONE_NUMBER}\"}", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}/whitelisted/#{PHONE_NUMBER}"}) response = @application.add_whitelist(VOICE_KEY, 'juan', PHONE_NUMBER) - response.should eql("") - + response.should be_instance_of(Connfu::Provisioning::WhitelistUser) + response.name.should eql("juan") + response.phone.should eql(PHONE_NUMBER) end it "should create a whitelist number with 1 parameter (WhitelistUser)" do stub_request(:post, "#{ENDPOINT}/channels/voice/#{VOICE_KEY}/whitelisted"). with(:body => "{\"name\":\"juan\",\"phone\":\"#{PHONE_NUMBER}\"}", :headers => {'Accept'=>'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). - to_return(:status => 200, :body => "", :headers => {}) + to_return(:status => 200, :body => "{'name':'juan','phone':'#{PHONE_NUMBER}'}", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}/whitelisted/#{PHONE_NUMBER}"}) response = @application.add_whitelist(VOICE_KEY, Connfu::Provisioning::WhitelistUser.new('juan', PHONE_NUMBER)) - response.should eql("") - + response.should be_instance_of(Connfu::Provisioning::WhitelistUser) + response.name.should eql("juan") + response.phone.should eql(PHONE_NUMBER) end it "should update a whitelist number with 1 parameter (WhitelistUser)" do stub_request(:put, "#{ENDPOINT}/channels/voice/#{VOICE_KEY}/whitelisted/#{PHONE_NUMBER}"). @@ -452,13 +458,14 @@ context "rss" do it "should create a RSS channel application" do stub_request(:post, "#{ENDPOINT}/channels/rss"). with(:body => "{\"uid\":\"#{RSS_KEY}\",\"uri\":\"http://connfu.com/rss\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}). - to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/voice/#{RSS_KEY}"}) + to_return(:status => 201, :body => "{'created_at':'2011-07-17T20:57:01+03:00','uri':'http://connfu.com/rss','uid':#{RSS_KEY},'updated_at':'2011-07-17T20:57:01+03:00'}", :headers => {:location => "#{ENDPOINT}/channels/voice/#{RSS_KEY}"}) - response = @application.create_rss_channel(RSS_KEY, "http://connfu.com/rss") - response.should eql("#{ENDPOINT}/channels/voice/#{RSS_KEY}") + rss = @application.create_rss_channel(RSS_KEY, "http://connfu.com/rss") + rss.uid.should eql(RSS_KEY) + rss.uri.should eql("http://connfu.com/rss") end it "should retrieve a RSS channel information when the channel exists" do stub_request(:get, "#{ENDPOINT}/channels/rss/#{RSS_KEY}?"). with(:headers => {'Accept'=>'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).