docbrown/spec/requests/api/v0/profile_images_spec.rb
Jeremy Friesen a65954107f
Refactoring to add helper method (#16064)
* Refactoring to add helper method

Prior to this commit, we made view level calls to service modules.  This
refactor provides convenience methods on the model.

Furthermore, it addresses a few Rubocop violations that "come along for
the ride."

* Ensuring cached entity squaks like User

* Fixing broken spec

* Fixing typo
2022-01-12 11:21:44 -05:00

51 lines
1.6 KiB
Ruby

require "rails_helper"
RSpec.describe "Api::V0::ProfileImages", type: :request do
describe "GET /api/profile_images/:username" do
it "returns 404 if the username is not taken" do
get api_profile_image_path("invalid-username")
expect(response).to have_http_status(:not_found)
end
context "when the username relates to an user" do
let(:user) { create(:user) }
it "returns the user profile image information" do
get api_profile_image_path(user.username)
expect(response.parsed_body).to eq(
"type_of" => "profile_image",
"image_of" => "user",
"profile_image" => user.profile_image_url_for(length: 640),
"profile_image_90" => user.profile_image_url_for(length: 90),
)
end
end
context "when the username relates to an invited user" do
let(:user) { create(:user, :invited) }
it "returns a 404" do
get api_profile_image_path(user.username)
expect(response).to have_http_status(:not_found)
end
end
context "when the username relates to an organization" do
let(:organization) { create(:organization) }
it "returns the organization's profile image information" do
get api_profile_image_path(organization.username)
expect(response.parsed_body).to eq(
"type_of" => "profile_image",
"image_of" => "organization",
"profile_image" => organization.profile_image_url_for(length: 640),
"profile_image_90" => organization.profile_image_url_for(length: 90),
)
end
end
end
end