docbrown/spec/requests/api/v0/profile_images_spec.rb
Diogo Osório 2b72a35d3d
[deploy] Introduce /api/profile_images/:username endpoint (#10547)
* Documents the new /profile-images/:username API endpoint

* Introduces the /api/profile_images/:username endpoint

This endpoint receives either an user or organization username as input
via the URL path and returns the profile image information for that
user/orgnization.

* Updates the /api/profile_images/:username response

Adapts the response according to the review comments:

1. Removes the cache directives
1. Tweaks how the user query is being done
1. Adds a `image_of` property to the response

* Bump API version

Co-authored-by: rhymes <rhymes@hey.com>
Co-authored-by: Molly Struve <mollylbs@gmail.com>
2020-10-14 14:24:25 -05:00

55 lines
1.7 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" => profile_image(user.profile_image_url, 640),
"profile_image_90" => profile_image(user.profile_image_url, 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" => profile_image(organization.profile_image_url, 640),
"profile_image_90" => profile_image(organization.profile_image_url, 90),
)
end
end
end
def profile_image(url, length)
Images::Profile.call(url, length: length)
end
end