fix(manager): remove admins added for a day

fix #6855
This commit is contained in:
Paul Chavard 2022-02-02 18:49:39 +01:00
parent f0de64a787
commit 0268511264
2 changed files with 24 additions and 1 deletions

View file

@ -2,6 +2,7 @@ class Cron::PurgeManagerAdministrateurSessionsJob < Cron::CronJob
self.schedule_expression = "every day at 3 am"
def perform
AdministrateursProcedure.where(manager: true).destroy_all
# TODO: add id column to administrateurs_procedures and use destroy_all
AdministrateursProcedure.where(manager: true).delete_all
end
end

View file

@ -0,0 +1,22 @@
RSpec.describe Cron::PurgeManagerAdministrateurSessionsJob, type: :job do
describe 'perform' do
let(:administrateur) { create(:administrateur) }
let(:procedure) { create(:procedure) }
subject { Cron::PurgeManagerAdministrateurSessionsJob.perform_now }
context "with an inactive administrateur" do
before do
AdministrateursProcedure.create(procedure: procedure, administrateur: administrateur, manager: true)
expect(AdministrateursProcedure.where(manager: true).count).to eq(1)
expect(AdministrateursProcedure.count).to eq(2)
subject
end
it {
expect(AdministrateursProcedure.where(manager: true).count).to eq(0)
expect(AdministrateursProcedure.count).to eq(1)
}
end
end
end