-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Find or create plus clair côté hubee, séquençage hubee > fqf dans un …
…organizer
- Loading branch information
Showing
20 changed files
with
403 additions
and
277 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
14 changes: 14 additions & 0 deletions
14
app/interactors/datapass_webhook/api_particulier/create_formulaire_qf_collectivity.rb
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,14 @@ | ||
class DatapassWebhook::APIParticulier::CreateFormulaireQFCollectivity < ApplicationInteractor | ||
delegate :authorization_request, to: :context | ||
delegate :organization, to: :authorization_request, private: true | ||
|
||
def call | ||
FormulaireQFAPIClient.new.create_collectivity(organization:, editor_name:) | ||
end | ||
|
||
private | ||
|
||
def editor_name | ||
authorization_request.extra_infos.dig('service_provider', 'id') | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
app/interactors/datapass_webhook/api_particulier/create_hubee_organization.rb
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,27 @@ | ||
class DatapassWebhook::APIParticulier::CreateHubEEOrganization < ApplicationInteractor | ||
delegate :authorization_request, :hubee_organization_payload, to: :context | ||
|
||
def call | ||
context.hubee_organization_payload = find_or_create_organization_on_hubee | ||
save_hubee_organization_id_to_authorization_request | ||
end | ||
|
||
private | ||
|
||
def build_hubee_organization_id | ||
"SI-#{hubee_organization_payload['companyRegister']}-#{hubee_organization_payload['branchCode']}" | ||
end | ||
|
||
def find_or_create_organization_on_hubee | ||
hubee_api_client.find_or_create_organization(authorization_request.organization, authorization_request.demandeur.email) | ||
end | ||
|
||
def hubee_api_client | ||
@hubee_api_client ||= HubEEAPIClient.new | ||
end | ||
|
||
def save_hubee_organization_id_to_authorization_request | ||
authorization_request.extra_infos['hubee_organization_id'] = build_hubee_organization_id | ||
authorization_request.save! | ||
end | ||
end |
52 changes: 52 additions & 0 deletions
52
app/interactors/datapass_webhook/api_particulier/create_hubee_subscription.rb
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,52 @@ | ||
class DatapassWebhook::APIParticulier::CreateHubEESubscription < ApplicationInteractor | ||
delegate :authorization_request, :hubee_organization_payload, :hubee_subscription_payload, to: :context | ||
|
||
def call | ||
context.hubee_subscription_payload = create_subscription_on_hubee | ||
save_hubee_subscription_id_to_authorization_request | ||
end | ||
|
||
private | ||
|
||
def create_subscription_on_hubee | ||
hubee_api_client.create_subscription(authorization_request, hubee_organization_payload, process_code, editor_payload) | ||
end | ||
|
||
def editor_organization | ||
@editor_organization ||= Organization.new(service_provider['siret']) | ||
end | ||
|
||
def editor_payload | ||
return {} unless editor_subscription? | ||
|
||
{ | ||
delegationActor: { | ||
branchCode: editor_organization.code_commune_etablissement, | ||
companyRegister: editor_organization.siret, | ||
type: 'EDT' | ||
}, | ||
accessMode: 'API' | ||
} | ||
end | ||
|
||
def editor_subscription? | ||
service_provider['type'] == 'editor' | ||
end | ||
|
||
def hubee_api_client | ||
@hubee_api_client ||= HubEEAPIClient.new | ||
end | ||
|
||
def process_code | ||
'FormulaireQF' | ||
end | ||
|
||
def save_hubee_subscription_id_to_authorization_request | ||
authorization_request.extra_infos['hubee_subscription_id'] = hubee_subscription_payload['id'] | ||
authorization_request.save! | ||
end | ||
|
||
def service_provider | ||
@service_provider ||= Hash(authorization_request.extra_infos['service_provider']) | ||
end | ||
end |
9 changes: 0 additions & 9 deletions
9
app/interactors/datapass_webhook/schedule_create_formulaire_qf_hubee_subscription_job.rb
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
app/interactors/datapass_webhook/schedule_create_formulaire_qf_resources_job.rb
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,8 @@ | ||
class DatapassWebhook::ScheduleCreateFormulaireQFResourcesJob < ApplicationInteractor | ||
def call | ||
return unless context.event == 'approve' | ||
return unless context.modalities.include?('formulaire_qf') | ||
|
||
CreateFormulaireQFResourcesJob.perform_later(context.authorization_request.id) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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,7 @@ | ||
class CreateFormulaireQFResourcesJob < ApplicationJob | ||
def perform(authorization_request_id) | ||
authorization_request = AuthorizationRequest.find(authorization_request_id) | ||
|
||
DatapassWebhook::CreateFormulaireQFResources.call(authorization_request:) | ||
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
5 changes: 5 additions & 0 deletions
5
app/organizers/datapass_webhook/create_formulaire_qf_resources.rb
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 @@ | ||
class DatapassWebhook::CreateFormulaireQFResources < ApplicationOrganizer | ||
organize DatapassWebhook::APIParticulier::CreateHubEEOrganization, | ||
DatapassWebhook::APIParticulier::CreateHubEESubscription, | ||
DatapassWebhook::APIParticulier::CreateFormulaireQFCollectivity | ||
end |
25 changes: 25 additions & 0 deletions
25
spec/interactors/datapass_webhook/api_particulier/create_formulaire_qf_collectivity_spec.rb
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 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe DatapassWebhook::APIParticulier::CreateFormulaireQFCollectivity, type: :interactor do | ||
subject(:interactor) { described_class.call(**params) } | ||
|
||
let(:authorization_request) { create(:authorization_request) } | ||
let(:formulaire_qf_api_client) { instance_double(FormulaireQFAPIClient) } | ||
let(:params) { { authorization_request: } } | ||
let(:organization) { authorization_request.organization } | ||
let(:editor_name) { 'SUPEREDITOR' } | ||
|
||
before do | ||
allow(FormulaireQFAPIClient).to receive(:new).and_return(formulaire_qf_api_client) | ||
allow(formulaire_qf_api_client).to receive(:create_collectivity) | ||
|
||
authorization_request.extra_infos['service_provider'] = { 'id' => editor_name } | ||
end | ||
|
||
it 'creates a collectivity on FormulaireQF' do | ||
expect(formulaire_qf_api_client).to receive(:create_collectivity).with(organization:, editor_name:) | ||
interactor | ||
end | ||
|
||
it { is_expected.to be_a_success } | ||
end |
Oops, something went wrong.