diff --git a/app/jobs/decidim/initiatives/check_published_initiatives.rb b/app/jobs/decidim/initiatives/check_published_initiatives.rb new file mode 100644 index 0000000000..1a3d95013f --- /dev/null +++ b/app/jobs/decidim/initiatives/check_published_initiatives.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Decidim + module Initiatives + class CheckPublishedInitiatives < ApplicationJob + queue_as :initiatives + + def perform + system "rake decidim_initiatives:check_published" + end + end + end +end diff --git a/app/jobs/decidim/initiatives/check_validating_initiatives.rb b/app/jobs/decidim/initiatives/check_validating_initiatives.rb new file mode 100644 index 0000000000..d527b9c7f2 --- /dev/null +++ b/app/jobs/decidim/initiatives/check_validating_initiatives.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Decidim + module Initiatives + class CheckValidatingInitiatives < ApplicationJob + queue_as :initiatives + + def perform + system "rake decidim_initiatives:check_validating" + end + end + end +end diff --git a/app/jobs/decidim/initiatives/notify_progress_initiatives.rb b/app/jobs/decidim/initiatives/notify_progress_initiatives.rb new file mode 100644 index 0000000000..38b4b8ae69 --- /dev/null +++ b/app/jobs/decidim/initiatives/notify_progress_initiatives.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Decidim + module Initiatives + class NotifyProgressInitiatives < ApplicationJob + queue_as :initiatives + + def perform + system "rake decidim_initiatives:notify_progress" + end + end + end +end diff --git a/config/sidekiq.yml b/config/sidekiq.yml index 4b5298cd4c..bce1d3cf5c 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -37,6 +37,18 @@ cron: "*/15 * * * *" class: Decidim::ParticipatoryProcesses::ChangeActiveStepJob queue: scheduled + CheckPublishedInitiatives: + cron: '0 1 * * *' + class: Decidim::Initiatives::CheckPublishedInitiatives + queue: initiatives + CheckValidatingInitiatives: + cron: '0 1 * * *' + class: Decidim::Initiatives::CheckValidatingInitiatives + queue: initiatives + NotifyProgressInitiatives: + cron: '0 1 * * *' + class: Decidim::Initiatives::NotifyProgressInitiatives + queue: initiatives # Decidim-AI Spam Digest Jobs AiSpamDigestDaily: diff --git a/spec/jobs/check_published_initatives_job_spec.rb b/spec/jobs/check_published_initatives_job_spec.rb new file mode 100644 index 0000000000..103799bd27 --- /dev/null +++ b/spec/jobs/check_published_initatives_job_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module Initiatives + describe CheckPublishedInitiatives do + subject { described_class } + + describe "queue" do + it "is queued to initiatives" do + expect(subject.queue_name).to eq "initiatives" + end + end + + describe "#perform" do + it "enqueues a job with perform_later" do + expect do + described_class.perform_later + end.to have_enqueued_job(described_class) + end + + it "runs the check_published rake task" do + job = described_class.new + allow(job).to receive(:system) + + job.perform + + expect(job).to have_received(:system).with("rake decidim_initiatives:check_published") + end + end + end + end +end diff --git a/spec/jobs/check_validating_initatives_job_spec.rb b/spec/jobs/check_validating_initatives_job_spec.rb new file mode 100644 index 0000000000..c83b32e74b --- /dev/null +++ b/spec/jobs/check_validating_initatives_job_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module Initiatives + describe CheckValidatingInitiatives do + subject { described_class } + + describe "queue" do + it "is queued to initiatives" do + expect(subject.queue_name).to eq "initiatives" + end + end + + describe "#perform" do + it "enqueues a job with perform_later" do + expect do + described_class.perform_later + end.to have_enqueued_job(described_class) + end + + it "runs the check_validating rake task" do + job = described_class.new + allow(job).to receive(:system) + + job.perform + + expect(job).to have_received(:system).with("rake decidim_initiatives:check_validating") + end + end + end + end +end diff --git a/spec/jobs/notify_progress_initatives_job_spec.rb b/spec/jobs/notify_progress_initatives_job_spec.rb new file mode 100644 index 0000000000..b701ce077f --- /dev/null +++ b/spec/jobs/notify_progress_initatives_job_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module Initiatives + describe NotifyProgressInitiatives do + subject { described_class } + + describe "queue" do + it "is queued to initiatives" do + expect(subject.queue_name).to eq "initiatives" + end + end + + describe "#perform" do + it "enqueues a job with perform_later" do + expect do + described_class.perform_later + end.to have_enqueued_job(described_class) + end + + it "runs the notify_progress rake task" do + job = described_class.new + allow(job).to receive(:system) + + job.perform + + expect(job).to have_received(:system).with("rake decidim_initiatives:notify_progress") + end + end + end + end +end diff --git a/spec/tasks/decidim_initiatives_tasks_spec.rb b/spec/tasks/decidim_initiatives_tasks_spec.rb new file mode 100644 index 0000000000..5220e4003b --- /dev/null +++ b/spec/tasks/decidim_initiatives_tasks_spec.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "decidim_initiatives:check_published", type: :task do + let(:organization) { create(:organization) } + let(:initiative_type) { create(:initiatives_type, organization:) } + let(:initiative_type_scope) { create(:initiatives_type_scope, type: initiative_type) } + + context "when the signing period has ended" do + context "when the initiative has NOT reached the signature threshold" do + let!(:initiative) do + create( + :initiative, + :published, + :rejectable, + organization:, + scoped_type: initiative_type_scope, + signature_end_date: 1.day.ago + ) + end + + it "moves the initiative to rejected state" do + expect { task.execute }.to change { initiative.reload.state }.from("published").to("rejected") + end + end + + context "when the initiative HAS reached the signature threshold" do + let!(:initiative) do + create( + :initiative, + :published, + :acceptable, + organization:, + scoped_type: initiative_type_scope, + signature_end_date: 1.day.ago + ) + end + + it "moves the initiative to accepted state" do + expect { task.execute }.to change { initiative.reload.state }.from("published").to("accepted") + end + end + end + + context "when the signing period is still active" do + let!(:initiative) do + create( + :initiative, + :published, + :rejectable, + organization:, + scoped_type: initiative_type_scope, + signature_end_date: 1.day.from_now + ) + end + + it "does not change the initiative state" do + expect { task.execute }.not_to(change { initiative.reload.state }) + end + end + + context "when the initiative is not in published state" do + let!(:initiative) do + create( + :initiative, + :created, + organization:, + scoped_type: initiative_type_scope, + signature_end_date: 1.day.ago + ) + end + + it "does not change the initiative state" do + expect { task.execute }.not_to(change { initiative.reload.state }) + end + end +end