Commit 10767c92f767b4a964c0526f14e614cb49ecc453
1 parent
305ff19a
Exists in
master
and in
1 other branch
extra tests for room support as well
Showing
1 changed file
with
59 additions
and
9 deletions
Show diff stats
spec/models/notification_service/gtalk_service_spec.rb
| @@ -4,6 +4,7 @@ describe NotificationService::GtalkService do | @@ -4,6 +4,7 @@ describe NotificationService::GtalkService do | ||
| 4 | it "it should send a notification to gtalk" do | 4 | it "it should send a notification to gtalk" do |
| 5 | # setup | 5 | # setup |
| 6 | notice = Fabricate :notice | 6 | notice = Fabricate :notice |
| 7 | + problem = notice.problem | ||
| 7 | notification_service = Fabricate :gtalk_notification_service, :app => notice.app | 8 | notification_service = Fabricate :gtalk_notification_service, :app => notice.app |
| 8 | problem = notice.problem | 9 | problem = notice.problem |
| 9 | 10 | ||
| @@ -15,22 +16,31 @@ describe NotificationService::GtalkService do | @@ -15,22 +16,31 @@ describe NotificationService::GtalkService do | ||
| 15 | Jabber::Client.should_receive(:new).with(jid).and_return(gtalk) | 16 | Jabber::Client.should_receive(:new).with(jid).and_return(gtalk) |
| 16 | gtalk.should_receive(:connect) | 17 | gtalk.should_receive(:connect) |
| 17 | gtalk.should_receive(:auth).with(notification_service.api_token) | 18 | gtalk.should_receive(:auth).with(notification_service.api_token) |
| 18 | - Jabber::Message.should_receive(:new).with(notification_service.room_id, "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_service.notification_description problem}").and_return(message) | ||
| 19 | - | 19 | + message_value = """#{problem.app.name.to_s} |
| 20 | +http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} | ||
| 21 | +#{notification_service.notification_description problem}""" | ||
| 22 | + | ||
| 23 | + Jabber::Message.should_receive(:new).with(notification_service.user_id, message_value).and_return(message) | ||
| 24 | + Jabber::Message.should_receive(:new).with(notification_service.room_id, message_value).and_return(message) | ||
| 25 | + | ||
| 26 | + Jabber::MUC::SimpleMUCClient.should_receive(:new).and_return(gtalk) | ||
| 27 | + gtalk.should_receive(:join).with(notification_service.room_id + "/errbit") | ||
| 28 | + | ||
| 20 | #assert | 29 | #assert |
| 21 | - gtalk.should_receive(:send).with(message) | ||
| 22 | - | 30 | + gtalk.should_receive(:send).exactly(2).times.with(message) |
| 23 | 31 | ||
| 24 | notification_service.create_notification(problem) | 32 | notification_service.create_notification(problem) |
| 25 | end | 33 | end |
| 26 | 34 | ||
| 27 | - describe "multiple room_ids (or users)" do | 35 | + describe "multiple users_ids" do |
| 28 | before(:each) do | 36 | before(:each) do |
| 29 | # setup | 37 | # setup |
| 30 | @notice = Fabricate :notice | 38 | @notice = Fabricate :notice |
| 31 | @notification_service = Fabricate :gtalk_notification_service, :app => @notice.app | 39 | @notification_service = Fabricate :gtalk_notification_service, :app => @notice.app |
| 32 | @problem = @notice.problem | 40 | @problem = @notice.problem |
| 33 | - @error_msg = "[errbit] http://#{Errbit::Config.host}/apps/#{@problem.app.id.to_s} #{@notification_service.notification_description @problem}" | 41 | + @error_msg = """#{@problem.app.name.to_s} |
| 42 | +http://#{Errbit::Config.host}/apps/#{@problem.app.id.to_s} | ||
| 43 | +#{@notification_service.notification_description @problem}""" | ||
| 34 | 44 | ||
| 35 | # gtalk stubbing | 45 | # gtalk stubbing |
| 36 | @gtalk = mock('GtalkService') | 46 | @gtalk = mock('GtalkService') |
| @@ -45,9 +55,11 @@ describe NotificationService::GtalkService do | @@ -45,9 +55,11 @@ describe NotificationService::GtalkService do | ||
| 45 | Jabber::Message.should_receive(:new).with("second@domain.org", @error_msg) | 55 | Jabber::Message.should_receive(:new).with("second@domain.org", @error_msg) |
| 46 | Jabber::Message.should_receive(:new).with("third@domain.org", @error_msg) | 56 | Jabber::Message.should_receive(:new).with("third@domain.org", @error_msg) |
| 47 | Jabber::Message.should_receive(:new).with("fourth@domain.org", @error_msg) | 57 | Jabber::Message.should_receive(:new).with("fourth@domain.org", @error_msg) |
| 58 | + Jabber::MUC::SimpleMUCClient.should_not_receive(:new) | ||
| 48 | @gtalk.should_receive(:send).exactly(4).times | 59 | @gtalk.should_receive(:send).exactly(4).times |
| 49 | 60 | ||
| 50 | - @notification_service.room_id = "first@domain.org,second@domain.org, third@domain.org , fourth@domain.org " | 61 | + @notification_service.user_id = "first@domain.org,second@domain.org, third@domain.org , fourth@domain.org " |
| 62 | + @notification_service.room_id = "" | ||
| 51 | @notification_service.create_notification(@problem) | 63 | @notification_service.create_notification(@problem) |
| 52 | end | 64 | end |
| 53 | it "should send a notification to all ';' separated users" do | 65 | it "should send a notification to all ';' separated users" do |
| @@ -55,9 +67,11 @@ describe NotificationService::GtalkService do | @@ -55,9 +67,11 @@ describe NotificationService::GtalkService do | ||
| 55 | Jabber::Message.should_receive(:new).with("second@domain.org", @error_msg) | 67 | Jabber::Message.should_receive(:new).with("second@domain.org", @error_msg) |
| 56 | Jabber::Message.should_receive(:new).with("third@domain.org", @error_msg) | 68 | Jabber::Message.should_receive(:new).with("third@domain.org", @error_msg) |
| 57 | Jabber::Message.should_receive(:new).with("fourth@domain.org", @error_msg) | 69 | Jabber::Message.should_receive(:new).with("fourth@domain.org", @error_msg) |
| 70 | + Jabber::MUC::SimpleMUCClient.should_not_receive(:new) | ||
| 58 | @gtalk.should_receive(:send).exactly(4).times | 71 | @gtalk.should_receive(:send).exactly(4).times |
| 59 | 72 | ||
| 60 | - @notification_service.room_id = "first@domain.org;second@domain.org; third@domain.org ; fourth@domain.org " | 73 | + @notification_service.user_id = "first@domain.org;second@domain.org; third@domain.org ; fourth@domain.org " |
| 74 | + @notification_service.room_id = "" | ||
| 61 | @notification_service.create_notification(@problem) | 75 | @notification_service.create_notification(@problem) |
| 62 | end | 76 | end |
| 63 | it "should send a notification to all ' ' separated users" do | 77 | it "should send a notification to all ' ' separated users" do |
| @@ -65,11 +79,47 @@ describe NotificationService::GtalkService do | @@ -65,11 +79,47 @@ describe NotificationService::GtalkService do | ||
| 65 | Jabber::Message.should_receive(:new).with("second@domain.org", @error_msg) | 79 | Jabber::Message.should_receive(:new).with("second@domain.org", @error_msg) |
| 66 | Jabber::Message.should_receive(:new).with("third@domain.org", @error_msg) | 80 | Jabber::Message.should_receive(:new).with("third@domain.org", @error_msg) |
| 67 | Jabber::Message.should_receive(:new).with("fourth@domain.org", @error_msg) | 81 | Jabber::Message.should_receive(:new).with("fourth@domain.org", @error_msg) |
| 82 | + Jabber::MUC::SimpleMUCClient.should_not_receive(:new) | ||
| 68 | @gtalk.should_receive(:send).exactly(4).times | 83 | @gtalk.should_receive(:send).exactly(4).times |
| 69 | 84 | ||
| 70 | - @notification_service.room_id = "first@domain.org second@domain.org third@domain.org fourth@domain.org " | 85 | + @notification_service.user_id = "first@domain.org second@domain.org third@domain.org fourth@domain.org " |
| 86 | + @notification_service.room_id = "" | ||
| 71 | @notification_service.create_notification(@problem) | 87 | @notification_service.create_notification(@problem) |
| 72 | end | 88 | end |
| 89 | + | ||
| 73 | end | 90 | end |
| 91 | + | ||
| 92 | + it "it should send a notification to room only" do | ||
| 93 | + # setup | ||
| 94 | + notice = Fabricate :notice | ||
| 95 | + problem = notice.problem | ||
| 96 | + notification_service = Fabricate :gtalk_notification_service, :app => notice.app | ||
| 97 | + problem = notice.problem | ||
| 98 | + | ||
| 99 | + #gtalk stubbing | ||
| 100 | + gtalk = mock('GtalkService') | ||
| 101 | + jid = double("jid") | ||
| 102 | + message = double("message") | ||
| 103 | + Jabber::JID.should_receive(:new).with(notification_service.subdomain).and_return(jid) | ||
| 104 | + Jabber::Client.should_receive(:new).with(jid).and_return(gtalk) | ||
| 105 | + gtalk.should_receive(:connect) | ||
| 106 | + gtalk.should_receive(:auth).with(notification_service.api_token) | ||
| 107 | + message_value = """#{problem.app.name.to_s} | ||
| 108 | +http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} | ||
| 109 | +#{notification_service.notification_description problem}""" | ||
| 110 | + | ||
| 111 | + Jabber::Message.should_receive(:new).with(notification_service.room_id, message_value).and_return(message) | ||
| 112 | + | ||
| 113 | + Jabber::MUC::SimpleMUCClient.should_receive(:new).and_return(gtalk) | ||
| 114 | + gtalk.should_receive(:join).with(notification_service.room_id + "/errbit") | ||
| 115 | + | ||
| 116 | + notification_service.user_id = "" | ||
| 117 | + | ||
| 118 | + #assert | ||
| 119 | + gtalk.should_receive(:send).with(message) | ||
| 120 | + | ||
| 121 | + notification_service.create_notification(problem) | ||
| 122 | + end | ||
| 123 | + | ||
| 74 | end | 124 | end |
| 75 | 125 |