- assert_select "description", :count => 1, :text => "test"
- assert_select "contributor-terms", :count => 1 do
- assert_select "[agreed='true'][pd='false']"
- end
- assert_select "img", :count => 0
- assert_select "roles", :count => 1 do
- assert_select "role", :count => 0
- end
- assert_select "changesets", :count => 1 do
- assert_select "[count='0']", :count => 1
- end
- assert_select "traces", :count => 1 do
- assert_select "[count='0']", :count => 1
- end
- assert_select "blocks", :count => 1 do
- assert_select "received", :count => 1 do
- assert_select "[count='0'][active='0']"
- end
- assert_select "issued", :count => 0
- end
- assert_select "home", :count => 1 do
- assert_select "[lat='12.1'][lon='12.1'][zoom='3']"
+ check_xml_details(user, true, false)
+
+ # check that data is returned properly in json
+ auth_header = bearer_authorization_header user
+ get api_user_details_path(:format => "json"), :headers => auth_header
+ assert_response :success
+ assert_equal "application/json", response.media_type
+
+ # parse the response
+ js = ActiveSupport::JSON.decode(@response.body)
+ assert_not_nil js
+
+ # check the data that is returned
+ check_json_details(js, user, true, false)
+ end
+
+ def test_details_oauth2
+ user = create(:user,
+ :home_lat => 12.1, :home_lon => 23.4,
+ :languages => ["en"])
+ good_auth = bearer_authorization_header(user, :scopes => %w[read_prefs])
+ bad_auth = bearer_authorization_header(user, :scopes => %w[])
+ email_auth = bearer_authorization_header(user, :scopes => %w[read_prefs read_email])
+
+ # check that we can't fetch details as XML without read_prefs
+ get api_user_details_path, :headers => bad_auth
+ assert_response :forbidden
+
+ # check that we can fetch details as XML without read_email
+ get api_user_details_path, :headers => good_auth
+ assert_response :success
+ assert_equal "application/xml", response.media_type
+
+ # check the data that is returned
+ check_xml_details(user, true, false)
+
+ # check that we can fetch details as XML with read_email
+ get api_user_details_path, :headers => email_auth
+ assert_response :success
+ assert_equal "application/xml", response.media_type
+
+ # check the data that is returned
+ check_xml_details(user, true, true)
+
+ # check that we can't fetch details as JSON without read_prefs
+ get api_user_details_path(:format => "json"), :headers => bad_auth
+ assert_response :forbidden
+
+ # check that we can fetch details as JSON without read_email
+ get api_user_details_path(:format => "json"), :headers => good_auth
+ assert_response :success
+ assert_equal "application/json", response.media_type
+
+ # parse the response
+ js = ActiveSupport::JSON.decode(@response.body)
+ assert_not_nil js
+
+ # check the data that is returned
+ check_json_details(js, user, true, false)
+
+ # check that we can fetch details as JSON with read_email
+ get api_user_details_path(:format => "json"), :headers => email_auth
+ assert_response :success
+ assert_equal "application/json", response.media_type
+
+ # parse the response
+ js = ActiveSupport::JSON.decode(@response.body)
+ assert_not_nil js
+
+ # check the data that is returned
+ check_json_details(js, user, true, true)
+ end
+
+ def test_index
+ user1 = create(:user, :description => "test1", :terms_agreed => Date.yesterday)
+ user2 = create(:user, :description => "test2", :terms_agreed => Date.yesterday)
+ user3 = create(:user, :description => "test3", :terms_agreed => Date.yesterday)
+
+ get api_users_path, :params => { :users => user1.id }
+ assert_response :success
+ assert_equal "application/xml", response.media_type
+ assert_select "user", :count => 1 do
+ check_xml_details(user1, false, false)
+ assert_select "user[id='#{user2.id}']", :count => 0
+ assert_select "user[id='#{user3.id}']", :count => 0