2023-02-28 13:55:52 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Champs::AnnuaireEducationChamp do
|
|
|
|
describe '#update_with_external_data!' do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :annuaire_education }]) }
|
|
|
|
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
|
|
|
|
let(:champ) { dossier.champs.first.tap { _1.update_column(:data, 'any data') } }
|
2023-02-28 13:55:52 +01:00
|
|
|
subject { champ.update_with_external_data!(data: data) }
|
|
|
|
|
|
|
|
shared_examples "a data updater (without updating the value)" do |data|
|
|
|
|
it { expect { subject }.to change { champ.reload.data }.to(data) }
|
|
|
|
it { expect { subject }.not_to change { champ.reload.value } }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when data is nil' do
|
|
|
|
let(:data) { nil }
|
|
|
|
it_behaves_like "a data updater (without updating the value)", nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when data is empty' do
|
|
|
|
let(:data) { '' }
|
|
|
|
it_behaves_like "a data updater (without updating the value)", ''
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when data is consistent' do
|
|
|
|
let(:data) {
|
|
|
|
{
|
2024-05-07 21:37:54 +02:00
|
|
|
'nom_etablissement' => "karrigel an ankou",
|
2023-02-28 13:55:52 +01:00
|
|
|
'nom_commune' => 'kumun',
|
|
|
|
'identifiant_de_l_etablissement' => '666667'
|
2024-05-07 21:37:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
it_behaves_like "a data updater (without updating the value)", {
|
|
|
|
'nom_etablissement' => "karrigel an ankou",
|
|
|
|
'nom_commune' => 'kumun',
|
|
|
|
'identifiant_de_l_etablissement' => '666667'
|
2023-02-28 13:55:52 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|