* 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>
168 lines
6.7 KiB
Ruby
168 lines
6.7 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "Api::V0::Organizations", type: :request do
|
|
describe "GET /api/organizations/:username" do
|
|
let(:organization) { create(:organization) }
|
|
|
|
it "returns 404 if the organizations username is not found" do
|
|
get "/api/organizations/invalid-username"
|
|
expect(response).to have_http_status(:not_found)
|
|
end
|
|
|
|
it "returns the correct json representation of the organization", :aggregate_failures do
|
|
get api_organization_path(organization.username)
|
|
|
|
response_organization = response.parsed_body
|
|
expect(response_organization).to include(
|
|
{
|
|
"profile_image" => organization.profile_image_url,
|
|
"type_of" => "organization",
|
|
"joined_at" => organization.created_at.utc.iso8601
|
|
},
|
|
)
|
|
|
|
%w[
|
|
username name summary twitter_username github_username url location tech_stack tag_line story
|
|
].each do |attr|
|
|
expect(response_organization[attr]).to eq(organization.public_send(attr))
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "GET /api/organizations/:username/users" do
|
|
let!(:org_user) { create(:user, :org_member) }
|
|
let(:organization) { org_user.organizations.first }
|
|
|
|
it "returns 404 if the organizations username is not found" do
|
|
get "/api/organizations/invalid-username/users"
|
|
expect(response).to have_http_status(:not_found)
|
|
end
|
|
|
|
it "supports pagination" do
|
|
create(:organization_membership, user: create(:user), organization: organization)
|
|
|
|
get api_organization_users_path(organization.username), params: { page: 1, per_page: 1 }
|
|
expect(response.parsed_body.length).to eq(1)
|
|
|
|
get api_organization_users_path(organization.username), params: { page: 2, per_page: 1 }
|
|
expect(response.parsed_body.length).to eq(1)
|
|
|
|
get api_organization_users_path(organization.username), params: { page: 3, per_page: 1 }
|
|
expect(response.parsed_body.length).to eq(0)
|
|
end
|
|
|
|
it "returns the correct json representation of the organizations users", :aggregate_failures do
|
|
get api_organization_users_path(organization.username)
|
|
|
|
response_org_users = response.parsed_body.first
|
|
|
|
expect(response_org_users["type_of"]).to eq("user")
|
|
|
|
%w[id username name twitter_username github_username].each do |attr|
|
|
expect(response_org_users[attr]).to eq(org_user.public_send(attr))
|
|
end
|
|
|
|
org_user_profile = org_user.profile
|
|
%w[summary location website_url].each do |attr|
|
|
expect(response_org_users[attr]).to eq(org_user_profile.public_send(attr))
|
|
end
|
|
|
|
expect(response_org_users["joined_at"]).to eq(org_user.created_at.strftime("%b %e, %Y"))
|
|
expect(response_org_users["profile_image"]).to eq(Images::Profile.call(org_user.profile_image_url, length: 320))
|
|
end
|
|
end
|
|
|
|
describe "GET /api/organizations/:username/listings" do
|
|
let(:org_user) { create(:user, :org_member) }
|
|
let(:organization) { org_user.organizations.first }
|
|
let!(:listing) { create(:listing, user: org_user, organization: organization) }
|
|
|
|
it "returns 404 if the organizations username is not found" do
|
|
get "/api/organizations/invalid-username/listings"
|
|
expect(response).to have_http_status(:not_found)
|
|
end
|
|
|
|
it "supports pagination" do
|
|
create(:listing, user: org_user, organization: organization)
|
|
|
|
get api_organization_listings_path(organization.username), params: { page: 1, per_page: 1 }
|
|
expect(response.parsed_body.length).to eq(1)
|
|
|
|
get api_organization_listings_path(organization.username), params: { page: 2, per_page: 1 }
|
|
expect(response.parsed_body.length).to eq(1)
|
|
|
|
get api_organization_listings_path(organization.username), params: { page: 3, per_page: 1 }
|
|
expect(response.parsed_body.length).to eq(0)
|
|
end
|
|
|
|
it "returns the correct json representation of the organizations listings", :aggregate_failures do
|
|
get api_organization_listings_path(organization.username)
|
|
response_listing = response.parsed_body.first
|
|
expect(response_listing["type_of"]).to eq("listing")
|
|
|
|
%w[id title slug body_markdown category processed_html published listing_category_id].each do |attr|
|
|
expect(response_listing[attr]).to eq(listing.public_send(attr))
|
|
end
|
|
|
|
expect(response_listing["tag_list"]).to eq(listing.cached_tag_list)
|
|
expect(response_listing["tags"]).to match_array(listing.tag_list)
|
|
|
|
%w[name username twitter_username github_username].each do |attr|
|
|
expect(response_listing["user"][attr]).to eq(org_user.public_send(attr))
|
|
end
|
|
|
|
expect(response_listing["organization"]["website_url"]).to eq(org_user.profile.website_url)
|
|
|
|
%w[name username slug].each do |attr|
|
|
expect(response_listing["organization"][attr]).to eq(organization.public_send(attr))
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "GET /api/organizations/:username/articles" do
|
|
let(:org_user) { create(:user, :org_member) }
|
|
let(:organization) { org_user.organizations.first }
|
|
let!(:article) { create(:article, user: org_user, organization: organization) }
|
|
|
|
it "returns 404 if the organizations articles is not found" do
|
|
get "/api/organizations/invalid-username/articles"
|
|
expect(response).to have_http_status(:not_found)
|
|
end
|
|
|
|
it "supports pagination" do
|
|
create(:article, organization: organization)
|
|
|
|
get api_organization_articles_path(organization.username), params: { page: 1, per_page: 1 }
|
|
expect(response.parsed_body.length).to eq(1)
|
|
|
|
get api_organization_articles_path(organization.username), params: { page: 2, per_page: 1 }
|
|
expect(response.parsed_body.length).to eq(1)
|
|
|
|
get api_organization_articles_path(organization.username), params: { page: 3, per_page: 1 }
|
|
expect(response.parsed_body.length).to eq(0)
|
|
end
|
|
|
|
it "returns the correct json representation of the organizations articles", :aggregate_failures do
|
|
get api_organization_articles_path(organization.username)
|
|
response_article = response.parsed_body.first
|
|
expect(response_article["type_of"]).to eq("article")
|
|
|
|
%w[id title slug description path public_reactions_count
|
|
positive_reactions_count comments_count published_timestamp].each do |attr|
|
|
expect(response_article[attr]).to eq(article.public_send(attr))
|
|
end
|
|
|
|
expect(response_article["tag_list"]).to match_array(article.tag_list)
|
|
|
|
%w[name username twitter_username github_username].each do |attr|
|
|
expect(response_article["user"][attr]).to eq(org_user.public_send(attr))
|
|
end
|
|
|
|
expect(response_article["user"]["website_url"]).to eq(org_user.profile.website_url)
|
|
|
|
%w[name username slug].each do |attr|
|
|
expect(response_article["organization"][attr]).to eq(organization.public_send(attr))
|
|
end
|
|
end
|
|
end
|
|
end
|