Merge pull request #7992 from demarches-simplifiees/add-file-depose-at-datagouv

Ajoute les dossiers déposés dans les statistiques Datagouv
This commit is contained in:
Kara Diaby 2022-11-03 11:46:52 +01:00 committed by GitHub
commit 5867f2cbe7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View file

@ -0,0 +1,19 @@
class Cron::Datagouv::FileDeposeByMonthJob < Cron::CronJob
include DatagouvCronSchedulableConcern
self.schedule_expression = "every month at 3:00"
FILE_NAME = "nb_dossiers_deposes_par_mois"
def perform(*args)
GenerateOpenDataCsvService.save_csv_to_tmp(FILE_NAME, data) do |file|
begin
APIDatagouv::API.upload(file, :statistics_dataset)
ensure
FileUtils.rm(file)
end
end
end
def data
Dossier.where(depose_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month).count
end
end

View file

@ -0,0 +1,19 @@
RSpec.describe Cron::Datagouv::FileDeposeByMonthJob, type: :job do
let!(:dossier) { create(:dossier, created_at: 1.month.ago) }
let(:status) { 200 }
let(:body) { "ok" }
let(:stub) { stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/.*\/upload\//) }
describe 'perform' do
before do
stub
end
subject { Cron::Datagouv::FileByMonthJob.perform_now }
it 'send POST request to datagouv' do
subject
expect(stub).to have_been_requested
end
end
end