2020-05-11 15:06:49 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require "swagger_helper"
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe "posts" do
|
2020-05-11 15:06:49 -04:00
|
|
|
let(:"Api-Key") { Fabricate(:api_key).key }
|
|
|
|
let(:"Api-Username") { "system" }
|
2021-03-12 18:48:39 -05:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Jobs.run_immediately!
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
2020-05-11 15:06:49 -04:00
|
|
|
|
|
|
|
path "/posts.json" do
|
|
|
|
get "List latest posts across topics" do
|
|
|
|
tags "Posts"
|
2021-09-03 09:39:29 -04:00
|
|
|
operationId "listPosts"
|
2020-05-11 15:06:49 -04:00
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
2022-09-16 10:09:15 -04:00
|
|
|
parameter name: "before",
|
|
|
|
in: :query,
|
|
|
|
type: :string,
|
|
|
|
description: "Load posts with an id lower than this value. Useful for pagination.",
|
|
|
|
required: false
|
2020-05-11 15:06:49 -04:00
|
|
|
produces "application/json"
|
2023-01-09 06:18:21 -05:00
|
|
|
|
2020-05-11 15:06:49 -04:00
|
|
|
response "200", "latest posts" do
|
|
|
|
schema type: :object,
|
|
|
|
properties: {
|
|
|
|
latest_posts: {
|
|
|
|
type: :array,
|
|
|
|
items: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
username: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
avatar_template: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
created_at: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
cooked: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
post_number: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
post_type: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
updated_at: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
reply_count: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reply_to_post_number: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
quote_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
incoming_link_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reads: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
readers_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
score: {
|
|
|
|
type: :number,
|
|
|
|
},
|
|
|
|
yours: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
topic_id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
topic_slug: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
topic_title: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
topic_html_title: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
category_id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
display_username: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
primary_group_name: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
flair_name: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
flair_url: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
flair_bg_color: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
flair_color: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
version: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
can_edit: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
can_delete: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
can_recover: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
can_wiki: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
user_title: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
raw: {
|
|
|
|
type: :string,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
actions_summary: {
|
|
|
|
type: :array,
|
|
|
|
items: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
can_act: {
|
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
moderator: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
admin: {
|
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
staff: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
user_id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
hidden: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
trust_level: {
|
|
|
|
type: :integer,
|
2021-08-12 14:25:17 -04:00
|
|
|
},
|
|
|
|
deleted_at: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
user_deleted: {
|
|
|
|
type: :boolean,
|
2021-08-12 14:25:17 -04:00
|
|
|
},
|
|
|
|
edit_reason: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
can_view_edit_history: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
wiki: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
reviewable_id: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
reviewable_score_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reviewable_score_pending_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let!(:post) { Fabricate(:post) }
|
|
|
|
run_test!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
post "Creates a new topic, a new post, or a private message" do
|
2021-03-12 18:48:39 -05:00
|
|
|
tags "Posts", "Topics", "Private Messages"
|
2021-09-03 09:39:29 -04:00
|
|
|
operationId "createTopicPostPM"
|
2020-05-11 15:06:49 -04:00
|
|
|
consumes "application/json"
|
2021-03-12 18:48:39 -05:00
|
|
|
expected_request_schema = load_spec_schema("topic_create_request")
|
|
|
|
parameter name: :params, in: :body, schema: expected_request_schema
|
2020-05-11 15:06:49 -04:00
|
|
|
|
|
|
|
produces "application/json"
|
|
|
|
response "200", "post created" do
|
2021-03-12 18:48:39 -05:00
|
|
|
expected_response_schema = load_spec_schema("topic_create_response")
|
|
|
|
schema expected_response_schema
|
2020-05-11 15:06:49 -04:00
|
|
|
|
2021-03-12 18:48:39 -05:00
|
|
|
let(:params) { Fabricate(:post) }
|
|
|
|
|
|
|
|
it_behaves_like "a JSON endpoint", 200 do
|
|
|
|
let(:expected_response_schema) { expected_response_schema }
|
|
|
|
let(:expected_request_schema) { expected_request_schema }
|
|
|
|
end
|
2020-05-11 15:06:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
path "/posts/{id}.json" do
|
2021-05-20 21:43:47 -04:00
|
|
|
get "Retrieve a single post" do
|
2020-05-11 15:06:49 -04:00
|
|
|
tags "Posts"
|
2021-09-03 09:39:29 -04:00
|
|
|
operationId "getPost"
|
2020-05-11 15:06:49 -04:00
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
|
|
|
|
produces "application/json"
|
2023-01-09 06:18:21 -05:00
|
|
|
|
2020-05-11 15:06:49 -04:00
|
|
|
response "200", "latest posts" do
|
|
|
|
schema type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
2021-08-12 14:25:17 -04:00
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
username: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
avatar_template: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
created_at: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :string,
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
cooked: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
post_number: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
post_type: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
updated_at: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
reply_count: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reply_to_post_number: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
quote_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
incoming_link_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reads: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
readers_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
score: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
yours: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
topic_id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
topic_slug: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
display_username: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
primary_group_name: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
flair_name: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
flair_url: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
flair_bg_color: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
flair_color: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
version: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
can_edit: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
can_delete: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
can_recover: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
can_wiki: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
user_title: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
raw: {
|
|
|
|
type: :string,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
actions_summary: {
|
|
|
|
type: :array,
|
|
|
|
items: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
can_act: {
|
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
moderator: {
|
2022-06-06 04:37:08 -04:00
|
|
|
type: :boolean,
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
admin: {
|
2022-06-06 04:37:08 -04:00
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
staff: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
user_id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
hidden: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
trust_level: {
|
|
|
|
type: :integer,
|
2021-08-12 14:25:17 -04:00
|
|
|
},
|
|
|
|
deleted_at: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
user_deleted: {
|
|
|
|
type: :boolean,
|
2021-08-12 14:25:17 -04:00
|
|
|
},
|
|
|
|
edit_reason: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
can_view_edit_history: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
wiki: {
|
|
|
|
type: :boolean,
|
2021-08-12 14:25:17 -04:00
|
|
|
},
|
|
|
|
reviewable_id: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
reviewable_score_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reviewable_score_pending_count: {
|
|
|
|
type: :integer,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let(:id) { Fabricate(:post).id }
|
|
|
|
run_test!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
put "Update a single post" do
|
|
|
|
tags "Posts"
|
2021-09-03 09:39:29 -04:00
|
|
|
operationId "updatePost"
|
2020-05-11 15:06:49 -04:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
|
|
|
|
parameter name: :post_body,
|
|
|
|
in: :body,
|
|
|
|
schema: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
2023-01-09 06:18:21 -05:00
|
|
|
post: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :object,
|
|
|
|
properties: {
|
2023-01-09 06:18:21 -05:00
|
|
|
raw: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :string,
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
2021-08-12 14:25:17 -04:00
|
|
|
edit_reason: {
|
|
|
|
type: :string,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
required: ["raw"],
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:06:49 -04:00
|
|
|
produces "application/json"
|
|
|
|
response "200", "post updated" do
|
|
|
|
schema type: :object,
|
|
|
|
properties: {
|
2023-01-09 06:18:21 -05:00
|
|
|
post: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
2023-01-09 06:18:21 -05:00
|
|
|
name: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: %i[string null],
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
username: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :string,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
avatar_template: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :string,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
created_at: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :string,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
cooked: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :string,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
post_number: {
|
|
|
|
type: :integer,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
post_type: {
|
|
|
|
type: :integer,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
updated_at: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :string,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
reply_count: {
|
|
|
|
type: :integer,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2021-08-12 14:25:17 -04:00
|
|
|
reply_to_post_number: {
|
|
|
|
type: %i[string null],
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
quote_count: {
|
|
|
|
type: :integer,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
incoming_link_count: {
|
|
|
|
type: :integer,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
reads: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :integer,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
readers_count: {
|
|
|
|
type: :integer,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
score: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :number,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
yours: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
topic_id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
topic_slug: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :string,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
display_username: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: %i[string null],
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2021-08-12 14:25:17 -04:00
|
|
|
primary_group_name: {
|
|
|
|
type: %i[string null],
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2021-08-12 14:25:17 -04:00
|
|
|
flair_url: {
|
|
|
|
type: %i[string null],
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
flair_bg_color: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: %i[string null],
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2021-08-12 14:25:17 -04:00
|
|
|
flair_color: {
|
|
|
|
type: %i[string null],
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
version: {
|
|
|
|
type: :integer,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
can_edit: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
can_delete: {
|
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
can_recover: {
|
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
can_wiki: {
|
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2021-08-12 14:25:17 -04:00
|
|
|
user_title: {
|
|
|
|
type: %i[string null],
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
actions_summary: {
|
|
|
|
type: :array,
|
2023-01-09 06:18:21 -05:00
|
|
|
items: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :object,
|
|
|
|
properties: {
|
2023-01-09 06:18:21 -05:00
|
|
|
id: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
can_act: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
moderator: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
2023-01-09 06:18:21 -05:00
|
|
|
admin: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
staff: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
user_id: {
|
|
|
|
type: :integer,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
draft_sequence: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
hidden: {
|
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
trust_level: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
deleted_at: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
user_deleted: {
|
|
|
|
type: :boolean,
|
2021-08-12 14:25:17 -04:00
|
|
|
},
|
|
|
|
edit_reason: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
can_view_edit_history: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
wiki: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
reviewable_id: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
reviewable_score_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reviewable_score_pending_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
}
|
2023-01-09 06:18:21 -05:00
|
|
|
|
2020-05-11 15:06:49 -04:00
|
|
|
let(:post_body) { { post: { raw: "Updated content!", edit_reason: "fixed typo" } } }
|
|
|
|
let(:id) { Fabricate(:post).id }
|
|
|
|
|
|
|
|
run_test! do |response|
|
|
|
|
data = JSON.parse(response.body)
|
|
|
|
expect(data["post"]["cooked"]).to eq("<p>Updated content!</p>")
|
|
|
|
expect(data["post"]["edit_reason"]).to eq("fixed typo")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-01-07 18:09:32 -05:00
|
|
|
|
|
|
|
delete "delete a single post" do
|
|
|
|
tags "Posts"
|
|
|
|
operationId "deletePost"
|
|
|
|
consumes "application/json"
|
|
|
|
expected_request_schema = load_spec_schema("post_delete_request")
|
|
|
|
parameter name: :id, in: :path, schema: { type: :integer }
|
|
|
|
parameter name: :params, in: :body, schema: expected_request_schema
|
|
|
|
|
|
|
|
produces "application/json"
|
|
|
|
response "200", "success response" do
|
|
|
|
expected_response_schema = nil
|
|
|
|
schema expected_response_schema
|
|
|
|
|
|
|
|
let(:topic) { Fabricate(:topic) }
|
|
|
|
let(:post) { Fabricate(:post, topic_id: topic.id, post_number: 3) }
|
|
|
|
let(:id) { post.id }
|
|
|
|
let(:params) { { "force_destroy" => false } }
|
|
|
|
|
|
|
|
it_behaves_like "a JSON endpoint", 200 do
|
|
|
|
let(:expected_response_schema) { expected_response_schema }
|
|
|
|
let(:expected_request_schema) { expected_request_schema }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-05-11 15:06:49 -04:00
|
|
|
end
|
|
|
|
|
2022-02-09 17:04:36 -05:00
|
|
|
path "/posts/{id}/replies.json" do
|
|
|
|
get "List replies to a post" do
|
|
|
|
tags "Posts"
|
|
|
|
operationId "postReplies"
|
|
|
|
consumes "application/json"
|
|
|
|
expected_request_schema = nil
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
|
|
|
|
produces "application/json"
|
|
|
|
response "200", "post replies" do
|
|
|
|
expected_response_schema = load_spec_schema("post_replies_response")
|
|
|
|
schema expected_response_schema
|
|
|
|
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
fab!(:topic) { Fabricate(:topic) }
|
|
|
|
fab!(:post) { Fabricate(:post, topic: topic, user: user) }
|
|
|
|
let!(:reply) do
|
|
|
|
PostCreator.new(
|
|
|
|
user,
|
|
|
|
raw: "this is some text for my post",
|
|
|
|
topic_id: topic.id,
|
|
|
|
reply_to_post_number: post.post_number,
|
|
|
|
).create
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2022-02-09 17:04:36 -05:00
|
|
|
let!(:id) { post.id }
|
|
|
|
|
|
|
|
it_behaves_like "a JSON endpoint", 200 do
|
|
|
|
let(:expected_response_schema) { expected_response_schema }
|
|
|
|
let(:expected_request_schema) { expected_request_schema }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-11 15:06:49 -04:00
|
|
|
path "/posts/{id}/locked.json" do
|
|
|
|
put "Lock a post from being edited" do
|
|
|
|
tags "Posts"
|
2021-09-03 09:39:29 -04:00
|
|
|
operationId "lockPost"
|
2020-05-11 15:06:49 -04:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
|
|
|
parameter name: :id, in: :path, schema: { type: :string }
|
|
|
|
|
|
|
|
parameter name: :post_body,
|
|
|
|
in: :body,
|
|
|
|
schema: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
2022-06-06 03:23:40 -04:00
|
|
|
locked: {
|
|
|
|
type: :string,
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
required: ["locked"],
|
|
|
|
}
|
|
|
|
|
|
|
|
produces "application/json"
|
|
|
|
response "200", "post updated" do
|
|
|
|
schema type: :object, properties: { locked: { type: :boolean } }
|
|
|
|
|
|
|
|
let(:post_body) { { locked: "true" } }
|
|
|
|
let(:id) { Fabricate(:post).id }
|
|
|
|
|
|
|
|
run_test! do |response|
|
|
|
|
data = JSON.parse(response.body)
|
|
|
|
expect(data["locked"]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
path "/post_actions.json" do
|
|
|
|
post "Like a post and other actions" do
|
|
|
|
tags "Posts"
|
2021-09-03 09:39:29 -04:00
|
|
|
operationId "performPostAction"
|
2020-05-11 15:06:49 -04:00
|
|
|
consumes "application/json"
|
|
|
|
parameter name: "Api-Key", in: :header, type: :string, required: true
|
|
|
|
parameter name: "Api-Username", in: :header, type: :string, required: true
|
2023-01-09 06:18:21 -05:00
|
|
|
|
2020-05-11 15:06:49 -04:00
|
|
|
parameter name: :post_body,
|
|
|
|
in: :body,
|
|
|
|
schema: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
post_action_type_id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
flag_topic: {
|
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
required: %w[id post_action_type_id],
|
|
|
|
}
|
2023-01-09 06:18:21 -05:00
|
|
|
|
2020-05-11 15:06:49 -04:00
|
|
|
produces "application/json"
|
|
|
|
response "200", "post updated" do
|
|
|
|
schema type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
username: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
avatar_template: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
created_at: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :string,
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
cooked: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
post_number: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
post_type: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
updated_at: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
reply_count: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reply_to_post_number: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
quote_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
incoming_link_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reads: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
readers_count: {
|
2022-01-07 18:09:32 -05:00
|
|
|
type: :integer,
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
score: {
|
|
|
|
type: :number,
|
|
|
|
},
|
|
|
|
yours: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
topic_id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
topic_slug: {
|
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
display_username: {
|
2021-08-12 14:25:17 -04:00
|
|
|
type: :string,
|
|
|
|
},
|
|
|
|
primary_group_name: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
flair_name: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
flair_url: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
flair_bg_color: {
|
|
|
|
type: %i[string null],
|
|
|
|
},
|
|
|
|
flair_color: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
version: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
can_edit: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
can_delete: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
can_recover: {
|
2022-06-06 04:37:08 -04:00
|
|
|
type: :boolean,
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
can_wiki: {
|
|
|
|
type: :boolean,
|
2021-08-12 14:25:17 -04:00
|
|
|
},
|
|
|
|
user_title: {
|
|
|
|
type: %i[string null],
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
actions_summary: {
|
|
|
|
type: :array,
|
|
|
|
items: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
2022-01-07 18:09:32 -05:00
|
|
|
type: :integer,
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
2023-01-09 06:18:21 -05:00
|
|
|
count: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
acted: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
can_undo: {
|
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
moderator: {
|
2022-06-06 04:37:08 -04:00
|
|
|
type: :boolean,
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
admin: {
|
2022-06-06 04:37:08 -04:00
|
|
|
type: :boolean,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
|
|
|
staff: {
|
2020-05-11 15:06:49 -04:00
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
user_id: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
hidden: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
trust_level: {
|
|
|
|
type: :integer,
|
2021-08-12 14:25:17 -04:00
|
|
|
},
|
|
|
|
deleted_at: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
user_deleted: {
|
|
|
|
type: :boolean,
|
2021-08-12 14:25:17 -04:00
|
|
|
},
|
|
|
|
edit_reason: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
can_view_edit_history: {
|
|
|
|
type: :boolean,
|
|
|
|
},
|
|
|
|
wiki: {
|
|
|
|
type: :boolean,
|
2020-11-11 07:49:53 -05:00
|
|
|
},
|
|
|
|
notice: {
|
|
|
|
type: :object,
|
2021-08-12 14:25:17 -04:00
|
|
|
},
|
|
|
|
reviewable_id: {
|
|
|
|
type: %i[string null],
|
2020-05-11 15:06:49 -04:00
|
|
|
},
|
|
|
|
reviewable_score_count: {
|
|
|
|
type: :integer,
|
|
|
|
},
|
|
|
|
reviewable_score_pending_count: {
|
2022-01-07 18:09:32 -05:00
|
|
|
type: :integer,
|
2023-01-09 06:18:21 -05:00
|
|
|
},
|
2020-05-11 15:06:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let(:id) { Fabricate(:post).id }
|
|
|
|
let(:post_body) { { id: id, post_action_type_id: 2 } }
|
|
|
|
|
|
|
|
run_test! do |response|
|
|
|
|
data = JSON.parse(response.body)
|
|
|
|
expect(data["actions_summary"][0]["id"]).to eq(2)
|
|
|
|
expect(data["actions_summary"][0]["count"]).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|