|
79 | 79 | end |
80 | 80 | end |
81 | 81 |
|
| 82 | + describe '#external_data_status_message' do |
| 83 | + let(:champ) { Champs::SiretChamp.new } |
| 84 | + |
| 85 | + it 'returns nil when fetched' do |
| 86 | + allow(champ).to receive_messages(pending?: false, external_error?: false) |
| 87 | + expect(champ.external_data_status_message).to be_nil |
| 88 | + end |
| 89 | + |
| 90 | + it 'returns :pending when pending and not required for conditions' do |
| 91 | + allow(champ).to receive_messages(pending?: true, external_error?: false, external_data_required_for_conditions?: false) |
| 92 | + expect(champ.external_data_status_message).to eq(:pending) |
| 93 | + end |
| 94 | + |
| 95 | + it 'returns :technical_error on external_error with non-not_found kind' do |
| 96 | + allow(champ).to receive_messages( |
| 97 | + pending?: false, external_error?: true, |
| 98 | + external_data_required_for_conditions?: false, |
| 99 | + fetch_external_data_exceptions: [ExternalDataException.new(error: 'x', code: 503, kind: :technical_error)] |
| 100 | + ) |
| 101 | + expect(champ.external_data_status_message).to eq(:technical_error) |
| 102 | + end |
| 103 | + |
| 104 | + it 'returns nil on :not_found (handled by the validation error)' do |
| 105 | + allow(champ).to receive_messages( |
| 106 | + pending?: false, external_error?: true, |
| 107 | + external_data_required_for_conditions?: false, |
| 108 | + fetch_external_data_exceptions: [ExternalDataException.new(error: 'x', code: 404, kind: :not_found)] |
| 109 | + ) |
| 110 | + expect(champ.external_data_status_message).to be_nil |
| 111 | + end |
| 112 | + |
| 113 | + it 'returns nil when external_data_required_for_conditions? is true' do |
| 114 | + allow(champ).to receive_messages(pending?: true, external_error?: false, external_data_required_for_conditions?: true) |
| 115 | + expect(champ.external_data_status_message).to be_nil |
| 116 | + end |
| 117 | + end |
| 118 | + |
82 | 119 | describe 'the state machine' do |
83 | 120 | let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :rnf }]) } |
84 | 121 | let(:dossier) { create(:dossier, procedure:) } |
|
0 commit comments