mirror of
https://github.com/discourse/discourse.git
synced 2024-12-12 20:28:13 +08:00
5c6e7e3401
Adding some api documentation for the badge routes.
106 lines
2.9 KiB
Ruby
106 lines
2.9 KiB
Ruby
# frozen_string_literal: true
|
|
require 'swagger_helper'
|
|
|
|
describe 'badges' do
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
let(:badge) { Fabricate(:badge) }
|
|
|
|
before do
|
|
Jobs.run_immediately!
|
|
sign_in(admin)
|
|
end
|
|
|
|
path '/admin/badges.json' do
|
|
|
|
get 'List badges' do
|
|
tags 'Badges'
|
|
consumes 'application/json'
|
|
expected_request_schema = nil
|
|
|
|
produces 'application/json'
|
|
response '200', 'success response' do
|
|
expected_response_schema = load_spec_schema('badge_list_response')
|
|
schema expected_response_schema
|
|
|
|
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
|
|
|
|
post 'Create badge' do
|
|
tags 'Badges'
|
|
consumes 'application/json'
|
|
expected_request_schema = load_spec_schema('badge_create_request')
|
|
parameter name: :params, in: :body, schema: expected_request_schema
|
|
|
|
produces 'application/json'
|
|
response '200', 'success response' do
|
|
expected_response_schema = load_spec_schema('badge_create_response')
|
|
schema expected_response_schema
|
|
|
|
let(:params) { {
|
|
'name' => 'badge1',
|
|
'badge_type_id' => 2
|
|
} }
|
|
|
|
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
|
|
|
|
path '/admin/badges/{id}.json' do
|
|
|
|
put 'Update badge' do
|
|
tags 'Badges'
|
|
consumes 'application/json'
|
|
expected_request_schema = load_spec_schema('badge_update_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 = load_spec_schema('badge_update_response')
|
|
schema expected_response_schema
|
|
|
|
let(:id) { badge.id }
|
|
|
|
let(:params) { {
|
|
'name' => 'badge1',
|
|
'badge_type_id' => 2
|
|
} }
|
|
|
|
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
|
|
|
|
delete 'Delete badge' do
|
|
tags 'Badges'
|
|
consumes 'application/json'
|
|
expected_request_schema = nil
|
|
parameter name: :id, in: :path, schema: { type: :integer }
|
|
|
|
produces 'application/json'
|
|
response '200', 'success response' do
|
|
expected_response_schema = nil
|
|
schema expected_response_schema
|
|
|
|
let(:id) { badge.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
|
|
end
|