2020-05-12 03:06:49 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'swagger_helper'
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe 'groups' do
|
2020-05-12 03:06:49 +08:00
|
|
|
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Jobs.run_immediately!
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
path '/admin/groups.json' do
|
|
|
|
post 'Creates a group' do
|
2020-10-26 22:55:22 +08:00
|
|
|
tags 'Groups'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'createGroup'
|
2020-05-12 03:06:49 +08:00
|
|
|
consumes 'application/json'
|
2022-07-21 09:18:48 +08:00
|
|
|
expected_request_schema = load_spec_schema('group_create_request')
|
|
|
|
parameter name: :params, in: :body, schema: expected_request_schema
|
2020-05-12 03:06:49 +08:00
|
|
|
|
|
|
|
produces 'application/json'
|
|
|
|
response '200', 'group created' do
|
2022-07-21 09:18:48 +08:00
|
|
|
expected_response_schema = load_spec_schema('group_create_response')
|
2022-07-28 23:49:33 +08:00
|
|
|
schema expected_response_schema
|
2020-05-12 03:06:49 +08:00
|
|
|
|
2022-07-21 09:18:48 +08:00
|
|
|
let(:params) { { 'group' => { 'name' => 'awesome' } } }
|
|
|
|
it_behaves_like "a JSON endpoint", 200 do
|
|
|
|
let(:expected_response_schema) { expected_response_schema }
|
|
|
|
let(:expected_request_schema) { expected_request_schema }
|
2020-05-12 03:06:49 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-10-26 22:55:22 +08:00
|
|
|
end
|
2020-05-12 03:06:49 +08:00
|
|
|
|
2021-02-04 08:12:35 +08:00
|
|
|
path '/admin/groups/{id}.json' do
|
|
|
|
delete 'Delete a group' do
|
|
|
|
tags 'Groups'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'deleteGroup'
|
2021-02-04 08:12:35 +08:00
|
|
|
consumes 'application/json'
|
|
|
|
parameter name: :id, in: :path, type: :integer
|
|
|
|
expected_request_schema = nil
|
|
|
|
|
|
|
|
produces 'application/json'
|
|
|
|
response '200', 'response' do
|
|
|
|
expected_response_schema = load_spec_schema('success_ok_response')
|
|
|
|
schema expected_response_schema
|
|
|
|
|
|
|
|
let(:id) { Fabricate(:group).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-10-26 22:55:22 +08:00
|
|
|
path '/groups/{id}.json' do
|
|
|
|
put 'Update a group' do
|
|
|
|
tags 'Groups'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'updateGroup'
|
2020-10-26 22:55:22 +08:00
|
|
|
consumes 'application/json'
|
2021-02-04 08:12:35 +08:00
|
|
|
parameter name: :id, in: :path, type: :integer
|
2022-08-09 00:52:08 +08:00
|
|
|
|
|
|
|
expected_request_schema = load_spec_schema('group_create_request')
|
|
|
|
parameter name: :params, in: :body, schema: expected_request_schema
|
2020-10-26 22:55:22 +08:00
|
|
|
|
|
|
|
produces 'application/json'
|
|
|
|
response '200', 'success response' do
|
|
|
|
schema type: :object, properties: {
|
|
|
|
success: { type: :string, example: "OK" }
|
|
|
|
}
|
|
|
|
|
|
|
|
let(:id) { Fabricate(:group).id }
|
2022-08-09 00:52:08 +08:00
|
|
|
let(:params) { { 'group' => { 'name' => 'awesome' } } }
|
2020-10-26 22:55:22 +08:00
|
|
|
|
|
|
|
run_test!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-04 08:12:35 +08:00
|
|
|
get 'Get a group' do
|
|
|
|
tags 'Groups'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'getGroup'
|
2021-02-04 08:12:35 +08:00
|
|
|
consumes 'application/json'
|
2021-08-13 18:22:15 +08:00
|
|
|
parameter name: :id, in: :path, type: :string, example: 'name', description: "Use group name instead of id"
|
2021-02-04 08:12:35 +08:00
|
|
|
expected_request_schema = nil
|
|
|
|
|
|
|
|
produces 'application/json'
|
|
|
|
response '200', 'success response' do
|
|
|
|
expected_response_schema = load_spec_schema('group_response')
|
|
|
|
schema expected_response_schema
|
|
|
|
|
2021-08-13 18:22:15 +08:00
|
|
|
let(:id) { Fabricate(:group).name }
|
2021-02-04 08:12:35 +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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-13 18:22:15 +08:00
|
|
|
path '/groups/{id}/members.json' do
|
2021-02-04 08:12:35 +08:00
|
|
|
get 'List group members' do
|
|
|
|
tags 'Groups'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'listGroupMembers'
|
2021-02-04 08:12:35 +08:00
|
|
|
consumes 'application/json'
|
2021-08-13 18:22:15 +08:00
|
|
|
parameter name: :id, in: :path, type: :string, example: 'name', description: "Use group name instead of id"
|
2021-02-04 08:12:35 +08:00
|
|
|
expected_request_schema = nil
|
|
|
|
|
|
|
|
produces 'application/json'
|
|
|
|
response '200', 'success response' do
|
|
|
|
expected_response_schema = load_spec_schema('group_members_response')
|
|
|
|
schema expected_response_schema
|
|
|
|
|
2021-08-13 18:22:15 +08:00
|
|
|
let(:id) { Fabricate(:group).name }
|
2021-02-04 08:12:35 +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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
put 'Add group members' do
|
|
|
|
tags 'Groups'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'addGroupMembers'
|
2021-02-04 08:12:35 +08:00
|
|
|
consumes 'application/json'
|
|
|
|
parameter name: :id, in: :path, type: :integer
|
|
|
|
expected_request_schema = load_spec_schema('group_add_members_request')
|
|
|
|
parameter name: :params, in: :body, schema: expected_request_schema
|
|
|
|
|
|
|
|
produces 'application/json'
|
|
|
|
response '200', 'success response' do
|
|
|
|
expected_response_schema = load_spec_schema('group_add_members_response')
|
|
|
|
schema expected_response_schema
|
|
|
|
|
|
|
|
let(:id) { Fabricate(:group).id }
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:user2) { Fabricate(:user) }
|
|
|
|
let(:usernames) { "#{user.username},#{user2.username}" }
|
|
|
|
let(:params) { { 'usernames' => usernames } }
|
|
|
|
|
|
|
|
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 'Remove group members' do
|
|
|
|
tags 'Groups'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'removeGroupMembers'
|
2021-02-04 08:12:35 +08:00
|
|
|
consumes 'application/json'
|
|
|
|
parameter name: :id, in: :path, type: :integer
|
|
|
|
expected_request_schema = load_spec_schema('group_remove_members_request')
|
|
|
|
parameter name: :params, in: :body, schema: expected_request_schema
|
|
|
|
|
|
|
|
produces 'application/json'
|
|
|
|
response '200', 'success response' do
|
|
|
|
expected_response_schema = load_spec_schema('group_remove_members_response')
|
|
|
|
schema expected_response_schema
|
|
|
|
|
|
|
|
let(:id) { Fabricate(:group).id }
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:user2) { Fabricate(:user) }
|
|
|
|
let(:usernames) { "#{user.username},#{user2.username}" }
|
|
|
|
let(:params) { { 'usernames' => usernames } }
|
|
|
|
|
|
|
|
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 '/groups.json' do
|
|
|
|
get 'List groups' do
|
|
|
|
tags 'Groups'
|
2021-09-03 21:39:29 +08:00
|
|
|
operationId 'listGroups'
|
2021-02-04 08:12:35 +08:00
|
|
|
consumes 'application/json'
|
|
|
|
expected_request_schema = nil
|
|
|
|
|
|
|
|
produces 'application/json'
|
|
|
|
response '200', 'response' do
|
|
|
|
expected_response_schema = load_spec_schema('groups_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
|
|
|
|
end
|
|
|
|
|
2020-05-12 03:06:49 +08:00
|
|
|
end
|