docbrown/spec/requests/api/v1/readinglist_spec.rb
Anna Buianova 7d053471f8
Rubocop fixes in spec/requests (#18946)
* Rubocop fixes in spec/requests

* Fixed spec/requests/api/v0/articles_spec.rb

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
2023-01-12 19:10:16 +03:00

60 lines
2 KiB
Ruby

require "rails_helper"
RSpec.describe "Api::V1::ReadingList" do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:api_secret) { create(:api_secret, user: user) }
let(:headers) do
{
"api-key" => api_secret.secret,
"content-type" => "application/json",
"Accept" => "application/vnd.forem.api-v1+json"
}
end
describe "GET /api/readinglist" do
let(:readinglist) { create_list(:reading_reaction, 3, user: user) }
context "when unauthenticated" do
it "returns unauthorized" do
get api_readinglist_index_path, headers: { "Accept" => "application/vnd.forem.api-v1+json" }
expect(response).to have_http_status(:unauthorized)
end
end
context "when unauthorized" do
it "returns unauthorized" do
get api_readinglist_index_path, headers: headers.merge({ "api-key" => "invalid api key" })
expect(response).to have_http_status(:unauthorized)
end
end
context "when request is authenticated" do
it "returns proper response specification" do
get api_readinglist_index_path, headers: headers
expect(response.media_type).to eq("application/json")
expect(response).to have_http_status(:ok)
end
it "doesn't return archived reactions" do
create(:reading_reaction, user: user)
create(:reading_reaction, user: user, status: :archived)
get api_readinglist_index_path, headers: headers
expect(response.parsed_body.length).to eq(1)
end
it "supports pagination" do
create_list(:reading_reaction, 3, user: user)
get api_readinglist_index_path, headers: headers, params: { page: 2, per_page: 2 }
expect(response.parsed_body.length).to eq(1)
end
it "doesn't return reading list items from other users" do
create_list(:reading_reaction, 3, user: user)
create_list(:reading_reaction, 2, user: user2)
get api_readinglist_index_path, headers: headers
expect(response.parsed_body.length).to eq(3)
end
end
end
end