Merge branch 'master' into 10112-workflow-show
[arvados.git] / apps / workbench / test / controllers / users_controller_test.rb
index 125d6b08856959904341ef78b42c43ff1a2b58ba..71354b82f3bf59650b05e49adaa905318c45845a 100644 (file)
@@ -1,6 +1,7 @@
 require 'test_helper'
 
 class UsersControllerTest < ActionController::TestCase
+
   test "valid token works in controller test" do
     get :index, {}, session_for(:active)
     assert_response :success
@@ -31,7 +32,7 @@ class UsersControllerTest < ActionController::TestCase
   end
 
   test "show repositories with read, write, or manage permission" do
-    get :manage_account, {}, session_for(:active)
+    get :repositories, {id: api_fixture("users")['active']['uuid']}, session_for(:active)
     assert_response :success
     repos = assigns(:my_repositories)
     assert repos
@@ -41,24 +42,81 @@ class UsersControllerTest < ActionController::TestCase
     assert_includes editables, false, "should have a readonly repository"
   end
 
+  test "show repositories lists linked as well as owned repositories" do
+    get :repositories, {id: api_fixture("users")['active']['uuid']}, session_for(:active)
+    assert_response :success
+    repos = assigns(:my_repositories)
+    assert repos
+    repo_writables = assigns(:repo_writable)
+    assert_not_empty repo_writables, "repo_writables should not be empty"
+    assert_includes repo_writables, api_fixture('repositories')['repository4']['uuid']  # writable by active
+    assert_includes repo_writables, api_fixture('repositories')['repository2']['uuid']  # owned by active
+  end
+
   test "request shell access" do
     user = api_fixture('users')['spectator']
 
+    ActionMailer::Base.deliveries = []
+
     post :request_shell_access, {
       id: user['uuid'],
       format: 'js'
     }, session_for(:spectator)
     assert_response :success
 
-    found_email = false
-    ActionMailer::Base.deliveries.andand.each do |email|
-      full_name = (user['first_name'] || "") + " " + (user['last_name'] || "")
-      expected = "Shell account request from #{full_name} (#{user['email']}, #{user['uuid']})"
+    full_name = "#{user['first_name']} #{user['last_name']}"
+    expected = "Shell account request from #{full_name} (#{user['email']}, #{user['uuid']})"
+    found_email = 0
+    ActionMailer::Base.deliveries.each do |email|
       if email.subject.include?(expected)
-        found_email = true
+        found_email += 1
         break
       end
     end
-    assert_equal true, found_email, "Expected email after requesting shell access"
+    assert_equal 1, found_email, "Expected 1 email after requesting shell access"
+  end
+
+  [
+    'admin',
+    'active',
+  ].each do |username|
+    test "access users page as #{username} and verify show button is available" do
+      admin_user = api_fixture('users','admin')
+      active_user = api_fixture('users','active')
+      get :index, {}, session_for(username)
+      if username == 'admin'
+        assert_match /<a href="\/projects\/#{admin_user['uuid']}">Home<\/a>/, @response.body
+        assert_match /<a href="\/projects\/#{active_user['uuid']}">Home<\/a>/, @response.body
+        assert_match /href="\/users\/#{admin_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
+        assert_match /href="\/users\/#{active_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
+        assert_includes @response.body, admin_user['email']
+        assert_includes @response.body, active_user['email']
+      else
+        refute_match  /Home<\/a>/, @response.body
+        refute_match /href="\/users\/#{admin_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
+        assert_match /href="\/users\/#{active_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
+        assert_includes @response.body, active_user['email']
+      end
+    end
+  end
+
+  [
+    'admin',
+    'active',
+  ].each do |username|
+    test "access settings drop down menu as #{username}" do
+      admin_user = api_fixture('users','admin')
+      active_user = api_fixture('users','active')
+      get :show, {
+        id: api_fixture('users')[username]['uuid']
+      }, session_for(username)
+      if username == 'admin'
+        assert_includes @response.body, admin_user['email']
+        refute_empty css_select('[id="system-menu"]')
+      else
+        assert_includes @response.body, active_user['email']
+        assert_empty css_select('[id="system-menu"]')
+      end
+    end
   end
 end