publish only some opendata procedures for datagouv
- only published or closed procedures - only procedures with flag opendata - only procedures with 4 or more dossiers - only procedures without word "mail" in lien_site_web - only procedures without word "intra" in lien_site_web
This commit is contained in:
parent
7e13d58db2
commit
9ff88db48c
5 changed files with 45 additions and 3 deletions
|
@ -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:)
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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\//) }
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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" }
|
||||
|
||||
|
|
Loading…
Reference in a new issue