Fix a nil check
[arvados.git] / services / api / test / functional / arvados / v1 / users_controller_test.rb
1 require 'test_helper'
2
3 class Arvados::V1::UsersControllerTest < ActionController::TestCase
4
5   test "activate a user after signing UA" do
6     authorize_with :inactive_but_signed_user_agreement
7     get :current
8     assert_response :success
9     me = JSON.parse(@response.body)
10     post :activate, uuid: me['uuid']
11     assert_response :success
12     assert_not_nil assigns(:object)
13     me = JSON.parse(@response.body)
14     assert_equal true, me['is_active']
15   end
16
17   test "refuse to activate a user before signing UA" do
18     authorize_with :inactive
19     get :current
20     assert_response :success
21     me = JSON.parse(@response.body)
22     post :activate, uuid: me['uuid']
23     assert_response 403
24     get :current
25     assert_response :success
26     me = JSON.parse(@response.body)
27     assert_equal false, me['is_active']
28   end
29
30   test "activate an already-active user" do
31     authorize_with :active
32     get :current
33     assert_response :success
34     me = JSON.parse(@response.body)
35     post :activate, uuid: me['uuid']
36     assert_response :success
37     me = JSON.parse(@response.body)
38     assert_equal true, me['is_active']
39   end
40
41   test "create new user" do
42     authorize_with :admin
43     post :create, user: {
44       first_name: "test_first_name",
45       last_name: "test_last_name",
46                         email: "test@abc.com"
47     }
48     assert_response :success
49     created = JSON.parse(@response.body)
50     assert_equal 'test_first_name', created['first_name']
51     assert_not_nil created['uuid'], 'expected non-null uuid for the newly created user'
52     assert_not_nil created['email'], 'since email was given, expected non-nil email'
53     assert_nil created['identity_url'], 'even though email is provided, expected no identity_url since users_controller only creates user at this time'
54   end
55
56         test "create user with vm and repo" do
57     authorize_with :admin
58
59     post :create, {
60       repo_name: 'test_repo',
61                         vm_uuid: 'abcdefg',
62       user: {
63                     uuid: "shouldnotbeused",                
64                                 first_name: "in_create_test_first_name",
65                     last_name: "test_last_name",
66                                 email: "test@abc.com"
67       }
68     }
69     assert_response :success
70     created = JSON.parse(@response.body)
71     assert_equal 'in_create_test_first_name', created['first_name']
72     assert_not_nil created['uuid'], 'expected non-null uuid for the newly created user'
73     assert_not_nil created['email'], 'since email was given, expected non-nil email'
74     assert_nil created['identity_url'], 'even though email is provided, expected no identity_url since users_controller only creates user' 
75         end
76
77 end