-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
251 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class EditableChamp::RNFComponent < EditableChamp::EditableChampBaseComponent | ||
end |
5 changes: 5 additions & 0 deletions
5
app/components/editable_champ/rnf_component/rnf_component.en.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
en: | ||
rnf_info_error: No fondation found | ||
rnf_info_pending: RNF verification pending | ||
rnf_info_success: "This RNF matches %{title}" |
5 changes: 5 additions & 0 deletions
5
app/components/editable_champ/rnf_component/rnf_component.fr.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
fr: | ||
rnf_info_error: Aucune fondation trouvée | ||
rnf_info_pending: Vérification du RNF en cours | ||
rnf_info_success: "Ce RNF correspond à %{title}" |
9 changes: 9 additions & 0 deletions
9
app/components/editable_champ/rnf_component/rnf_component.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
= @form.text_field :external_id, required: @champ.required?, class: "width-33-desktop fr-input small-margin", id: @champ.input_id | ||
|
||
.rnf-info{ id: dom_id(@champ, :rnf_info) } | ||
- if @champ.fetch_external_data_error? | ||
%p.fr-error-text= t('.rnf_info_error') | ||
- elsif @champ.fetch_external_data_pending? | ||
%p.fr-info-text= t('.rnf_info_pending') | ||
- elsif @champ.data? | ||
%p.fr-info-text= t('.rnf_info_success', title: @champ.title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Champs::RNFChamp < Champ | ||
store_accessor :data, :title, :email, :phone, :createdAt, :updatedAt, :dissolvedAt, :address, :status | ||
|
||
def rnf_id | ||
external_id | ||
end | ||
|
||
def fetch_external_data | ||
RNFService.new.(rnf_id:) | ||
end | ||
|
||
def fetch_external_data? | ||
true | ||
end | ||
|
||
def poll_external_data? | ||
true | ||
end | ||
|
||
def blank? | ||
rnf_id.blank? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class TypesDeChamp::RNFTypeDeChamp < TypesDeChamp::TextTypeDeChamp | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "http://demarches-simplifiees.fr/rnf.schema.json", | ||
"title": "RNF", | ||
"type": "object", | ||
"properties": { | ||
"id": { "type": "integer" }, | ||
"rnfId": { "type": "string" }, | ||
"type": { "type": "string" }, | ||
"department": { "type": "string" }, | ||
"title": { "type": "string" }, | ||
"dissolvedAt": { "type": ["string", "null"] }, | ||
"phone": { "type": "string" }, | ||
"email": { "type": "string" }, | ||
"addressId": { "type": "integer" }, | ||
"address": { | ||
"id": { "type": "integer" }, | ||
"createdAt":{ "type": "string" }, | ||
"updatedAt":{ "type": "string" }, | ||
"label":{ "type": "string" }, | ||
"type":{ "type": "string" }, | ||
"streetAddress":{ "type": "string" }, | ||
"streetNumber":{ "type": "string" }, | ||
"streetName":{ "type": "string" }, | ||
"postalCode":{ "type": "string" }, | ||
"cityName":{ "type": "string" }, | ||
"cityCode":{ "type": "string" }, | ||
"departmentName":{ "type": "string" }, | ||
"departmentCode":{ "type": "string" }, | ||
"regionName":{ "type": "string" }, | ||
"regionCode":{ "type": "string" } | ||
}, | ||
"status": { "type": ["string", "null"] }, | ||
"persons": { "type": "array" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class RNFService | ||
include Dry::Monads[:result] | ||
|
||
def call(rnf_id:) | ||
result = API::Client.new.(url: "#{url}/#{rnf_id}", schema:) | ||
case result | ||
in Success(body:) | ||
Success(body) | ||
in Failure(code:, reason:) if code.in?(401..403) | ||
Failure(API::Client::Error[:unauthorized, code, false, reason]) | ||
else | ||
result | ||
end | ||
end | ||
|
||
private | ||
|
||
def schema | ||
JSONSchemer.schema(Rails.root.join('app/schemas/rnf.json')) | ||
end | ||
|
||
def url | ||
"#{API_RNF_URL}/api/foundations" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"id":3, | ||
"createdAt":"2023-09-07T13:26:10.358Z", | ||
"updatedAt":"2023-09-07T13:26:10.358Z", | ||
"rnfId": 750000301 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"id":3, | ||
"createdAt":"2023-09-07T13:26:10.358Z", | ||
"updatedAt":"2023-09-07T13:26:10.358Z", | ||
"rnfId":"075-FDD-00003-01", | ||
"type":"FDD", | ||
"department":"75", | ||
"title":"Fondation SFR", | ||
"dissolvedAt":null, | ||
"phone":"+33185060000", | ||
"email":"[email protected]", | ||
"addressId":3, | ||
"address": { | ||
"id":3, | ||
"createdAt":"2023-09-07T13:26:10.358Z", | ||
"updatedAt":"2023-09-07T13:26:10.358Z", | ||
"label":"16 Rue du Général de Boissieu 75015 Paris", | ||
"type":"housenumber", | ||
"streetAddress":"16 Rue du Général de Boissieu", | ||
"streetNumber":"16", | ||
"streetName":"Rue du Général de Boissieu", | ||
"postalCode":"75015", | ||
"cityName":"Paris", | ||
"cityCode":"75115", | ||
"departmentName":"Paris", | ||
"departmentCode":"75", | ||
"regionName":"Île-de-France", | ||
"regionCode":"11" | ||
}, | ||
"status":null, | ||
"persons":[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
describe Champs::RNFChamp, type: :model do | ||
let(:champ) { build(:champ_rnf, external_id:) } | ||
let(:stub) { stub_request(:get, "#{url}/#{external_id}").to_return(body:, status:) } | ||
let(:url) { RNFService.new.send(:url) } | ||
let(:body) { Rails.root.join('spec', 'fixtures', 'files', 'api_rnf', "#{response_type}.json").read } | ||
let(:external_id) { '075-FDD-00003-01' } | ||
let(:status) { 200 } | ||
let(:response_type) { 'valid' } | ||
|
||
describe 'fetch_external_data' do | ||
subject { stub; champ.fetch_external_data } | ||
|
||
context 'success' do | ||
it do | ||
expect(subject.value!).to eq({ | ||
id: 3, | ||
rnfId: '075-FDD-00003-01', | ||
type: 'FDD', | ||
department: '75', | ||
title: 'Fondation SFR', | ||
dissolvedAt: nil, | ||
phone: '+33185060000', | ||
email: '[email protected]', | ||
addressId: 3, | ||
createdAt: "2023-09-07T13:26:10.358Z", | ||
updatedAt: "2023-09-07T13:26:10.358Z", | ||
address: { | ||
id: 3, | ||
createdAt: "2023-09-07T13:26:10.358Z", | ||
updatedAt: "2023-09-07T13:26:10.358Z", | ||
label: "16 Rue du Général de Boissieu 75015 Paris", | ||
type: "housenumber", | ||
streetAddress: "16 Rue du Général de Boissieu", | ||
streetNumber: "16", | ||
streetName: "Rue du Général de Boissieu", | ||
postalCode: "75015", | ||
cityName: "Paris", | ||
cityCode: "75115", | ||
departmentName: "Paris", | ||
departmentCode: "75", | ||
regionName: "Île-de-France", | ||
regionCode: "11" | ||
}, | ||
status: nil, | ||
persons: [] | ||
}) | ||
end | ||
end | ||
|
||
context 'failure (schema)' do | ||
let(:response_type) { 'invalid' } | ||
it { | ||
expect(subject.failure.retryable).to be_falsey | ||
expect(subject.failure.reason).to be_a(API::Client::SchemaError) | ||
} | ||
end | ||
|
||
context 'failure (http 500)' do | ||
let(:status) { 500 } | ||
let(:response_type) { 'invalid' } | ||
it { | ||
expect(subject.failure.retryable).to be_truthy | ||
expect(subject.failure.reason).to be_a(API::Client::HTTPError) | ||
} | ||
end | ||
|
||
context 'failure (http 401)' do | ||
let(:status) { 401 } | ||
let(:response_type) { 'invalid' } | ||
it { | ||
expect(subject.failure.retryable).to be_falsey | ||
expect(subject.failure.reason).to be_a(API::Client::HTTPError) | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters