Add spec for query order API

pull/7473/head
Oliver Günther 5 years ago
parent dd49432406
commit b2505245ff
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 2
      frontend/src/app/modules/hal/dm-services/query-order-dm.service.ts
  2. 2
      lib/api/v3/queries/order/query_order_api.rb
  3. 88
      spec/requests/api/v3/queries/order/query_order_api_spec.rb

@ -49,7 +49,7 @@ export class QueryOrderDmService {
public update(id:string, delta:QueryOrder):Promise<unknown> {
return this.http
.put(
.patch(
this.orderPath(id),
{ delta: delta }
)

@ -78,7 +78,7 @@ module API
params do
optional :delta, type: Hash
end
put do
patch do
params[:delta].each do |work_package_id, new_position|
if new_position == -1
remove_order(work_package_id)

@ -0,0 +1,88 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
require 'spec_helper'
require 'rack/test'
describe "/api/v3/queries/:id/order", type: :request do
let(:user) { FactoryBot.create :admin }
let(:query) { FactoryBot.create(:query, name: "A Query", user: user) }
let(:path) { "/api/v3/queries/#{query.id}/order" }
subject(:body) { JSON.parse(last_response.body) }
before do
login_as user
header "Content-Type", "application/json"
end
describe 'with order present' do
let(:wp1) { FactoryBot.create :work_package }
let(:wp2) { FactoryBot.create :work_package }
before do
query.ordered_work_packages.create(work_package_id: wp1.id, position: 0)
query.ordered_work_packages.create(work_package_id: wp2.id, position: 8192)
end
it 'returns the order' do
get path
expect(last_response.status).to eq 200
expect(body).to be_a Hash
expect(body).to eq( { wp1.id => 0, wp2.id => 8192 }.stringify_keys )
end
end
describe '#patch' do
let!(:wp1) { FactoryBot.create :work_package }
let!(:wp2) { FactoryBot.create :work_package }
before do
query.ordered_work_packages.create(work_package_id: wp1.id, position: 0)
end
it 'allows inserting a delta' do
patch path, { delta: { wp2.id.to_s => 1234 } }.to_json
expect(last_response.status).to eq 204
query.reload
expect(query.ordered_work_packages.find_by(work_package: wp2).position).to eq 1234
end
it 'allows removing an item' do
patch path, { delta: { wp1.id.to_s => -1 } }.to_json
expect(last_response.status).to eq 204
query.reload
expect(query.ordered_work_packages.to_a).to be_empty
end
end
end
Loading…
Cancel
Save