add admin update default zones job

This commit is contained in:
Christophe Robillard 2023-03-31 15:25:17 +02:00
parent 34540d34e9
commit ca922005f9
2 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,6 @@
class AdminUpdateDefaultZonesJob < ApplicationJob
def perform(admin)
tchap_hs = APITchap::HsAdapter.new(admin.email).to_hs
admin.default_zones << Zone.default_for(tchap_hs)
end
end

View file

@ -0,0 +1,21 @@
# frozen_string_literal: true
require 'rails_helper'
describe AdminUpdateDefaultZonesJob, type: :job do
let(:email) { 'louise@educ.pop.gouv.fr' }
let(:admin) { create(:administrateur, email: email) }
let(:hs_adapter) { double('hs_adapter', to_hs: 'agent.educpop.tchap.gouv.fr') }
subject(:perform_job) { described_class.perform_now(admin) }
before do
allow(APITchap::HsAdapter).to receive(:new).with(email).and_return(hs_adapter)
create(:zone, acronym: 'EP', tchap_hs: ['agent.educpop.tchap.gouv.fr'])
end
it 'update default zones' do
perform_job
expect(admin.default_zones.map(&:acronym)).to eq ['EP']
end
end