* Remove duplicated work display from header * Update work profile field handling * Update DUS + spec * Delegate more carefully * Update delegation guard * Adapt for removed delegation * Undo accidental schema changes * Fix seeds * Remove accidentaly change * Fix User#processed_website_url * Update guard clause * Update profile card content * Add Organization#profile * Be more conservative with profile fields * Spec fixes round 1 * Fix typo * Update spec * Limit number of header fields and update card content * Decorate correct model * Update factory * Update schema.rb * Fix validation * How bad could this possibly be? * Pretty bad, nevermind * Remove obsolete code * Reset profile fields during test runs * Move profile fields back to before(:suite) * Spec fixes * Remove accidentally re-added files * More spec fixes * Specs * Change User#tag_keywords_for_search * More spec fixes * Add comment * Undo accidental schema changes * Attempt spec fix * Remove fix attempt * Fix e2e test * Update spec * Remove guard clause * Remove hardcoded instances of education field * WIP Access display_email_on_profile via User Settings * Remove unused profile column * WIP fix issues revealed by systems specs * WIP fix issues revealed by services specs * WIP Fix failing tests * WIP Fix spec failures * wip * Move two attributes from controller to decorator * Update comment * More consistently use user.tag_line Even before the profile changes we sometimes used the user.summary attribute directly but used the user.tag_line method in other places. * Remove education * Add comment * WIP * Clean up mostly_work_with * WIP * Update work profile field handling * More work-related changes * Remove settings_only from display_area enum * Remove quickfix from _metadata partial * Remove special attributes * Remove leftover spec * Retrieve location from profile, not user * Profile.special_attributes no longer exists * Update specs * More spec fixes * Update UsersController * Update UsersController and spec * Fix e2e seeds * Minor cleanup * More e2e seed fixes * Fix profile field CSV * Fix e2e seeds * Move one more attribute in e2e seeds * Remove duplicate line * Clear inputs before typing in them Co-authored-by: Jacob Herrington <jacobherringtondeveloper@gmail.com>
110 lines
4 KiB
Ruby
110 lines
4 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "Api::V0::Users", type: :request do
|
|
describe "GET /api/users/:id" do
|
|
let!(:user) do
|
|
create(:user,
|
|
profile_image: "",
|
|
_skip_creating_profile: true,
|
|
profile: create(:profile, summary: "Something something"))
|
|
end
|
|
|
|
it "returns 404 if the user id is not found" do
|
|
get api_user_path("invalid-id")
|
|
|
|
expect(response).to have_http_status(:not_found)
|
|
end
|
|
|
|
it "returns 404 if the user username is not found" do
|
|
get api_user_path("by_username"), params: { url: "invalid-username" }
|
|
expect(response).to have_http_status(:not_found)
|
|
end
|
|
|
|
it "returns 404 if the user is not registered" do
|
|
user.update_column(:registered, false)
|
|
get api_user_path(user.id)
|
|
expect(response).to have_http_status(:not_found)
|
|
end
|
|
|
|
it "returns 200 if the user username is found" do
|
|
get api_user_path("by_username"), params: { url: user.username }
|
|
expect(response).to have_http_status(:ok)
|
|
end
|
|
|
|
it "returns unauthenticated if no authentication and the Forem instance is set to private" do
|
|
allow(Settings::UserExperience).to receive(:public).and_return(false)
|
|
get api_user_path("by_username"), params: { url: user.username }
|
|
expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
|
|
it "returns the correct json representation of the user", :aggregate_failures do
|
|
get api_user_path(user.id)
|
|
|
|
response_user = response.parsed_body
|
|
|
|
expect(response_user["type_of"]).to eq("user")
|
|
|
|
%w[id username name twitter_username github_username].each do |attr|
|
|
expect(response_user[attr]).to eq(user.public_send(attr))
|
|
end
|
|
|
|
%w[summary website_url location].each do |attr|
|
|
expect(response_user[attr]).to eq(user.profile.public_send(attr))
|
|
end
|
|
|
|
expect(response_user["joined_at"]).to eq(user.created_at.strftime("%b %e, %Y"))
|
|
expect(response_user["profile_image"]).to eq(Images::Profile.call(user.profile_image_url, length: 320))
|
|
end
|
|
end
|
|
|
|
describe "GET /api/users/me" do
|
|
it "requires request to be authenticated" do
|
|
get me_api_users_path
|
|
expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
|
|
context "when request is authenticated" do
|
|
let(:user) { create(:user) }
|
|
let(:access_token) { create(:doorkeeper_access_token, resource_owner: user, scopes: "public") }
|
|
|
|
it "returns the correct json representation of the user", :aggregate_failures do
|
|
get me_api_users_path, params: { access_token: access_token.token }
|
|
|
|
response_user = response.parsed_body
|
|
|
|
expect(response_user["type_of"]).to eq("user")
|
|
|
|
%w[id username name twitter_username github_username].each do |attr|
|
|
expect(response_user[attr]).to eq(user.public_send(attr))
|
|
end
|
|
|
|
%w[summary website_url location].each do |attr|
|
|
expect(response_user[attr]).to eq(user.profile.public_send(attr))
|
|
end
|
|
|
|
expect(response_user["joined_at"]).to eq(user.created_at.strftime("%b %e, %Y"))
|
|
expect(response_user["profile_image"]).to eq(Images::Profile.call(user.profile_image_url, length: 320))
|
|
end
|
|
|
|
it "returns 200 if no authentication and the Forem instance is set to private but user is authenticated" do
|
|
allow(Settings::UserExperience).to receive(:public).and_return(false)
|
|
get me_api_users_path, params: { access_token: access_token.token }
|
|
|
|
response_user = response.parsed_body
|
|
|
|
expect(response_user["type_of"]).to eq("user")
|
|
|
|
%w[id username name twitter_username github_username].each do |attr|
|
|
expect(response_user[attr]).to eq(user.public_send(attr))
|
|
end
|
|
|
|
%w[summary website_url location].each do |attr|
|
|
expect(response_user[attr]).to eq(user.profile.public_send(attr))
|
|
end
|
|
|
|
expect(response_user["joined_at"]).to eq(user.created_at.strftime("%b %e, %Y"))
|
|
expect(response_user["profile_image"]).to eq(Images::Profile.call(user.profile_image_url, length: 320))
|
|
end
|
|
end
|
|
end
|
|
end
|