2020-04-28 06:40:07 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'swagger_helper'
|
|
|
|
|
|
|
|
describe 'categories' do
|
|
|
|
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
2020-05-12 03:06:49 +08:00
|
|
|
let!(:category) { Fabricate(:category, user: admin) }
|
2020-04-28 06:40:07 +08:00
|
|
|
|
|
|
|
before do
|
|
|
|
Jobs.run_immediately!
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
path '/categories.json' do
|
|
|
|
|
|
|
|
post 'Creates a category' do
|
2020-05-12 03:06:49 +08:00
|
|
|
tags 'Categories'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'createCategory'
|
2020-04-28 06:40:07 +08:00
|
|
|
consumes 'application/json'
|
2021-02-09 21:27:23 +08:00
|
|
|
expected_request_schema = load_spec_schema('category_create_request')
|
|
|
|
parameter name: :params, in: :body, schema: expected_request_schema
|
2020-04-28 06:40:07 +08:00
|
|
|
|
|
|
|
produces 'application/json'
|
2021-02-09 21:27:23 +08:00
|
|
|
response '200', 'success response' do
|
|
|
|
expected_response_schema = load_spec_schema('category_create_response')
|
|
|
|
schema expected_response_schema
|
2020-04-28 06:40:07 +08:00
|
|
|
|
2021-02-09 21:27:23 +08:00
|
|
|
let(:params) { { 'name' => 'todo' } }
|
|
|
|
|
|
|
|
it_behaves_like "a JSON endpoint", 200 do
|
|
|
|
let(:expected_response_schema) { expected_response_schema }
|
|
|
|
let(:expected_request_schema) { expected_request_schema }
|
|
|
|
end
|
2020-04-28 06:40:07 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-30 23:42:26 +08:00
|
|
|
get 'Retrieves a list of categories' do
|
2020-05-12 03:06:49 +08:00
|
|
|
tags 'Categories'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'listCategories'
|
2021-02-09 21:27:23 +08:00
|
|
|
consumes 'application/json'
|
|
|
|
expected_request_schema = nil
|
2021-10-07 02:34:03 +08:00
|
|
|
parameter name: :include_subcategories,
|
|
|
|
in: :query,
|
|
|
|
schema: {
|
|
|
|
type: :boolean,
|
|
|
|
enum: [true]
|
|
|
|
}
|
2020-04-28 06:40:07 +08:00
|
|
|
|
2021-02-09 21:27:23 +08:00
|
|
|
produces 'application/json'
|
|
|
|
response '200', 'success response' do
|
|
|
|
expected_response_schema = load_spec_schema('category_list_response')
|
|
|
|
schema expected_response_schema
|
|
|
|
|
2021-10-07 02:34:03 +08:00
|
|
|
let(:include_subcategories) { true }
|
|
|
|
|
2021-02-09 21:27:23 +08:00
|
|
|
it_behaves_like "a JSON endpoint", 200 do
|
|
|
|
let(:expected_response_schema) { expected_response_schema }
|
|
|
|
let(:expected_request_schema) { expected_request_schema }
|
|
|
|
end
|
2020-04-28 06:40:07 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-05-12 03:06:49 +08:00
|
|
|
|
2021-02-09 21:27:23 +08:00
|
|
|
path '/categories/{id}.json' do
|
2020-05-12 03:06:49 +08:00
|
|
|
|
|
|
|
put 'Updates a category' do
|
|
|
|
tags 'Categories'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'updateCategory'
|
2020-05-12 03:06:49 +08:00
|
|
|
consumes 'application/json'
|
2021-02-09 21:27:23 +08:00
|
|
|
expected_request_schema = load_spec_schema('category_create_request')
|
|
|
|
parameter name: :id, in: :path, schema: { type: :integer }
|
|
|
|
parameter name: :params, in: :body, schema: expected_request_schema
|
2020-05-12 03:06:49 +08:00
|
|
|
|
|
|
|
produces 'application/json'
|
2021-02-09 21:27:23 +08:00
|
|
|
response '200', 'success response' do
|
|
|
|
expected_response_schema = load_spec_schema('category_update_response')
|
|
|
|
schema expected_response_schema
|
2020-05-12 03:06:49 +08:00
|
|
|
|
2021-02-09 21:27:23 +08:00
|
|
|
let(:id) { category.id }
|
|
|
|
let(:params) { { 'name' => 'todo' } }
|
|
|
|
|
|
|
|
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-12 03:06:49 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-09 21:27:23 +08:00
|
|
|
path '/c/{slug}/{id}.json' do
|
2020-05-12 03:06:49 +08:00
|
|
|
|
|
|
|
get 'List topics' do
|
|
|
|
tags 'Categories'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'listCategoryTopics'
|
2020-05-12 03:06:49 +08:00
|
|
|
produces 'application/json'
|
2021-02-09 21:27:23 +08:00
|
|
|
parameter name: :slug, in: :path, schema: { type: :string }
|
|
|
|
parameter name: :id, in: :path, schema: { type: :integer }
|
|
|
|
expected_request_schema = nil
|
2020-05-12 03:06:49 +08:00
|
|
|
|
2021-02-09 21:27:23 +08:00
|
|
|
produces 'application/json'
|
|
|
|
response '200', 'success response' do
|
|
|
|
expected_response_schema = load_spec_schema('category_topics_response')
|
|
|
|
schema expected_response_schema
|
|
|
|
|
|
|
|
let(:id) { category.id }
|
|
|
|
let(:slug) { category.slug_path.join("/") }
|
|
|
|
|
|
|
|
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-12 03:06:49 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-09 21:27:23 +08:00
|
|
|
path '/c/{id}/show.json' do
|
2020-05-12 03:06:49 +08:00
|
|
|
|
|
|
|
get 'Show category' do
|
|
|
|
tags 'Categories'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'getCategory'
|
2021-02-09 21:27:23 +08:00
|
|
|
consumes 'application/json'
|
|
|
|
parameter name: :id, in: :path, schema: { type: :integer }
|
|
|
|
expected_request_schema = nil
|
2020-05-12 03:06:49 +08:00
|
|
|
|
2021-02-09 21:27:23 +08:00
|
|
|
produces 'application/json'
|
2020-05-12 03:06:49 +08:00
|
|
|
response '200', 'response' do
|
2021-02-09 21:27:23 +08:00
|
|
|
expected_response_schema = load_spec_schema('category_create_response')
|
|
|
|
schema expected_response_schema
|
|
|
|
|
|
|
|
let(:id) { category.id }
|
|
|
|
|
|
|
|
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-12 03:06:49 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-28 06:40:07 +08:00
|
|
|
end
|