fix(cojo): invalid accreditation should result in a blank champ

This commit is contained in:
Paul Chavard 2023-07-10 19:15:39 +02:00
parent e2a9978c26
commit 95f7ca0f44
2 changed files with 32 additions and 3 deletions

View file

@ -19,7 +19,7 @@ class Champs::COJOChamp < Champ
end
def blank?
accreditation_success.nil?
accreditation_success != true
end
def fetch_external_data?

View file

@ -1,12 +1,12 @@
describe Champs::COJOChamp, type: :model do
let(:champ) { build(:champ_cojo, accreditation_number:, accreditation_birthdate:) }
let(:external_id) { nil }
let(:stub) { stub_request(:post, url).with(body: { accreditationNumber: accreditation_number, birthdate: accreditation_birthdate }).to_return(body:, status:) }
let(:stub) { stub_request(:post, url).with(body: { accreditationNumber: accreditation_number.to_i, birthdate: accreditation_birthdate }).to_return(body:, status:) }
let(:url) { COJOService.new.send(:url) }
let(:body) { Rails.root.join('spec', 'fixtures', 'files', 'api_cojo', "accreditation_#{response_type}.json").read }
let(:status) { 200 }
let(:response_type) { 'yes' }
let(:accreditation_number) { 123456 }
let(:accreditation_number) { '123456' }
let(:accreditation_birthdate) { '21/12/1959' }
describe 'fetch_external_data' do
@ -47,4 +47,33 @@ describe Champs::COJOChamp, type: :model do
}
end
end
describe 'fill champ' do
let(:champ) { create(:champ_cojo, accreditation_number:, accreditation_birthdate:) }
subject { stub; champ.touch; perform_enqueued_jobs; champ.reload }
it 'success (yes)' do
expect(subject.blank?).to be_falsey
end
context 'success (no)' do
let(:response_type) { 'no' }
it { expect(subject.blank?).to be_truthy }
end
context 'failure (schema)' do
let(:response_type) { 'invalid' }
it { expect(subject.blank?).to be_truthy }
end
context 'failure (http 401)' do
let(:status) { 401 }
let(:response_type) { 'invalid' }
it { expect(subject.blank?).to be_truthy }
end
end
end