Commit b03d485aedc31dfb031d80c86359e3f184154ed0
Committed by
Leandro Santos
1 parent
63924055
Exists in
staging
and in
31 other branches
Refactor for anonymous tests
Showing
1 changed file
with
28 additions
and
1 deletions
Show diff stats
test/api/people_test.rb
... | ... | @@ -4,10 +4,10 @@ class PeopleTest < ActiveSupport::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | 6 | Person.delete_all |
7 | - login_api | |
8 | 7 | end |
9 | 8 | |
10 | 9 | should 'list all people' do |
10 | + login_api | |
11 | 11 | person1 = fast_create(Person, :public_profile => true) |
12 | 12 | person2 = fast_create(Person) |
13 | 13 | get "/api/v1/people?#{params.to_query}" |
... | ... | @@ -16,6 +16,7 @@ class PeopleTest < ActiveSupport::TestCase |
16 | 16 | end |
17 | 17 | |
18 | 18 | should 'list all members of a community' do |
19 | + login_api | |
19 | 20 | person1 = fast_create(Person) |
20 | 21 | person2 = fast_create(Person) |
21 | 22 | community = fast_create(Community) |
... | ... | @@ -29,6 +30,7 @@ class PeopleTest < ActiveSupport::TestCase |
29 | 30 | end |
30 | 31 | |
31 | 32 | should 'not list invisible people' do |
33 | + login_api | |
32 | 34 | invisible_person = fast_create(Person, :visible => false) |
33 | 35 | |
34 | 36 | get "/api/v1/people?#{params.to_query}" |
... | ... | @@ -36,6 +38,7 @@ class PeopleTest < ActiveSupport::TestCase |
36 | 38 | end |
37 | 39 | |
38 | 40 | should 'list private people' do |
41 | + login_api | |
39 | 42 | private_person = fast_create(Person, :public_profile => false) |
40 | 43 | |
41 | 44 | get "/api/v1/people?#{params.to_query}" |
... | ... | @@ -43,6 +46,7 @@ class PeopleTest < ActiveSupport::TestCase |
43 | 46 | end |
44 | 47 | |
45 | 48 | should 'list private person for friends' do |
49 | + login_api | |
46 | 50 | p1 = fast_create(Person) |
47 | 51 | p2 = fast_create(Person, :public_profile => false) |
48 | 52 | person.add_friend(p2) |
... | ... | @@ -53,6 +57,7 @@ class PeopleTest < ActiveSupport::TestCase |
53 | 57 | end |
54 | 58 | |
55 | 59 | should 'get person' do |
60 | + login_api | |
56 | 61 | some_person = fast_create(Person) |
57 | 62 | |
58 | 63 | get "/api/v1/people/#{some_person.id}?#{params.to_query}" |
... | ... | @@ -61,6 +66,7 @@ class PeopleTest < ActiveSupport::TestCase |
61 | 66 | end |
62 | 67 | |
63 | 68 | should 'people endpoint filter by fields parameter' do |
69 | + login_api | |
64 | 70 | get "/api/v1/people?#{params.to_query}&fields=name" |
65 | 71 | json = JSON.parse(last_response.body) |
66 | 72 | expected = {'people' => [{'name' => person.name}]} |
... | ... | @@ -68,6 +74,7 @@ class PeopleTest < ActiveSupport::TestCase |
68 | 74 | end |
69 | 75 | |
70 | 76 | should 'people endpoint filter by fields parameter with hierarchy' do |
77 | + login_api | |
71 | 78 | fields = URI.encode({only: [:name, {user: [:login]}]}.to_json.to_str) |
72 | 79 | get "/api/v1/people?#{params.to_query}&fields=#{fields}" |
73 | 80 | json = JSON.parse(last_response.body) |
... | ... | @@ -76,12 +83,14 @@ class PeopleTest < ActiveSupport::TestCase |
76 | 83 | end |
77 | 84 | |
78 | 85 | should 'get logged person' do |
86 | + login_api | |
79 | 87 | get "/api/v1/people/me?#{params.to_query}" |
80 | 88 | json = JSON.parse(last_response.body) |
81 | 89 | assert_equal person.id, json['person']['id'] |
82 | 90 | end |
83 | 91 | |
84 | 92 | should 'me endpoint filter by fields parameter' do |
93 | + login_api | |
85 | 94 | get "/api/v1/people/me?#{params.to_query}&fields=name" |
86 | 95 | json = JSON.parse(last_response.body) |
87 | 96 | expected = {'person' => {'name' => person.name}} |
... | ... | @@ -89,6 +98,7 @@ class PeopleTest < ActiveSupport::TestCase |
89 | 98 | end |
90 | 99 | |
91 | 100 | should 'not get invisible person' do |
101 | + login_api | |
92 | 102 | person = fast_create(Person, :visible => false) |
93 | 103 | |
94 | 104 | get "/api/v1/people/#{person.id}?#{params.to_query}" |
... | ... | @@ -97,6 +107,7 @@ class PeopleTest < ActiveSupport::TestCase |
97 | 107 | end |
98 | 108 | |
99 | 109 | should 'get private people' do |
110 | + login_api | |
100 | 111 | private_person = fast_create(Person, :public_profile => false) |
101 | 112 | |
102 | 113 | get "/api/v1/people/#{private_person.id}?#{params.to_query}" |
... | ... | @@ -105,6 +116,7 @@ class PeopleTest < ActiveSupport::TestCase |
105 | 116 | end |
106 | 117 | |
107 | 118 | should 'get private person for friends' do |
119 | + login_api | |
108 | 120 | private_person = fast_create(Person, :public_profile => false) |
109 | 121 | person.add_friend(private_person) |
110 | 122 | private_person.add_friend(person) |
... | ... | @@ -115,6 +127,7 @@ class PeopleTest < ActiveSupport::TestCase |
115 | 127 | end |
116 | 128 | |
117 | 129 | should 'list person friends' do |
130 | + login_api | |
118 | 131 | friend = fast_create(Person) |
119 | 132 | person.add_friend(friend) |
120 | 133 | friend.add_friend(person) |
... | ... | @@ -123,6 +136,7 @@ class PeopleTest < ActiveSupport::TestCase |
123 | 136 | end |
124 | 137 | |
125 | 138 | should 'not list person invisible friends' do |
139 | + login_api | |
126 | 140 | friend = fast_create(Person) |
127 | 141 | invisible_friend = fast_create(Person, :visible => false) |
128 | 142 | person.add_friend(friend) |
... | ... | @@ -137,6 +151,7 @@ class PeopleTest < ActiveSupport::TestCase |
137 | 151 | end |
138 | 152 | |
139 | 153 | should 'create a person' do |
154 | + login_api | |
140 | 155 | login = 'some' |
141 | 156 | params[:person] = {:login => login, :password => '123456', :password_confirmation => '123456', :email => 'some@some.com'} |
142 | 157 | post "/api/v1/people?#{params.to_query}" |
... | ... | @@ -145,6 +160,7 @@ class PeopleTest < ActiveSupport::TestCase |
145 | 160 | end |
146 | 161 | |
147 | 162 | should 'return 400 status for invalid person creation' do |
163 | + login_api | |
148 | 164 | params[:person] = {:login => 'some'} |
149 | 165 | post "/api/v1/people?#{params.to_query}" |
150 | 166 | json = JSON.parse(last_response.body) |
... | ... | @@ -152,6 +168,7 @@ class PeopleTest < ActiveSupport::TestCase |
152 | 168 | end |
153 | 169 | |
154 | 170 | should 'display permissions' do |
171 | + login_api | |
155 | 172 | community = fast_create(Community) |
156 | 173 | community.add_member(fast_create(Person)) |
157 | 174 | community.add_member(person) |
... | ... | @@ -163,11 +180,13 @@ class PeopleTest < ActiveSupport::TestCase |
163 | 180 | end |
164 | 181 | |
165 | 182 | should 'display permissions if self' do |
183 | + login_api | |
166 | 184 | get "/api/v1/people/#{person.id}/permissions?#{params.to_query}" |
167 | 185 | assert_equal 200, last_response.status |
168 | 186 | end |
169 | 187 | |
170 | 188 | should 'display permissions if admin' do |
189 | + login_api | |
171 | 190 | environment = person.environment |
172 | 191 | environment.add_admin(person) |
173 | 192 | some_person = fast_create(Person) |
... | ... | @@ -177,6 +196,7 @@ class PeopleTest < ActiveSupport::TestCase |
177 | 196 | end |
178 | 197 | |
179 | 198 | should 'not display permissions if not admin or self' do |
199 | + login_api | |
180 | 200 | some_person = create_user('some-person').person |
181 | 201 | |
182 | 202 | get "/api/v1/people/#{some_person.id}/permissions?#{params.to_query}" |
... | ... | @@ -184,12 +204,14 @@ class PeopleTest < ActiveSupport::TestCase |
184 | 204 | end |
185 | 205 | |
186 | 206 | should 'not update another person' do |
207 | + login_api | |
187 | 208 | person = fast_create(Person, :environment_id => environment.id) |
188 | 209 | post "/api/v1/people/#{person.id}?#{params.to_query}" |
189 | 210 | assert_equal 403, last_response.status |
190 | 211 | end |
191 | 212 | |
192 | 213 | should 'update yourself' do |
214 | + login_api | |
193 | 215 | another_name = 'Another Name' |
194 | 216 | params[:person] = {} |
195 | 217 | params[:person][:name] = another_name |
... | ... | @@ -200,6 +222,7 @@ class PeopleTest < ActiveSupport::TestCase |
200 | 222 | end |
201 | 223 | |
202 | 224 | should 'display public custom fields' do |
225 | + login_api | |
203 | 226 | CustomField.create!(:name => "Custom Blog", :format => "string", :customized_type => "Person", :active => true, :environment => Environment.default) |
204 | 227 | some_person = create_user('some-person').person |
205 | 228 | some_person.custom_values = { "Custom Blog" => { "value" => "www.blog.org", "public" => "true"} } |
... | ... | @@ -212,6 +235,7 @@ class PeopleTest < ActiveSupport::TestCase |
212 | 235 | end |
213 | 236 | |
214 | 237 | should 'not display non-public custom fields' do |
238 | + login_api | |
215 | 239 | CustomField.create!(:name => "Custom Blog", :format => "string", :customized_type => "Person", :active => true, :environment => Environment.default) |
216 | 240 | some_person = create_user('some-person').person |
217 | 241 | some_person.custom_values = { "Custom Blog" => { "value" => "www.blog.org", "public" => "0"} } |
... | ... | @@ -223,6 +247,7 @@ class PeopleTest < ActiveSupport::TestCase |
223 | 247 | end |
224 | 248 | |
225 | 249 | should 'display non-public custom fields to friend' do |
250 | + login_api | |
226 | 251 | CustomField.create!(:name => "Custom Blog", :format => "string", :customized_type => "Person", :active => true, :environment => Environment.default) |
227 | 252 | some_person = create_user('some-person').person |
228 | 253 | some_person.custom_values = { "Custom Blog" => { "value" => "www.blog.org", "public" => "0"} } |
... | ... | @@ -243,12 +268,14 @@ class PeopleTest < ActiveSupport::TestCase |
243 | 268 | |
244 | 269 | PERSON_ATTRIBUTES.map do |attribute| |
245 | 270 | define_method "test_should_not_expose_#{attribute}_attribute_in_person_enpoint_if_field_parameter_does_not_contain_the_attribute" do |
271 | + login_api | |
246 | 272 | get "/api/v1/people/me?#{params.to_query}&fields=name" |
247 | 273 | json = JSON.parse(last_response.body) |
248 | 274 | assert_nil json['person'][attribute] |
249 | 275 | end |
250 | 276 | |
251 | 277 | define_method "test_should_expose_#{attribute}_attribute_in_person_enpoints_if_field_parameter_is_passed" do |
278 | + login_api | |
252 | 279 | get "/api/v1/people/me?#{params.to_query}&fields=#{attribute}" |
253 | 280 | json = JSON.parse(last_response.body) |
254 | 281 | assert_not_nil json['person'][attribute] | ... | ... |