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