Commit 10767c92f767b4a964c0526f14e614cb49ecc453

Authored by damau
1 parent 305ff19a
Exists in master and in 1 other branch production

extra tests for room support as well

spec/models/notification_service/gtalk_service_spec.rb
... ... @@ -4,6 +4,7 @@ describe NotificationService::GtalkService do
4 4 it "it should send a notification to gtalk" do
5 5 # setup
6 6 notice = Fabricate :notice
  7 + problem = notice.problem
7 8 notification_service = Fabricate :gtalk_notification_service, :app => notice.app
8 9 problem = notice.problem
9 10  
... ... @@ -15,22 +16,31 @@ describe NotificationService::GtalkService do
15 16 Jabber::Client.should_receive(:new).with(jid).and_return(gtalk)
16 17 gtalk.should_receive(:connect)
17 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 29 #assert
21   - gtalk.should_receive(:send).with(message)
22   -
  30 + gtalk.should_receive(:send).exactly(2).times.with(message)
23 31  
24 32 notification_service.create_notification(problem)
25 33 end
26 34  
27   - describe "multiple room_ids (or users)" do
  35 + describe "multiple users_ids" do
28 36 before(:each) do
29 37 # setup
30 38 @notice = Fabricate :notice
31 39 @notification_service = Fabricate :gtalk_notification_service, :app => @notice.app
32 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 45 # gtalk stubbing
36 46 @gtalk = mock('GtalkService')
... ... @@ -45,9 +55,11 @@ describe NotificationService::GtalkService do
45 55 Jabber::Message.should_receive(:new).with("second@domain.org", @error_msg)
46 56 Jabber::Message.should_receive(:new).with("third@domain.org", @error_msg)
47 57 Jabber::Message.should_receive(:new).with("fourth@domain.org", @error_msg)
  58 + Jabber::MUC::SimpleMUCClient.should_not_receive(:new)
48 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 63 @notification_service.create_notification(@problem)
52 64 end
53 65 it "should send a notification to all ';' separated users" do
... ... @@ -55,9 +67,11 @@ describe NotificationService::GtalkService do
55 67 Jabber::Message.should_receive(:new).with("second@domain.org", @error_msg)
56 68 Jabber::Message.should_receive(:new).with("third@domain.org", @error_msg)
57 69 Jabber::Message.should_receive(:new).with("fourth@domain.org", @error_msg)
  70 + Jabber::MUC::SimpleMUCClient.should_not_receive(:new)
58 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 75 @notification_service.create_notification(@problem)
62 76 end
63 77 it "should send a notification to all ' ' separated users" do
... ... @@ -65,11 +79,47 @@ describe NotificationService::GtalkService do
65 79 Jabber::Message.should_receive(:new).with("second@domain.org", @error_msg)
66 80 Jabber::Message.should_receive(:new).with("third@domain.org", @error_msg)
67 81 Jabber::Message.should_receive(:new).with("fourth@domain.org", @error_msg)
  82 + Jabber::MUC::SimpleMUCClient.should_not_receive(:new)
68 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 87 @notification_service.create_notification(@problem)
72 88 end
  89 +
73 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 124 end
75 125  
... ...