Skip to content

Commit

Permalink
rspec: file_state_by_month.job
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoit-MINT committed Oct 3, 2024
1 parent c8671bc commit 4ec6659
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/jobs/cron/datagouv/file_state_by_month_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Cron::Datagouv::FileStateByMonthJob < Cron::CronJob
include DatagouvCronSchedulableConcern
self.schedule_expression = "every month at 3:20"
Expand Down
70 changes: 70 additions & 0 deletions spec/jobs/cron/datagouv/file_by_state_by_month_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# frozen_string_literal: true

RSpec.describe Cron::Datagouv::FileStateByMonthJob, type: :job do
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::FileStateByMonthJob.perform_now }

it 'send POST request to datagouv' do
subject
expect(stub).to have_been_requested
end
end

describe '#data' do
let!(:procedure) { create(:procedure, :published, estimated_dossiers_count: 300, opendata: true) }
let!(:dossier_brouillon) { create(:dossier, state: :brouillon, procedure:) }
let!(:dossier_depose) { create(:dossier, state: :en_construction, procedure:) }
let!(:dossier_en_instruction) { create(:dossier, state: :en_instruction, procedure:) }
let!(:dossier_accepte) { create(:dossier, state: :accepte, procedure:) }
let!(:dossier_refuse) { create(:dossier, state: :refuse, procedure:) }
let!(:dossier_sans_suite) { create(:dossier, state: :sans_suite, procedure:) }

subject { Cron::Datagouv::FileStateByMonthJob.new.data }

context 'when all conditions are met' do
it 'returns the correct data and structure' do
expect(subject).to match_array(
[[procedure.id, 1, 1, 1, 3]]
)
end
end

context 'when the procedure is not opendata' do
before do
procedure.update(opendata: false)
end

it 'does not include the procedure' do
expect(subject).to be_empty
end
end

context 'when the procedure has insufficient number of dossiers' do
before do
procedure.update(estimated_dossiers_count: 299)
end

it 'does not include the procedure' do
expect(subject).to be_empty
end
end

context 'when the procedure has several revisions' do
before do
procedure.publish_revision!
end

it 'only considers the published revision' do
expect(subject).to be_empty
end
end
end
end

0 comments on commit 4ec6659

Please sign in to comment.