add admin update default zones job
This commit is contained in:
parent
34540d34e9
commit
ca922005f9
2 changed files with 27 additions and 0 deletions
6
app/jobs/admin_update_default_zones_job.rb
Normal file
6
app/jobs/admin_update_default_zones_job.rb
Normal 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
|
21
spec/jobs/admin_update_default_zones_job_spec.rb
Normal file
21
spec/jobs/admin_update_default_zones_job_spec.rb
Normal 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
|
Loading…
Reference in a new issue