notify admin with service without siret
This commit is contained in:
parent
8ad87de461
commit
20d70d2b1c
5 changed files with 101 additions and 0 deletions
|
@ -22,6 +22,14 @@ class AdministrateurMailer < ApplicationMailer
|
|||
reply_to: CONTACT_EMAIL)
|
||||
end
|
||||
|
||||
def notify_service_without_siret(user_email)
|
||||
@subject = "Siret manquant sur un de vos services"
|
||||
|
||||
mail(to: user_email,
|
||||
subject: @subject,
|
||||
reply_to: CONTACT_EMAIL)
|
||||
end
|
||||
|
||||
def api_token_expiration(user, tokens)
|
||||
@subject = "Renouvellement de jeton d'API nécessaire"
|
||||
@tokens = tokens
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
- content_for(:title, "Service avec Siret manquant")
|
||||
|
||||
%p
|
||||
Bonjour,
|
||||
|
||||
%p
|
||||
Vous êtes administrateur sur la plateforme
|
||||
= APPLICATION_NAME
|
||||
et au moins un de vos services n'a pas son siret renseigné.
|
||||
|
||||
%p
|
||||
Afin d'éviter tout dysfonctionnement sur la plateforme, nous vous invitons à le remplir au plus vite à cette adresse :
|
||||
= link_to admin_procedures_url, admin_procedures_url
|
||||
|
||||
= render partial: "layouts/mailers/signature"
|
||||
|
21
lib/tasks/clean_services.rake
Normal file
21
lib/tasks/clean_services.rake
Normal file
|
@ -0,0 +1,21 @@
|
|||
namespace :service do
|
||||
desc 'remove service without procedure'
|
||||
task remove_orphans: :environment do
|
||||
puts "Destroying services without procedure..."
|
||||
Service.joins('LEFT OUTER JOIN "procedures" ON "procedures"."service_id" = "services"."id"')
|
||||
.where(procedures: { id: nil })
|
||||
.destroy_all
|
||||
puts "Services without procedure destroyed"
|
||||
end
|
||||
|
||||
desc 'email admins with published procedures with service without siret'
|
||||
task email_no_siret: :environment do
|
||||
admins = Administrateur.joins(:administrateurs_procedures).where(administrateurs_procedures: { procedure: Procedure.publiees.joins(:service).where(service: { siret: nil }) })
|
||||
progress = ProgressReport.new(admins.count)
|
||||
|
||||
admins.each do |admin|
|
||||
AdministrateurMailer.notify_service_without_siret(admin.email).deliver
|
||||
progress.inc
|
||||
end
|
||||
end
|
||||
end
|
49
spec/lib/tasks/clean_services_spec.rb
Normal file
49
spec/lib/tasks/clean_services_spec.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
describe 'service tasks' do
|
||||
let(:rake_task) { Rake::Task[task] }
|
||||
subject { rake_task.invoke }
|
||||
after(:each) do
|
||||
rake_task.reenable
|
||||
end
|
||||
|
||||
describe 'service:remove_orphans' do
|
||||
let(:task) { 'service:remove_orphans' }
|
||||
let(:service) { create(:service) }
|
||||
let(:procedure) { create(:procedure, :with_service) }
|
||||
let(:service_with_procedure) { procedure.service }
|
||||
it 'remove orphans' do
|
||||
service
|
||||
service_with_procedure
|
||||
|
||||
subject
|
||||
|
||||
expect(Service.find_by(id: service.id)).to be_nil
|
||||
expect(Service.find_by(id: service_with_procedure.id)).to eq service_with_procedure
|
||||
end
|
||||
end
|
||||
|
||||
describe 'service:notify_no_siret' do
|
||||
let(:task) { 'service:email_no_siret' }
|
||||
let!(:procedure_without_siret_service) { create(:procedure, :published, service: service, administrateur: administrateur) }
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
let(:service) do
|
||||
s = build(:service, siret: nil, administrateur: administrateur)
|
||||
s.save(validate: false)
|
||||
s
|
||||
end
|
||||
let!(:procedure_with_siret_service) { create(:procedure, :published, service: siret_service, administrateur: administrateur_with_siret_service) }
|
||||
let(:siret_service) { create(:service, administrateur: administrateur_with_siret_service) }
|
||||
let(:administrateur_with_siret_service) { create(:administrateur) }
|
||||
|
||||
it 'emails admins with published procedures with services without siret' do
|
||||
message = double("message")
|
||||
allow(message).to receive(:deliver)
|
||||
allow(AdministrateurMailer).to receive(:notify_service_without_siret).with(administrateur.email).and_return(message)
|
||||
allow(AdministrateurMailer).to receive(:notify_service_without_siret).with(administrateur_with_siret_service.email).and_return(message)
|
||||
|
||||
subject
|
||||
|
||||
expect(AdministrateurMailer).to have_received(:notify_service_without_siret).with(administrateur.email).once
|
||||
expect(AdministrateurMailer).not_to have_received(:notify_service_without_siret).with(administrateur_with_siret_service.email)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -22,4 +22,11 @@ RSpec.describe AdministrateurMailer, type: :mailer do
|
|||
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(forced_delivery_method.to_s) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '.notify_service_without_siret' do
|
||||
subject { described_class.notify_service_without_siret(admin_email) }
|
||||
it { expect(subject.to).to eq([admin_email]) }
|
||||
it { expect(subject.subject).to eq("Siret manquant sur un de vos services") }
|
||||
it { expect(subject.body).to include("un de vos services n'a pas son siret renseigné") }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue