Skip to content

Commit

Permalink
feat(referentiel_service): basic implementation pour call API
Browse files Browse the repository at this point in the history
  • Loading branch information
mfo committed Dec 23, 2024
1 parent 98ce4a6 commit c7b4448
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
41 changes: 41 additions & 0 deletions app/services/referentiel_service.rb
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

Check warning on line 9 in app/services/referentiel_service.rb

View check run for this annotation

Codecov / codecov/patch

app/services/referentiel_service.rb#L1-L9

Added lines #L1 - L9 were not covered by tests

private

Check warning on line 11 in app/services/referentiel_service.rb

View check run for this annotation

Codecov / codecov/patch

app/services/referentiel_service.rb#L11

Added line #L11 was not covered by tests

attr_reader :type_de_champ
def initialize(type_de_champ:)
@type_de_champ = type_de_champ
end

Check warning on line 16 in app/services/referentiel_service.rb

View check run for this annotation

Codecov / codecov/patch

app/services/referentiel_service.rb#L13-L16

Added lines #L13 - L16 were not covered by tests

class ReferentielApiClient
attr_reader :type_de_champ
def initialize(type_de_champ:)
@type_de_champ = type_de_champ
end

Check warning on line 22 in app/services/referentiel_service.rb

View check run for this annotation

Codecov / codecov/patch

app/services/referentiel_service.rb#L18-L22

Added lines #L18 - L22 were not covered by tests

def valid?(value)
case call(value)
when Dry::Monads[:result]::Success
true
else
false
end
end

Check warning on line 31 in app/services/referentiel_service.rb

View check run for this annotation

Codecov / codecov/patch

app/services/referentiel_service.rb#L24-L31

Added lines #L24 - L31 were not covered by tests

def call(value) = API::Client.new.(url: build_url(value))

Check warning on line 33 in app/services/referentiel_service.rb

View check run for this annotation

Codecov / codecov/patch

app/services/referentiel_service.rb#L33

Added line #L33 was not covered by tests

def build_url(value)
original_url = @type_de_champ.referentiel_url

Check warning on line 36 in app/services/referentiel_service.rb

View check run for this annotation

Codecov / codecov/patch

app/services/referentiel_service.rb#L35-L36

Added lines #L35 - L36 were not covered by tests

original_url.gsub('{id}', value)
end
end
end

Check warning on line 41 in app/services/referentiel_service.rb

View check run for this annotation

Codecov / codecov/patch

app/services/referentiel_service.rb#L38-L41

Added lines #L38 - L41 were not covered by tests
55 changes: 55 additions & 0 deletions spec/fixtures/cassettes/referentiel/test.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions spec/services/referentiel_service_spec.rb
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

0 comments on commit c7b4448

Please sign in to comment.