Commit a5b68b1ce5aa3265fb007cf12aefe5dde502b315

Authored by Rodrigo Souto
1 parent e7196037

chat: review functional tests

Showing 1 changed file with 68 additions and 26 deletions   Show diff stats
test/functional/chat_controller_test.rb
... ... @@ -6,18 +6,20 @@ class ChatControllerTest < ActionController::TestCase
6 6 env = Environment.default
7 7 env.enable('xmpp_chat')
8 8 env.save!
  9 + #TODO Maybe someday we should have a real testing ejabberd server
  10 + RubyBOSH.stubs(:initialize_session).returns(['fake-jid@example.org', 'fake-sid', 'fake-rid'])
9 11 @person = create_user('testuser').person
10 12 end
11 13  
12 14 should 'cant view chat when not logged in' do
13   - get :index
  15 + get :start_session
14 16 assert_response 302
15 17 end
16 18  
17 19 should 'can view chat when logged in' do
18 20 login_as 'testuser'
19 21  
20   - get :index
  22 + get :start_session
21 23 assert_response :success
22 24 end
23 25  
... ... @@ -39,29 +41,6 @@ class ChatControllerTest < ActionController::TestCase
39 41 assert @response.body.index('PNG')
40 42 end
41 43  
42   - should 'auto connect if last presence status is blank' do
43   - login_as 'testuser'
44   -
45   - get :index
46   - assert_template 'auto_connect_online'
47   - end
48   -
49   - should 'auto connect if there last presence status was chat' do
50   - create_user('testuser_online', :last_chat_status => 'chat')
51   - login_as 'testuser_online'
52   -
53   - get :index
54   - assert_template 'auto_connect_online'
55   - end
56   -
57   - should 'auto connect busy if last presence status was dnd' do
58   - create_user('testuser_busy', :last_chat_status => 'dnd')
59   - login_as 'testuser_busy'
60   -
61   - get :index
62   - assert_template 'auto_connect_busy'
63   - end
64   -
65 44 begin
66 45 require 'ruby_bosh'
67 46 should 'try to start xmpp session' do
... ... @@ -87,7 +66,7 @@ class ChatControllerTest < ActionController::TestCase
87 66 env.disable('xmpp_chat')
88 67 env.save!
89 68  
90   - get :index
  69 + get :start_session
91 70  
92 71 assert_response 404
93 72 assert_template 'not_found'
... ... @@ -116,4 +95,67 @@ class ChatControllerTest < ActionController::TestCase
116 95 assert_not_equal chat_status_at, @person.user.chat_status_at
117 96 end
118 97  
  98 + should 'toggle chat status' do
  99 + login_as 'testuser'
  100 +
  101 + get :start_session
  102 + assert_nil session[:chat][:status]
  103 +
  104 + get :toggle
  105 + assert_equal 'opened', session[:chat][:status]
  106 +
  107 + get :toggle
  108 + assert_equal 'closed', session[:chat][:status]
  109 +
  110 + get :toggle
  111 + assert_equal 'opened', session[:chat][:status]
  112 + end
  113 +
  114 + should 'set tab' do
  115 + login_as 'testuser'
  116 + get :start_session
  117 +
  118 + post :tab, :tab_id => 'my_tab'
  119 + assert_equal 'my_tab', session[:chat][:tab_id]
  120 + end
  121 +
  122 + should 'join room' do
  123 + login_as 'testuser'
  124 + get :start_session
  125 +
  126 + post :join, :room_id => 'room1'
  127 + assert_equivalent ['room1'], session[:chat][:rooms]
  128 +
  129 + post :join, :room_id => 'room2'
  130 + assert_equivalent ['room1', 'room2'], session[:chat][:rooms]
  131 +
  132 + post :join, :room_id => 'room1'
  133 + assert_equivalent ['room1', 'room2'], session[:chat][:rooms]
  134 + end
  135 +
  136 + should 'leave room' do
  137 + login_as 'testuser'
  138 + get :start_session
  139 + session[:chat][:rooms] = ['room1', 'room2']
  140 +
  141 + post :leave, :room_id => 'room2'
  142 + assert_equivalent ['room1'], session[:chat][:rooms]
  143 +
  144 + post :leave, :room_id => 'room1'
  145 + assert_equivalent [], session[:chat][:rooms]
  146 +
  147 + post :leave, :room_id => 'room1'
  148 + assert_equivalent [], session[:chat][:rooms]
  149 + end
  150 +
  151 + should 'fetch chat session as json' do
  152 + login_as 'testuser'
  153 + get :start_session
  154 + my_chat = {:status => 'opened', :rooms => ['room1', 'room2'], :tab_id => 'room1'}
  155 + session[:chat] = my_chat
  156 +
  157 + get :my_session
  158 + assert_equal @response.body, my_chat.to_json
  159 + end
  160 +
119 161 end
... ...