-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Review improvements on hubee storing
Showing
38 changed files
with
327 additions
and
258 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
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 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 |
---|---|---|
@@ -1,5 +1,13 @@ | ||
class Hubee | ||
class CreateFolder < BaseOrganizer | ||
organize PrepareFolder, PrepareAttachments, Create, UploadAttachments, MarkFolderComplete, CleanAttachments | ||
class HubEE::CreateFolder < BaseInteractor | ||
before do | ||
context.session ||= HubEE::Api.session | ||
end | ||
|
||
def call | ||
context.folder = context.session.create_folder(folder: context.folder) | ||
end | ||
|
||
def rollback | ||
context.session.delete_folder(folder_id: context.folder.id) | ||
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 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
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
app/interactors/get_family_quotient.rb → app/organizers/get_family_quotient.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
2 changes: 1 addition & 1 deletion
2
app/interactors/store_quotient_familial.rb → app/organizers/store_quotient_familial.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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
class StoreQuotientFamilial < BaseOrganizer | ||
organize Hubee::CreateFolder | ||
organize UploadQuotientFamilialToHubEE | ||
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,8 @@ | ||
class UploadQuotientFamilialToHubEE < BaseOrganizer | ||
organize PrepareQuotientFamilialHubEEFolder, | ||
HubEE::PrepareAttachments, | ||
HubEE::CreateFolder, | ||
HubEE::UploadAttachments, | ||
HubEE::MarkFolderComplete, | ||
HubEE::CleanAttachments | ||
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
require "net/http" | ||
require "json" | ||
|
||
class Hubee::Api | ||
class HubEE::Api | ||
def self.session | ||
new | ||
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
FactoryBot.define do | ||
factory :hubee_folder, class: Hubee::Folder do | ||
factory :hubee_folder, class: HubEE::Folder do | ||
initialize_with { new(**attributes) } | ||
|
||
applicant { {first_name: "David", last_name: "Heinemeier Hansson"} } | ||
attachments { [build(:hubee_attachment, :with_file)] } | ||
cases { [recipient: build(:hubee_recipient), external_id: "case_id"] } | ||
external_id { "external_id" } | ||
cases { [recipient: build(:hubee_recipient), external_id: "Formulaire-QF-ABCDEF1234567-01"] } | ||
external_id { "Formulaire-QF-ABCDEF1234567" } | ||
process_code { "FormulaireQF" } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,44 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Hubee::CreateFolder, type: :organizer do | ||
let(:interactors) do | ||
[ | ||
Hubee::PrepareFolder, | ||
Hubee::PrepareAttachments, | ||
Hubee::Create, | ||
Hubee::UploadAttachments, | ||
Hubee::MarkFolderComplete, | ||
Hubee::CleanAttachments, | ||
] | ||
RSpec.describe HubEE::CreateFolder, type: :interactor do | ||
subject(:interactor) { described_class.call(**params) } | ||
|
||
let(:params) do | ||
{ | ||
folder:, | ||
} | ||
end | ||
|
||
let(:session) { double(HubEE::Api) } | ||
|
||
before do | ||
allow(HubEE::Api).to receive(:session).and_return(session) | ||
end | ||
|
||
it "creates the folder, uploads the attachments and marks the folder complete" do | ||
expect(described_class).to organize interactors | ||
describe ".call" do | ||
let(:folder) { double(HubEE::Folder) } | ||
it "creates the folder" do | ||
expect(session).to receive(:create_folder).with(folder:) | ||
interactor | ||
end | ||
end | ||
|
||
describe "#rollback" do | ||
subject(:rollback) { interactor.rollback } | ||
|
||
let(:folder) { double(HubEE::Folder, id: folder_id) } | ||
let(:folder_id) { "folder_id" } | ||
let(:interactor) { described_class.new(**params) } | ||
let(:params) do | ||
{ | ||
folder:, | ||
session:, | ||
} | ||
end | ||
|
||
it "deletes the folder" do | ||
expect(session).to receive(:delete_folder).with(folder_id:) | ||
rollback | ||
end | ||
end | ||
end |
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
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,44 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe UploadQuotientFamilialToHubEE, type: :organizer do | ||
let(:interactors) do | ||
[ | ||
PrepareQuotientFamilialHubEEFolder, | ||
HubEE::PrepareAttachments, | ||
HubEE::CreateFolder, | ||
HubEE::UploadAttachments, | ||
HubEE::MarkFolderComplete, | ||
HubEE::CleanAttachments, | ||
] | ||
end | ||
|
||
it "creates the folder, uploads the attachments and marks the folder complete" do | ||
expect(described_class).to organize interactors | ||
end | ||
|
||
describe ".call" do | ||
subject { described_class.call(**params) } | ||
|
||
let(:folder) { build(:hubee_folder) } | ||
let(:identity) { PivotIdentity.new(recipient:, auth: {info: {first_name: "David", last_name: "Heinemeier Hansson"}}) } | ||
let(:recipient) { build(:hubee_recipient) } | ||
let(:params) do | ||
{ | ||
folder:, | ||
identity:, | ||
recipient:, | ||
} | ||
end | ||
|
||
before do | ||
allow(SecureRandom).to receive(:hex).and_return("abcdef1234567thiswontbeused") | ||
|
||
stub_hubee_token | ||
stub_hubee_create_folder | ||
stub_hubee_upload_attachment | ||
stub_hubee_mark_folder_complete | ||
end | ||
|
||
it { is_expected.to be_a_success } | ||
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 @@ | ||
module ProviderStubs; 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,104 @@ | ||
require_relative "../provider_stubs" | ||
|
||
module ProviderStubs::HubEE | ||
def stub_hubee_token(access_token: "access_token_123") | ||
stub_request(:post, "https://auth.bas.hubee.numerique.gouv.fr/oauth2/token") | ||
.with( | ||
body: '{"scope":"OSL","grant_type":"client_credentials"}', | ||
headers: { | ||
"Authorization" => "Basic bm90X2FfcmVhbF9pZDpub3RfYV9yZWFsX3NlY3JldA==", | ||
"Content-Type" => "application/json", | ||
"Host" => "auth.bas.hubee.numerique.gouv.fr", | ||
} | ||
) | ||
.to_return( | ||
status: 200, | ||
body: {"access_token" => access_token}.to_json, | ||
headers: {} | ||
) | ||
end | ||
|
||
def stub_hubee_create_folder(access_token: "access_token_123") | ||
stub_request(:post, "https://api.bas.hubee.numerique.gouv.fr/teledossiers/v1/folders") | ||
.with( | ||
body: '{"processCode":"FormulaireQF","externalId":"Formulaire-QF-ABCDEF1234567","applicant":{"firstName":"David","lastName":"Heinemeier Hansson"},"cases":[{"recipient":{"companyRegister":"123456789","branchCode":"1234","type":"SI"},"externalId":"Formulaire-QF-ABCDEF1234567-01"}],"attachments":[{"fileName":"FormulaireQF.json","type":"FormulaireQF","size":22,"mimeType":"application/json","recipients":["Formulaire-QF-ABCDEF1234567-01"]}]}', | ||
headers: { | ||
"Authorization" => "Bearer #{access_token}", | ||
"Content-Type" => "application/json", | ||
} | ||
) | ||
.to_return(status: 200, body: { | ||
id: "3fa85f64-5717-4562-b3fc-2c963f66afa6", | ||
globalStatus: "HUBEE_RECEIVED", | ||
processCode: "FormulaireQF", | ||
createDateTime: "2024-05-22T13:36:01.781Z", | ||
closeDateTime: "2024-05-22T13:36:01.781Z", | ||
applicant: { | ||
firstName: "David", | ||
lastName: "Heinemeier Hansson", | ||
}, | ||
externalId: "Formulaire-QF-ABCDEF1234567", | ||
updateDateTime: "2024-05-22T13:36:01.781Z", | ||
cases: [ | ||
{ | ||
id: "d7923df5-c071-400e-87b5-f0d01d539aa5", | ||
status: "HUBEE_NOTIFIED", | ||
recipient: { | ||
type: "SI", | ||
companyRegister: "123456789", | ||
branchCode: "1234", | ||
}, | ||
externalId: "Formulaire-QF-ABCDEF1234567-01", | ||
updateDateTime: "2024-05-22T13:36:01.781Z", | ||
transmissionDateTime: "2024-05-22T13:36:01.781Z", | ||
}, | ||
], | ||
attachments: [ | ||
{ | ||
id: "a66abb0c-52d1-4e50-9195-22526fb7ce92", | ||
status: "PENDING", | ||
fileName: "FormulaireQF.json", | ||
type: "FormulaireQF", | ||
size: 22, | ||
mimeType: "application/json", | ||
recipients: [ | ||
"Formulaire-QF-ABCDEF1234567-01", | ||
], | ||
}, | ||
], | ||
}.to_json, headers: {}) | ||
end | ||
|
||
def stub_hubee_upload_attachment(access_token: "access_token_123") | ||
stub_request(:put, "https://api.bas.hubee.numerique.gouv.fr/teledossiers/v1/folders/3fa85f64-5717-4562-b3fc-2c963f66afa6/attachments/a66abb0c-52d1-4e50-9195-22526fb7ce92") | ||
.with( | ||
body: '{"first_name":"David"}', | ||
headers: { | ||
"Authorization" => "Bearer #{access_token}", | ||
"Content-Length" => "22", | ||
"Content-Type" => "application/octet-stream", | ||
} | ||
) | ||
.to_return(status: 204, body: "", headers: {}) | ||
end | ||
|
||
def stub_hubee_mark_folder_complete(access_token: "access_token_123") | ||
stub_request(:patch, "https://api.bas.hubee.numerique.gouv.fr/teledossiers/v1/folders/3fa85f64-5717-4562-b3fc-2c963f66afa6") | ||
.with( | ||
body: '{"globalStatus":"HUBEE_COMPLETED"}' | ||
) | ||
.to_return(status: 204, body: "", headers: {}) | ||
end | ||
|
||
def stub_hubee_delete_folder(access_token: "access_token_123") | ||
stub_request(:delete, "https://api.bas.hubee.numerique.gouv.fr/teledossiers/v1/folders/3fa85f64-5717-4562-b3fc-2c963f66afa6") | ||
.with( | ||
headers: { | ||
"Authorization" => "Bearer access_token_123", | ||
"Content-Type" => "application/json", | ||
"Host" => "api.bas.hubee.numerique.gouv.fr", | ||
} | ||
) | ||
.to_return(status: 204, body: "", headers: {}) | ||
end | ||
end |