demarches-normaliennes/spec/jobs/api_entreprise/exercices_job_spec.rb

24 lines
869 B
Ruby
Raw Normal View History

# frozen_string_literal: true
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
2023-05-29 16:45:21 +02:00
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/dgfip\/etablissements\/#{siret}\/chiffres_affaires/)
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
ca_list = Etablissement.find(etablissement.id).exercices.map(&:ca)
2023-05-29 16:45:21 +02:00
expect(ca_list).to contain_exactly('900001', '1900051')
2020-05-14 10:56:26 +02:00
end
end