OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#45450] Implement the api/v3/days/non_working endpoint
Dombi Attila3f07c7d110d4
diff --git a/app/models/queries/non_working_days.rb b/app/models/queries/non_working_days.rbnew file mode 100644index 00000000000..11d6e95878e--- /dev/null+++ b/app/models/queries/non_working_days.rb@@ -0,0 +1,33 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# 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 COPYRIGHT and LICENSE files for more details.+#++++module Queries::NonWorkingDays+ ::Queries::Register.register(NonWorkingDayQuery) do+ filter Filters::DatesIntervalFilter+ end+enddiff --git a/app/models/queries/non_working_days/filters/dates_interval_filter.rb b/app/models/queries/non_working_days/filters/dates_interval_filter.rbnew file mode 100644index 00000000000..753ad899e23--- /dev/null+++ b/app/models/queries/non_working_days/filters/dates_interval_filter.rb@@ -0,0 +1,57 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# 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 COPYRIGHT and LICENSE files for more details.+#++++class Queries::NonWorkingDays::Filters::DatesIntervalFilter < Queries::NonWorkingDays::Filters::NonWorkingDayFilter+ include Queries::Operators::DateRangeClauses++ def type+ :date+ end++ def self.key+ :date+ end++ def where+ lower_boundary, upper_boundary = values.map { |v| v.blank? ? nil : Date.parse(v) }+ lower_boundary ||= Date.current.beginning_of_year+ upper_boundary ||= Date.current.end_of_year++ <<-SQL.squish+ (#{date_range_clause('"non_working_days"', '"date"', lower_boundary, upper_boundary)})+ SQL+ end++ def type_strategy+ @type_strategy ||= Queries::Filters::Strategies::DateInterval.new(self)+ end++ def connection+ ActiveRecord::Base::connection+ end+enddiff --git a/app/models/queries/non_working_days/filters/non_working_day_filter.rb b/app/models/queries/non_working_days/filters/non_working_day_filter.rbnew file mode 100644index 00000000000..0de28efb727--- /dev/null+++ b/app/models/queries/non_working_days/filters/non_working_day_filter.rb@@ -0,0 +1,35 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# 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 COPYRIGHT and LICENSE files for more details.+#++++class Queries::NonWorkingDays::Filters::NonWorkingDayFilter < Queries::Filters::Base+ self.model = NonWorkingDay++ def human_name+ model.human_attribute_name(name)+ end+enddiff --git a/app/models/queries/non_working_days/non_working_day_query.rb b/app/models/queries/non_working_days/non_working_day_query.rbnew file mode 100644index 00000000000..7861cc4944a--- /dev/null+++ b/app/models/queries/non_working_days/non_working_day_query.rb@@ -0,0 +1,46 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# 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 COPYRIGHT and LICENSE files for more details.+#++++class Queries::NonWorkingDays::NonWorkingDayQuery < Queries::BaseQuery+ def self.model+ NonWorkingDay+ end++ # If there is a date filter present, we don't apply the default scope+ def default_scope+ if filters.detect { |f| f.class.key == :date }+ super+ else+ super.where(date: Date.current.all_year)+ end+ end++ def results+ super.reorder(date: :asc)+ end+enddiff --git a/docs/api/apiv3/components/schemas/non_working_day_collection_model.yml b/docs/api/apiv3/components/schemas/non_working_day_collection_model.ymlnew file mode 100644index 00000000000..4bb6d51d2da--- /dev/null+++ b/docs/api/apiv3/components/schemas/non_working_day_collection_model.yml@@ -0,0 +1,60 @@+# Schema: NonWorkingDayCollectionModel+---+allOf:+ - $ref: './collection_model.yml'+ - type: object+ required:+ - _links+ - _embedded+ properties:+ _links:+ type: object+ required:+ - self+ properties:+ self:+ allOf:+ - $ref: './link.yml'+ - description: |-+ This non working days collection++ **Resource**: NonWorkingDayCollectionModel+ _embedded:+ type: object+ required:+ - elements+ properties:+ elements:+ type: array+ description: |-+ The array of non working days. Each day has a name and a date.+ items:+ $ref: './non_working_day_model.yml'++example:+ _type: Collection+ total: 2+ count: 2+ _links:+ self:+ href: '/api/v3/non_working?filters=[{"interval":{"operator":"<>d","values":["2022-04-29","2022-12-24"]}}]'+ _embedded:+ elements:+ - _type: NonWorkingDay+ date: '2022-12-24'+ name: 'Christmas Evening'+ _links:+ self:+ href: /api/v3/days/non_working/2022-04-24+ weekday:+ href: /api/v3/days/week/6+ title: Saturday+ - _type: NonWorkingDay+ date: '2022-05-01'+ name: 'Labour day'+ _links:+ self:+ href: /api/v3/days/non_working/2022-05-01+ weekday:+ href: /api/v3/days/week/7+ title: Sundaydiff --git a/docs/api/apiv3/openapi-spec.yml b/docs/api/apiv3/openapi-spec.ymlindex f41cb27c6ca..49a2d521d7e 100644--- a/docs/api/apiv3/openapi-spec.yml+++ b/docs/api/apiv3/openapi-spec.yml@@ -650,6 +650,8 @@ components:"$ref": "./components/schemas/membership_update_form.yml"NewsModel:"$ref": "./components/schemas/news_model.yml"+ NonWorkingDayCollectionModel:+ "$ref": "./components/schemas/non_working_day_collection_model.yml"NonWorkingDayModel:"$ref": "./components/schemas/non_working_day_model.yml"NotificationCollectionModel:diff --git a/docs/api/apiv3/paths/days_non_working.yml b/docs/api/apiv3/paths/days_non_working.ymlindex 5235443a14a..ed95330ed34 100644--- a/docs/api/apiv3/paths/days_non_working.yml+++ b/docs/api/apiv3/paths/days_non_working.yml@@ -1,5 +1,51 @@# /api/v3/days/non_working---+get:+ summary: Lists all non working days+ operationId: list_non_working_days+ tags:+ - Work Schedule+ description: |-+ Lists all one-time non working days, such as holidays.+ It does not lists the non working weekdays, such as each Saturday, Sunday.+ For listing the weekends, the `/api/v3/days` endpoint should be used.++ All days from current year are returned by default.+ parameters:+ - name: filters+ in: query+ description: |-+ JSON specifying filter conditions.++ Accepts the same format as returned by the [queries](https://www.openproject.org/docs/api/endpoints/queries/)+ endpoint. Currently supported filters are:++ + date: the inclusive date interval to scope days to look up. When+ unspecified, default is from the beginning of current month to the end+ of following month.++ Example: `{ "date": { "operator": "<>d", "values": ["2022-05-02","2022-05-26"] } }`+ would return days between May 5 and May 26 2022, inclusive.++ example: '[{ "date": { "operator": "<>d", "values": ["2022-05-02","2022-05-26"] } }]'+ required: false+ schema:+ type: string+ responses:+ '200':+ description: |-+ OK+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/non_working_day_collection_model.yml'+ '400':+ $ref: "../components/responses/invalid_request_body.yml"+ '406':+ $ref: "../components/responses/missing_content_type.yml"+ '415':+ $ref: "../components/responses/unsupported_media_type.yml"+post:summary: Creates a non-working day (NOT IMPLEMENTED)operationId: create_non_working_daydiff --git a/lib/api/v3/days/non_working_day_collection_representer.rb b/lib/api/v3/days/non_working_day_collection_representer.rbnew file mode 100644index 00000000000..2be90189206--- /dev/null+++ b/lib/api/v3/days/non_working_day_collection_representer.rb@@ -0,0 +1,32 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# 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 COPYRIGHT and LICENSE files for more details.+#++++module API::V3::Days+ class NonWorkingDayCollectionRepresenter < ::API::Decorators::UnpaginatedCollection+ end+enddiff --git a/lib/api/v3/days/non_working_day_representer.rb b/lib/api/v3/days/non_working_day_representer.rbindex 4785c083ed5..e810c8f87e3 100644--- a/lib/api/v3/days/non_working_day_representer.rb+++ b/lib/api/v3/days/non_working_day_representer.rb@@ -31,6 +31,7 @@ module API::V3::Daysinclude ::API::Decorators::DatePropertyinclude ::API::Caching::CachedRepresenter+ property :idproperty :namedate_property :datediff --git a/lib/api/v3/days/non_working_days_api.rb b/lib/api/v3/days/non_working_days_api.rbindex 7233152d268..dbb395d9c10 100644--- a/lib/api/v3/days/non_working_days_api.rb+++ b/lib/api/v3/days/non_working_days_api.rb@@ -31,6 +31,13 @@ module API::V3::Dayshelpers ::API::Utilities::UrlPropsParsingHelperresources :non_working do+ get &::API::V3::Utilities::Endpoints::Index.new(+ api_name: "Day",+ model: NonWorkingDay,+ render_representer: NonWorkingDayCollectionRepresenter,+ self_path: -> { api_v3_paths.days_non_working }+ ).mount+route_param :date, type: Date, desc: 'NonWorkingDay DATE' doafter_validation do@non_working_day = NonWorkingDay.find_by!(date: declared_params[:date])diff --git a/spec/lib/api/v3/days/non_working_day_collection_representer_spec.rb b/spec/lib/api/v3/days/non_working_day_collection_representer_spec.rbnew file mode 100644index 00000000000..4deb2c1d925--- /dev/null+++ b/spec/lib/api/v3/days/non_working_day_collection_representer_spec.rb@@ -0,0 +1,51 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# 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 COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'++describe API::V3::Days::NonWorkingDayCollectionRepresenter do+ let(:non_working_days) do+ [+ build(:non_working_day, date: Date.new(2022, 12, 27)),+ build(:non_working_day, date: Date.new(2022, 12, 28)),+ build(:non_working_day, date: Date.new(2022, 12, 29))+ ]+ end+ let(:current_user) { instance_double(User, name: 'current_user') }+ let(:representer) do+ described_class.new(non_working_days,+ self_link: '/api/v3/self_link_untested',+ current_user:)+ end++ describe '#to_json' do+ subject(:collection) { representer.to_json }++ it_behaves_like 'unpaginated APIv3 collection', 3, 'self_link_untested', 'NonWorkingDay'+ end+enddiff --git a/spec/lib/api/v3/days/non_working_day_representer_spec.rb b/spec/lib/api/v3/days/non_working_day_representer_spec.rbindex 13632928b65..63d14c8a8cd 100644--- a/spec/lib/api/v3/days/non_working_day_representer_spec.rb+++ b/spec/lib/api/v3/days/non_working_day_representer_spec.rb@@ -35,13 +35,16 @@ describe ::API::V3::Days::NonWorkingDayRepresenter dodescribe '#to_json' dosubject(:generated) { representer.to_json }- it 'has _type: NonWorkingDay' do- expect(subject).to be_json_eql('NonWorkingDay'.to_json).at_path('_type')+ it_behaves_like 'property', :_type do+ let(:value) { 'NonWorkingDay' }end- it 'has name string property' do- expect(subject).to have_json_type(String).at_path('name')- expect(subject).to be_json_eql(non_working_day.name.to_json).at_path('name')+ it_behaves_like 'property', :id do+ let(:value) { non_working_day.id }+ end++ it_behaves_like 'property', :name do+ let(:value) { non_working_day.name }endit_behaves_like 'has ISO 8601 date only' dodiff --git a/spec/models/queries/non_working_days/filters/dates_interval_filter_spec.rb b/spec/models/queries/non_working_days/filters/dates_interval_filter_spec.rbnew file mode 100644index 00000000000..0714a65ddca--- /dev/null+++ b/spec/models/queries/non_working_days/filters/dates_interval_filter_spec.rb@@ -0,0 +1,50 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# 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 COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'++describe Queries::NonWorkingDays::Filters::DatesIntervalFilter do+ it_behaves_like 'basic query filter' do+ let(:type) { :date }+ let(:class_key) { :date }++ describe '#available?' do+ it 'is true' do+ expect(instance).to be_available+ end+ end++ describe '#allowed_values' do+ it 'is nil' do+ expect(instance.allowed_values).to be_nil+ end+ end++ it_behaves_like 'non ar filter'+ end+enddiff --git a/spec/models/queries/non_working_days/non_working_day_query_spec.rb b/spec/models/queries/non_working_days/non_working_day_query_spec.rbnew file mode 100644index 00000000000..cdd709e1154--- /dev/null+++ b/spec/models/queries/non_working_days/non_working_day_query_spec.rb@@ -0,0 +1,113 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# 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 COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'+require 'services/work_packages/shared/shared_examples_days'++describe Queries::NonWorkingDays::NonWorkingDayQuery do+ shared_let(:first_of_may) { create(:non_working_day, date: Date.new(Date.current.year, 5, 1)) }+ shared_let(:christmas) { create(:non_working_day, date: Date.new(Date.current.year, 12, 25)) }+ shared_let(:new_year_day) { create(:non_working_day, date: Date.new(Date.current.year + 1, 1, 1)) }++ let(:instance) { described_class.new }+ let(:base_scope) do+ NonWorkingDay+ .where(date: Date.current.all_year)+ .reorder(date: :asc)+ end++ let(:current_user) { build_stubbed(:admin) }++ before do+ login_as(current_user)+ end++ shared_examples "returns this year's non working days" do+ it "generates query for this year's non working days" do+ expect(instance.results.to_sql).to eql base_scope.to_sql+ end++ it "returns this year's non working days" do+ expect(instance.results).to eq [first_of_may, christmas]+ end+ end++ context 'without a filter' do+ context 'as an admin' do+ include_examples "returns this year's non working days"+ end++ context 'as a non admin' do+ let(:current_user) { build_stubbed(:user) }++ include_examples "returns this year's non working days"+ end+ end++ context 'with a date filter using the "<>d" operator' do+ let(:date_range) { [from.iso8601, to.iso8601] }++ before do+ instance.where('date', '<>d', date_range)+ end++ context 'with dates from this year' do+ let(:from) { Date.new(Date.current.year, 12, 1) }+ let(:to) { from.end_of_year }++ it 'returns days from the December' do+ expect(instance.results).to eq [christmas]+ end++ context 'with dates missing the to date' do+ let(:date_range) { [from.iso8601, ""] }++ it 'returns days from December until the end of year' do+ expect(instance.results).to eq [christmas]+ end+ end++ context 'with dates missing the from date' do+ let(:date_range) { ["", from.iso8601] }++ it 'returns days from the beginning of the year until December' do+ expect(instance.results).to eq [first_of_may]+ end+ end+ end++ context 'with dates from multiple years' do+ let(:from) { Date.current.beginning_of_year }+ let(:to) { Date.current.next_year.end_of_year }++ it 'returns days from this year and next year' do+ expect(instance.results).to eq [first_of_may, christmas, new_year_day]+ end+ end+ end+enddiff --git a/spec/requests/api/v3/days/non_working_days_index_resource_spec.rb b/spec/requests/api/v3/days/non_working_days_index_resource_spec.rbnew file mode 100644index 00000000000..c4338947241--- /dev/null+++ b/spec/requests/api/v3/days/non_working_days_index_resource_spec.rb@@ -0,0 +1,59 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# 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 COPYRIGHT and LICENSE files for more details.++require 'spec_helper'+require 'services/work_packages/shared/shared_examples_days'++describe API::V3::Days::NonWorkingDaysAPI,+ 'index',+ content_type: :json do+ include API::V3::Utilities::PathHelper++ let(:parsed_response) { JSON.parse(last_response.body) }+ let(:filters) { [] }++ current_user { user }++ before do+ get api_v3_paths.path_for :days_non_working, filters:+ end++ context 'for an admin user', :non_working_days_from_this_and_next_year do+ let(:user) { build(:admin) }++ it_behaves_like 'API V3 collection response', 2, 2, 'NonWorkingDay'++ context 'when filtering by date' do+ let(:filters) do+ [{ date: { operator: '<>d',+ values: [first_of_may.date.beginning_of_month.iso8601, new_year_day.date.iso8601] } }]+ end++ it_behaves_like 'API V3 collection response', 3, 3, 'NonWorkingDay'+ end+ end+enddiff --git a/spec/services/work_packages/shared/shared_examples_days.rb b/spec/services/work_packages/shared/shared_examples_days.rbindex abaa8a64267..5ab80da25c4 100644--- a/spec/services/work_packages/shared/shared_examples_days.rb+++ b/spec/services/work_packages/shared/shared_examples_days.rb@@ -32,6 +32,12 @@ RSpec.shared_context 'with weekend days Saturday and Sunday' doshared_let(:week_days) { week_with_saturday_and_sunday_as_weekend }end+RSpec.shared_context 'with non working days from this and next year' do+ shared_let(:first_of_may) { create(:non_working_day, date: Date.new(Date.current.year, 5, 1)) }+ shared_let(:christmas) { create(:non_working_day, date: Date.new(Date.current.year, 12, 25)) }+ shared_let(:new_year_day) { create(:non_working_day, date: Date.new(Date.current.year + 1, 1, 1)) }+end+RSpec.shared_context 'with non working days Christmas 2022 and new year 2023' doshared_let(:christmas) { create(:non_working_day, date: Date.new(2022, 12, 25)) }shared_let(:new_year_day) { create(:non_working_day, date: Date.new(2023, 1, 1)) }@@ -48,6 +54,7 @@ endRSpec.configure do |rspec|rspec.include_context 'with weekend days Saturday and Sunday', :weekend_saturday_sundayrspec.include_context 'with non working days Christmas 2022 and new year 2023', :christmas_2022_new_year_2023+ rspec.include_context 'with non working days from this and next year', :non_working_days_from_this_and_next_yearrspec.include_context 'with no working days', :no_working_daysend