docbrown/spec/requests/user/user_suggestions_spec.rb
Michael Kohl 1ebec4b67f
Remove hardcoded user profile fields (#14079)
* 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>
2021-08-18 11:44:53 +07:00

106 lines
3.4 KiB
Ruby

require "rails_helper"
RSpec.describe "Users", type: :request do
describe "GET /users" do
let(:user) { create(:user, username: "Sloan") }
let!(:suggested_users_list) { %w[eeyore] }
let!(:suggested_user_profile) do
create(
:profile,
user: create(:user, :without_profile, username: "eeyore", name: "Eeyore"),
summary: "I am always sad",
)
end
let!(:suggested_user) { suggested_user_profile.user }
before do
allow(Settings::General).to receive(:suggested_users).and_return(suggested_users_list)
end
context "when no state params are present" do
it "returns no users" do
sign_in user
get users_path
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to be_empty
end
end
context "when follow_suggestions params are present and no suggestions are found" do
it "returns the default suggested_users from Settings::General if they are present" do
sign_in user
get users_path(state: "follow_suggestions")
expect(response).to have_http_status(:ok)
expect(response.parsed_body.first).to include(
"id" => suggested_user.id,
"name" => suggested_user.name,
"username" => suggested_user.username,
"summary" => suggested_user.profile.summary,
"profile_image_url" => Images::Profile.call(suggested_user.profile_image_url, length: 90),
"following" => false,
)
end
end
context "when follow_suggestions params are present" do
let(:user) { create(:user) }
let(:tag) { create(:tag) }
let(:other_user) { create(:user) }
before do
# Prepare auto-generated user suggestions
user.follow(tag)
create(:article, user: other_user, tags: [tag.name])
end
it "returns follow suggestions for an authenticated user" do
sign_in user
get users_path(state: "follow_suggestions")
response_user = response.parsed_body.first
expect(response_user["id"]).to eq(other_user.id)
end
it "returns follow suggestions that have profile images" do
sign_in user
get users_path(state: "follow_suggestions")
response_user = response.parsed_body.first
expect(response_user["profile_image_url"]).to eq(other_user.profile_image_url)
end
it "returns the default suggested_users from Settings::General if prefer_manual_suggested_users is true" do
allow(Settings::General).to receive(:prefer_manual_suggested_users).and_return(true)
sign_in user
get users_path(state: "follow_suggestions")
expect(response).to have_http_status(:ok)
expect(response.parsed_body.first).to include(
"id" => suggested_user.id,
"name" => suggested_user.name,
"username" => suggested_user.username,
"summary" => suggested_user.profile.summary,
"profile_image_url" => Images::Profile.call(suggested_user.profile_image_url, length: 90),
"following" => false,
)
end
end
context "when sidebar_suggestions params are present" do
it "returns no sidebar suggestions for an authenticated user" do
sign_in create(:user)
get users_path(state: "sidebar_suggestions")
expect(response.parsed_body).to be_empty
end
end
end
end