diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index ff36e4f85..47b7c1b9f 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -19,7 +19,7 @@ module Types field :demarches_publiques, DemarcheDescriptorType.connection_type, null: false, internal: true def demarches_publiques - Procedure.publiees_ou_closes.opendata.includes(draft_revision: :procedure, published_revision: :procedure) + Procedure.publiques.includes(draft_revision: :procedure, published_revision: :procedure) end def demarche_descriptor(demarche:) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 1f8d42b72..76654ee07 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -219,6 +219,15 @@ class Procedure < ApplicationRecord scope :closes, -> { where(aasm_state: [:close, :depubliee]) } scope :opendata, -> { where(opendata: true) } scope :publiees_ou_closes, -> { where(aasm_state: [:publiee, :close, :depubliee]) } + + scope :publiques, -> do + publiees_ou_closes + .opendata + .where('estimated_dossiers_count >= ?', 4) + .where.not('lien_site_web LIKE ?', '%mail%') + .where.not('lien_site_web LIKE ?', '%intra%') + end + scope :by_libelle, -> { order(libelle: :asc) } scope :created_during, -> (range) { where(created_at: range) } scope :cloned_from_library, -> { where(cloned_from_library: true) } diff --git a/spec/jobs/cron/datagouv/export_and_publish_demarches_publiques_job_spec.rb b/spec/jobs/cron/datagouv/export_and_publish_demarches_publiques_job_spec.rb index f12068bb8..42a40377c 100644 --- a/spec/jobs/cron/datagouv/export_and_publish_demarches_publiques_job_spec.rb +++ b/spec/jobs/cron/datagouv/export_and_publish_demarches_publiques_job_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Cron::Datagouv::ExportAndPublishDemarchesPubliquesJob, type: :job do - let!(:procedure) { create(:procedure, :published, :with_service, :with_type_de_champ) } + let!(:procedure) { create(:procedure, :published, :with_service, :with_type_de_champ, estimated_dossiers_count: 4) } let(:status) { 200 } let(:body) { "ok" } let(:stub) { stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/.*\/upload\//) } diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 80159b85d..5ee3de641 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -395,6 +395,39 @@ describe Procedure do end end + describe 'publiques' do + let(:draft_procedure) { create(:procedure_with_dossiers, :draft, estimated_dossiers_count: 4, lien_site_web: 'https://monministere.gouv.fr/cparici') } + let(:published_procedure) { create(:procedure_with_dossiers, :published, estimated_dossiers_count: 4, lien_site_web: 'https://monministere.gouv.fr/cparici') } + let(:published_procedure_no_opendata) { create(:procedure_with_dossiers, :published, estimated_dossiers_count: 4, opendata: false) } + let(:published_procedure_with_3_dossiers) { create(:procedure_with_dossiers, :published, estimated_dossiers_count: 3) } + let(:published_procedure_with_mail) { create(:procedure_with_dossiers, :published, estimated_dossiers_count: 4, lien_site_web: 'par mail') } + let(:published_procedure_with_intra) { create(:procedure_with_dossiers, :published, estimated_dossiers_count: 4, lien_site_web: 'https://intra.service-etat.gouv.fr') } + + it 'returns published procedure, with opendata flag, with accepted lien_site_web' do + expect(Procedure.publiques).not_to include(published_procedure_no_opendata) + end + + it "returns only published or closed procedures" do + expect(Procedure.publiques).not_to include(draft_procedure) + end + + it "returns only procedures with opendata flag" do + expect(Procedure.publiques).not_to include(published_procedure_with_mail) + end + + it "returns only procedures without mail in lien_site_web" do + expect(Procedure.publiques).not_to include(published_procedure_with_mail) + end + + it "returns only procedures without intra in lien_site_web" do + expect(Procedure.publiques).not_to include(published_procedure_with_intra) + end + + it "does not return procedures with less than 4 dossiers" do + expect(Procedure.publiques).not_to include(published_procedure_with_3_dossiers) + end + end + describe 'active' do let(:procedure) { create(:procedure) } subject { Procedure.active(procedure.id) } diff --git a/spec/services/demarches_publiques_export_service_spec.rb b/spec/services/demarches_publiques_export_service_spec.rb index bec59a795..f29dc79ad 100644 --- a/spec/services/demarches_publiques_export_service_spec.rb +++ b/spec/services/demarches_publiques_export_service_spec.rb @@ -1,5 +1,5 @@ describe DemarchesPubliquesExportService do - let(:procedure) { create(:procedure, :published, :with_service, :with_type_de_champ) } + let(:procedure) { create(:procedure, :published, :with_service, :with_type_de_champ, estimated_dossiers_count: 4) } let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) } let(:gzip_filename) { "demarches.json.gz" }