2018-01-05 11:16:50 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe FindDubiousProceduresJob, type: :job do
|
|
|
|
describe 'perform' do
|
2018-05-25 18:05:28 +02:00
|
|
|
let(:mailer_double) { double('mailer', deliver_later: true) }
|
2018-01-05 11:16:50 +01:00
|
|
|
let(:procedure) { create(:procedure) }
|
2018-02-13 17:00:19 +01:00
|
|
|
let(:allowed_tdc) { create(:type_de_champ, libelle: 'fournir') }
|
2018-01-05 11:16:50 +01:00
|
|
|
|
|
|
|
before do
|
2018-03-27 11:31:35 +02:00
|
|
|
allow(AdministrationMailer).to receive(:dubious_procedures) do |arg|
|
|
|
|
@dubious_procedures_args = arg
|
|
|
|
end.and_return(mailer_double)
|
2018-01-05 11:16:50 +01:00
|
|
|
|
|
|
|
procedure.types_de_champ << tdcs
|
|
|
|
FindDubiousProceduresJob.new.perform
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with suspicious champs' do
|
|
|
|
let(:forbidden_tdcs) do
|
2018-01-15 14:42:48 +01:00
|
|
|
[
|
2018-02-13 17:00:19 +01:00
|
|
|
create(:type_de_champ, libelle: 'num de securite sociale, stp'),
|
|
|
|
create(:type_de_champ, libelle: "t'aurais une carte bancaire ?")
|
2018-01-15 14:42:48 +01:00
|
|
|
]
|
2018-01-05 11:16:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:tdcs) { forbidden_tdcs + [allowed_tdc] }
|
|
|
|
|
|
|
|
it 'mails tech about the dubious procedure' do
|
2018-03-27 11:31:35 +02:00
|
|
|
receive_procedure, receive_forbidden_tdcs = @dubious_procedures_args[0]
|
|
|
|
|
|
|
|
expect(receive_procedure).to eq(procedure)
|
2018-05-09 18:44:09 +02:00
|
|
|
expect(receive_forbidden_tdcs).to match_array(forbidden_tdcs)
|
2018-05-07 12:24:05 +02:00
|
|
|
|
|
|
|
expect(AdministrationMailer).to have_received(:dubious_procedures).with(@dubious_procedures_args)
|
2018-01-05 11:16:50 +01:00
|
|
|
end
|
|
|
|
|
2018-01-05 17:08:43 +01:00
|
|
|
context 'and a whitelisted procedure' do
|
|
|
|
let(:procedure) { create(:procedure, whitelisted_at: DateTime.now) }
|
|
|
|
|
2018-05-07 12:24:05 +02:00
|
|
|
it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) }
|
2018-01-05 17:08:43 +01:00
|
|
|
end
|
|
|
|
|
2018-01-05 11:16:50 +01:00
|
|
|
context 'and a archived procedure' do
|
|
|
|
let(:procedure) { create(:procedure, archived_at: DateTime.now) }
|
|
|
|
|
2018-05-07 12:24:05 +02:00
|
|
|
it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) }
|
2018-01-05 11:16:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no suspicious champs' do
|
|
|
|
let(:tdcs) { [allowed_tdc] }
|
|
|
|
|
2018-05-07 12:24:05 +02:00
|
|
|
it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) }
|
2018-01-05 11:16:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|