demarches-normaliennes/spec/jobs/cron/find_dubious_procedures_job_spec.rb

62 lines
2 KiB
Ruby
Raw Normal View History

RSpec.describe Cron::FindDubiousProceduresJob, type: :job do
describe 'perform' do
let(:mailer_double) { double('mailer', deliver_later: true) }
2020-08-27 19:57:01 +02:00
let(:procedure) { create(:procedure, types_de_champ: tdcs) }
let(:allowed_tdc) { build(:type_de_champ, libelle: 'fournir') }
before do
2020-08-27 19:57:01 +02:00
procedure
allow(AdministrationMailer).to receive(:dubious_procedures) do |arg|
@dubious_procedures_args = arg
end.and_return(mailer_double)
Cron::FindDubiousProceduresJob.new.perform
end
context 'with suspicious champs' do
let(:forbidden_tdcs) do
[
2020-08-27 19:57:01 +02:00
build(:type_de_champ, libelle: 'num de securite sociale, stp'),
build(:type_de_champ, libelle: "t'aurais une carte bancaire ?")
]
end
let(:tdcs) { forbidden_tdcs + [allowed_tdc] }
it 'mails tech about the dubious procedure' do
receive_procedure, receive_forbidden_tdcs = @dubious_procedures_args[0]
expect(receive_procedure).to eq(procedure)
expect(receive_forbidden_tdcs).to match_array(forbidden_tdcs)
expect(AdministrationMailer).to have_received(:dubious_procedures).with(@dubious_procedures_args)
end
context 'and a whitelisted procedure' do
2018-05-30 14:21:17 +02:00
let(:procedure) { create(:procedure, :whitelisted) }
it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) }
end
context 'and a closed procedure' do
let(:procedure) { create(:procedure, :closed) }
it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) }
end
2020-02-05 16:09:03 +01:00
context 'and a discarded procedure' do
let(:procedure) { create(:procedure, :discarded) }
it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) }
end
end
context 'with no suspicious champs' do
let(:tdcs) { [allowed_tdc] }
it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) }
end
end
end