2020-08-05 18:40:47 +02:00
|
|
|
RSpec.describe APIEntreprise::ExercicesJob, type: :job do
|
2020-05-14 10:56:26 +02:00
|
|
|
let(:siret) { '41816609600051' }
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
let(:etablissement) { create(:etablissement, siret: siret) }
|
|
|
|
let(:body) { File.read('spec/fixtures/files/api_entreprise/exercices.json') }
|
|
|
|
let(:status) { 200 }
|
|
|
|
|
|
|
|
before do
|
2020-12-10 15:28:39 +01:00
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\//)
|
2020-05-14 10:56:26 +02:00
|
|
|
.to_return(body: body, status: status)
|
2020-08-05 18:40:47 +02:00
|
|
|
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
2020-05-14 10:56:26 +02:00
|
|
|
end
|
|
|
|
|
2020-08-05 18:40:47 +02:00
|
|
|
subject { APIEntreprise::ExercicesJob.new.perform(etablissement.id, procedure.id) }
|
2020-05-14 10:56:26 +02:00
|
|
|
|
|
|
|
it 'updates etablissement' do
|
|
|
|
subject
|
2021-05-07 10:41:45 +02:00
|
|
|
ca_list = Etablissement.find(etablissement.id).exercices.map(&:ca)
|
|
|
|
expect(ca_list).to contain_exactly('21009417', '18968298', '17768838')
|
2020-05-14 10:56:26 +02:00
|
|
|
end
|
|
|
|
end
|