docbrown/spec/requests/api/v1/docs/reactions_spec.rb
Joshua Wehner 7f41dae631
Pages API: Read (get index+show) (#18970)
* Pages API pt 1 (read/get/index+show)

* Update spec/requests/api/v1/docs/pages_spec.rb

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

* Update spec/requests/api/v1/docs/pages_spec.rb

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

* API Key not required for index & show

* API Feature flag has long since been removed

* Page schema

* Fix spec broken by merge

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
2023-01-25 17:15:27 +01:00

121 lines
3.5 KiB
Ruby

require "rails_helper"
require "swagger_helper"
# rubocop:disable RSpec/EmptyExampleGroup
# rubocop:disable RSpec/VariableName
RSpec.describe "api/v1/reactions" do
let(:Accept) { "application/vnd.forem.api-v1+json" }
let(:api_secret) { create(:api_secret) }
let(:category) { "like" }
let(:reactable) { create(:article) }
let(:reaction) { reactable.reactions.create user: user, category: "like" }
let(:result) { ReactionHandler::Result.new reaction: reaction }
let(:user) { api_secret.user }
before do
user.add_role(:admin)
result.category = category
allow(ReactionHandler).to receive(:toggle).and_return(result)
end
path "/api/reactions/toggle" do
describe "post to toggle reaction" do
post("toggle reaction") do
tags "reactions"
description(<<-DESCRIBE.strip)
This endpoint allows the client to toggle the user's reaction to a specified reactable (eg, Article, Comment, or User). For examples:
* "Like"ing an Article will create a new "like" Reaction from the user for that Articles
* "Like"ing that Article a second time will remove the "like" from the user
DESCRIBE
produces "application/json"
parameter name: :category, in: :query, required: true, schema: {
type: :string,
enum: ReactionCategory.public
}
parameter name: :reactable_id, in: :query, required: true, schema: {
type: :integer,
format: :int32
}
parameter name: :reactable_type, in: :query, required: true, schema: {
type: :string,
enum: Reaction::REACTABLE_TYPES
}
let(:reactable_id) { reactable.id }
let(:reactable_type) { "Article" }
before do
result.action = "create"
end
response(200, "successful") do
let(:"api-key") { api_secret.secret }
add_examples
run_test!
end
response "401", "unauthorized" do
let(:"api-key") { "invalid" }
add_examples
run_test!
end
end
end
end
path "/api/reactions" do
describe "post to create reaction" do
post("create reaction") do
tags "reactions"
description(<<-DESCRIBE.strip)
This endpoint allows the client to create a reaction to a specified reactable (eg, Article, Comment, or User). For examples:
* "Like"ing an Article will create a new "like" Reaction from the user for that Articles
* "Like"ing that Article a second time will return the previous "like"
DESCRIBE
produces "application/json"
parameter name: :category, in: :query, required: true, schema: {
type: :string,
enum: ReactionCategory.public
}
parameter name: :reactable_id, in: :query, required: true, schema: {
type: :integer,
format: :int32
}
parameter name: :reactable_type, in: :query, required: true, schema: {
type: :string,
enum: Reaction::REACTABLE_TYPES
}
let(:reactable_id) { reactable.id }
let(:reactable_type) { "Article" }
before do
result.action = "create"
end
response(200, "successful") do
let(:"api-key") { api_secret.secret }
add_examples
run_test!
end
response "401", "unauthorized" do
let(:"api-key") { "invalid" }
add_examples
run_test!
end
end
end
end
end
# rubocop:enable RSpec/VariableName
# rubocop:enable RSpec/EmptyExampleGroup