Skip to content

Commit

Permalink
Fix : harmonise le retour du client hubee/fqf
Browse files Browse the repository at this point in the history
  • Loading branch information
jbfeldis committed Nov 29, 2024
1 parent 59020fe commit f409288
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/clients/hubee_api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def find_or_create_organization(organization, email_demandeur = nil)
end

def find_organization(organization)
http_connection.get("#{host}/referential/v1/organizations/SI-#{organization.siret}-#{organization.code_commune_etablissement}").body
http_connection.get("#{host}/referential/v1/organizations/SI-#{organization.siret}-#{organization.code_commune_etablissement}")
rescue Faraday::ResourceNotFound
raise NotFound
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def build_hubee_organization_id
end

def find_or_create_organization_on_hubee
hubee_api_client.find_or_create_organization(authorization_request.organization, authorization_request.demandeur.email)
hubee_api_client.find_or_create_organization(authorization_request.organization, authorization_request.demandeur.email).body
end

def hubee_api_client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def call
private

def create_subscription_on_hubee
hubee_api_client.create_subscription(authorization_request, hubee_organization_payload, process_code, editor_payload)
hubee_api_client.create_subscription(authorization_request, hubee_organization_payload, process_code, editor_payload).body
end

def editor_organization
Expand Down
2 changes: 1 addition & 1 deletion spec/clients/hubee_api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
end

describe '#find_organization' do
subject(:find_organization_payload) { described_class.new.find_organization(organization) }
subject(:find_organization_payload) { described_class.new.find_organization(organization).body }

let(:organization) { Organization.new(siret) }
let(:siret) { '13002526500013' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:authorization_request) { create(:authorization_request, :with_demandeur) }
let(:hubee_api_client) { instance_double(HubEEAPIClient) }
let(:params) { { authorization_request: } }
let(:stripped_organization_payload) { { 'companyRegister' => '123456789', 'branchCode' => '123456' } }
let(:stripped_organization_payload) { instance_double(Faraday::Response, body: { 'branchCode' => '123456', 'companyRegister' => '123456789' }) }

context 'when everything works as expected' do
before do
Expand All @@ -26,7 +26,7 @@
end

it 'adds the HubEE organization payload to the context' do
expect(interactor.hubee_organization_payload).to eq(stripped_organization_payload)
expect(interactor.hubee_organization_payload).to eq(stripped_organization_payload.body)
end

it { is_expected.to be_a_success }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

let(:authorization_request) { create(:authorization_request) }
let(:hubee_api_client) { instance_double(HubEEAPIClient) }
let(:stripped_hubee_organization_payload) { { 'branchCode' => '132456', 'companyRegister' => '123456789', 'id' => '123456789' } }
let(:stripped_hubee_subscription_payload) { { 'id' => 'ABC123456789' } }
let(:stripped_hubee_organization_payload) { instance_double(Faraday::Response, body: { 'branchCode' => '123456', 'companyRegister' => '123456789', 'id' => '123456789' }) }
let(:stripped_hubee_subscription_payload) { instance_double(Faraday::Response, body: { 'id' => 'ABC123456789' }) }
let(:params) { { authorization_request:, hubee_organization_payload: stripped_hubee_organization_payload } }

context 'when everything works as expected' do
Expand Down Expand Up @@ -63,7 +63,7 @@
end

it 'adds the HubEE subscription payload to the context' do
expect(interactor.hubee_subscription_payload).to eq(stripped_hubee_subscription_payload)
expect(interactor.hubee_subscription_payload).to eq(stripped_hubee_subscription_payload.body)
end

it { is_expected.to be_a_success }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
let(:insee_api_authentication) { instance_double(INSEEAPIAuthentication, access_token: 'access_token') }
let(:insee_payload) { insee_sirene_api_etablissement_valid_payload(siret: editor_siret, full: true) }
let(:authorization_request) { create(:authorization_request, :with_demandeur, api: 'particulier') }
let(:subscription_payload) { hubee_subscription_payload(authorization_request:) }
let(:subscription_payload) { instance_double(Faraday::Response, body: hubee_subscription_payload(authorization_request:)) }
let(:editor_siret) { '13002526500013' }
let(:service_provider) { { 'type' => 'editor', 'siret' => editor_siret } }
let(:formulaire_qf_api_client) { instance_double(FormulaireQFAPIClient) }
let(:siret) { '12345678901234' }
let(:code_commune) { '12345' }

let(:organization_payload) { hubee_organization_payload(siret:, code_commune:) }
let(:organization_payload) { instance_double(Faraday::Response, body: hubee_organization_payload(siret:, code_commune:)) }

before do
allow(HubEEAPIClient).to receive(:new).and_return(hubee_api_client)
Expand Down Expand Up @@ -44,7 +44,7 @@
it 'stores the subscription id on the authorization request' do
interactor

expect(authorization_request.reload.extra_infos['hubee_subscription_id']).to eq(subscription_payload['id'])
expect(authorization_request.reload.extra_infos['hubee_subscription_id']).to eq(subscription_payload.body['id'])
end

describe 'subscription creation' do
Expand Down

0 comments on commit f409288

Please sign in to comment.