Skip to content
Snippets Groups Projects
Commit 61137670 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre
Browse files

Add an endpoint to generate the default lists for a board

parent 68cfdba7
No related branches found
No related tags found
1 merge request!5548Issue boards
Loading
Loading
@@ -33,6 +33,16 @@ class Projects::BoardListsController < Projects::ApplicationController
end
end
 
def generate
service = Boards::Lists::GenerateService.new(project, current_user)
if service.execute
render json: project.board.lists.label.as_json(only: [:id, :list_type, :position], methods: [:title], include: { label: { only: [:id, :title, :color] } })
else
head :unprocessable_entity
end
end
private
 
def list_params
Loading
Loading
Loading
Loading
@@ -860,6 +860,10 @@ Rails.application.routes.draw do
resources :issues, only: [:update], controller: :board_issues
 
resources :lists, only: [:create, :update, :destroy], controller: :board_lists do
collection do
post :generate
end
resources :issues, only: [:index], controller: :board_issues
end
end
Loading
Loading
Loading
Loading
@@ -119,4 +119,36 @@ describe Projects::BoardListsController do
format: :json
end
end
describe 'POST #generate' do
context 'when board lists is empty' do
it 'returns a successful 200 response' do
generate_default_board_lists
expect(response).to have_http_status(200)
end
it 'returns the defaults lists' do
generate_default_board_lists
expect(response).to match_response_schema('list', array: true)
end
end
context 'when board lists is not empty' do
it 'returns a unprocessable entity 422 response' do
create(:list, board: board)
generate_default_board_lists
expect(response).to have_http_status(422)
end
end
def generate_default_board_lists
post :generate, namespace_id: project.namespace.to_param,
project_id: project.to_param,
format: :json
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment