-
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.
feat(referentiel_service): basic implementation pour call API
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
class ReferentielService | ||
def test | ||
case type_de_champ.referentiel_adapter | ||
when 'url' | ||
ReferentielApiClient.new(type_de_champ:).valid?(type_de_champ.referentiel_test_data) | ||
else | ||
fail "not yet implemented: #{type_de_champ.referentiel_adapter}" | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :type_de_champ | ||
def initialize(type_de_champ:) | ||
@type_de_champ = type_de_champ | ||
end | ||
|
||
class ReferentielApiClient | ||
attr_reader :type_de_champ | ||
def initialize(type_de_champ:) | ||
@type_de_champ = type_de_champ | ||
end | ||
|
||
def valid?(value) | ||
case call(value) | ||
when Dry::Monads[:result]::Success | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
def call(value) = API::Client.new.(url: build_url(value)) | ||
|
||
def build_url(value) | ||
original_url = @type_de_champ.referentiel_url | ||
|
||
original_url.gsub('{id}', value) | ||
end | ||
end | ||
end | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 @@ | ||
RSpec.describe ReferentielService, type: :service do | ||
describe '.test' do | ||
let(:type_de_champ) do | ||
build(:type_de_champ_referentiel, referentiel_url:, referentiel_test_data:, referentiel_adapter:) | ||
end | ||
let(:referentiel_adapter) { 'url' } | ||
let(:referentiel_url) { "https://api.fr/{id}/" } | ||
let(:referentiel_test_data) { "kthxbye" } | ||
|
||
context 'when referentiel_adapter is url', vcr: 'referentiel/test' do | ||
subject { described_class.new(type_de_champ:).test } | ||
|
||
it { is_expected.to eq(true) } | ||
end | ||
end | ||
end |