* Refactor user_same_as_json_ld method to be more readable * Refactor user JSON-LD to be less verbose in Stories::Controller * Removes set_user_same_as_json_ld method * Removes set_user_profile_json_ld method * Adds user_works_for and user_disambiguating_description * Adds inline logic to the data structure * Simplifies user_same_as method * Add documentation around specific data properties * Add .reject to user_json_ld to remove key, value if value blank * Checks for blank values and rejects key,value if blank * Accounts for JSON-LD preference for no key,value if blank * Add reject and compact to worksFor in Stories::Controller * Ensures any nil/empty values for worksFor are removed * Cleans up existing code within Stories::Controller * Add test for values that eval to true when .blank? is called * Adds test to check that empty key/values are not included * Adds test to check that nil key/values are not included * Refactors variables to be inline in user_show_spec * Refactors existing code in user_show_spec * Add reject for blank values to user_same_as in Stories::Contrroller * Adds a check for email_public to email * Fix typo within comment in Stories::Controller * Add ternary operation to email in Stories::Controller
110 lines
3.1 KiB
Ruby
110 lines
3.1 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "UserShow", type: :request do
|
|
let_it_be(:user) { create(:user, :with_all_info, email_public: true) }
|
|
|
|
describe "GET /:slug (user)" do
|
|
it "returns a 200 status when navigating to the user's page" do
|
|
get user.path
|
|
expect(response).to have_http_status(:ok)
|
|
end
|
|
|
|
# rubocop:disable RSpec/ExampleLength
|
|
it "renders the proper JSON-LD for a user" do
|
|
get user.path
|
|
text = Nokogiri::HTML(response.body).at('script[type="application/ld+json"]').text
|
|
response_json = JSON.parse(text)
|
|
expect(response_json).to include(
|
|
"@context" => "http://schema.org",
|
|
"@type" => "Person",
|
|
"mainEntityOfPage" => {
|
|
"@type" => "WebPage",
|
|
"@id" => URL.user(user)
|
|
},
|
|
"url" => URL.user(user),
|
|
"sameAs" => [
|
|
"https://twitter.com/#{user.twitter_username}",
|
|
"https://github.com/#{user.github_username}",
|
|
user.mastodon_url,
|
|
user.facebook_url,
|
|
user.youtube_url,
|
|
user.linkedin_url,
|
|
user.behance_url,
|
|
user.stackoverflow_url,
|
|
user.dribbble_url,
|
|
user.medium_url,
|
|
user.gitlab_url,
|
|
user.instagram_url,
|
|
user.twitch_username,
|
|
user.website_url,
|
|
],
|
|
"image" => ProfileImage.new(user).get(width: 320),
|
|
"name" => user.name,
|
|
"email" => user.email,
|
|
"jobTitle" => user.employment_title,
|
|
"description" => user.summary,
|
|
"disambiguatingDescription" => [
|
|
user.mostly_work_with,
|
|
user.currently_hacking_on,
|
|
user.currently_learning,
|
|
],
|
|
"worksFor" => [
|
|
{
|
|
"@type" => "Organization",
|
|
"name" => user.employer_name,
|
|
"url" => user.employer_url
|
|
},
|
|
],
|
|
"alumniOf" => user.education,
|
|
)
|
|
end
|
|
# rubocop:enable RSpec/ExampleLength
|
|
|
|
it "does not render a key if no value is given" do
|
|
incomplete_user = create(:user)
|
|
get incomplete_user.path
|
|
text = Nokogiri::HTML(response.body).at('script[type="application/ld+json"]').text
|
|
response_json = JSON.parse(text)
|
|
expect(response_json).not_to include("worksFor")
|
|
expect(response_json.value?(nil)).to be(false)
|
|
expect(response_json.value?("")).to be(false)
|
|
end
|
|
end
|
|
|
|
context "when user signed in" do
|
|
before do
|
|
sign_in user
|
|
get user.path
|
|
end
|
|
|
|
describe "GET /:slug (user)" do
|
|
it "does not render json ld" do
|
|
expect(response.body).not_to include "application/ld+json"
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when user not signed in" do
|
|
before do
|
|
get user.path
|
|
end
|
|
|
|
describe "GET /:slug (user)" do
|
|
it "does not render json ld" do
|
|
expect(response.body).to include "application/ld+json"
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when user not signed in but internal nav triggered" do
|
|
before do
|
|
get user.path + "?i=i"
|
|
end
|
|
|
|
describe "GET /:slug (user)" do
|
|
it "does not render json ld" do
|
|
expect(response.body).not_to include "application/ld+json"
|
|
end
|
|
end
|
|
end
|
|
end
|