Skip to content

Commit

Permalink
Start hubee POC
Browse files Browse the repository at this point in the history
  • Loading branch information
jbfeldis committed May 24, 2024
1 parent b4348b5 commit df545f7
Show file tree
Hide file tree
Showing 58 changed files with 1,324 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml

/config/credentials/test.key
coverage
dump.rdb
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
10 changes: 8 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,34 @@ gem "config"
gem "omniauth_openid_connect"
gem "hash_mapper"
gem "omniauth-rails_csrf_protection"
gem "interactor", "~> 3.0"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[mri windows]
gem "rspec-rails", "~> 6.1.0"
gem "factory_bot_rails"
end

group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"

gem "standard", require: false
gem "standard", "~> 1.36", require: false
gem "rubocop-rails", require: false

# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"

# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
gem "spring"
gem "spring-commands-rspec"
end

group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem "webmock"
gem "simplecov", require: false
end
67 changes: 58 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,26 @@ GEM
config (5.4.0)
deep_merge (~> 1.2, >= 1.2.1)
connection_pool (2.4.1)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
date (3.3.4)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
deep_merge (1.2.2)
diff-lcs (1.5.1)
docile (1.4.0)
drb (2.2.1)
email_validator (2.2.4)
activemodel
erubi (1.12.0)
factory_bot (6.4.6)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
faraday (2.9.0)
faraday-net_http (>= 2.0, < 3.2)
faraday-follow_redirects (0.3.0)
Expand All @@ -120,13 +130,15 @@ GEM
activesupport (>= 6.1)
hash_mapper (0.2.7)
activesupport (>= 4)
hashdiff (1.1.0)
hashie (5.0.0)
i18n (1.14.4)
concurrent-ruby (~> 1.0)
importmap-rails (2.0.1)
actionpack (>= 6.0.0)
activesupport (>= 6.0.0)
railties (>= 6.0.0)
interactor (3.1.2)
io-console (0.7.2)
irb (1.12.0)
rdoc
Expand Down Expand Up @@ -261,7 +273,24 @@ GEM
reline (0.5.0)
io-console (~> 0.5)
rexml (3.2.6)
rubocop (1.62.1)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (6.1.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.13)
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.63.5)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -274,9 +303,9 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-performance (1.20.2)
rubocop-performance (1.21.0)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.24.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
Expand All @@ -289,25 +318,34 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
spring (4.2.1)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
standard (1.35.1)
standard (1.36.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.62.0)
rubocop (~> 1.63.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.3)
standard-performance (~> 1.4)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.3.1)
standard-performance (1.4.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.20.2)
rubocop-performance (~> 1.21.0)
stimulus-rails (1.3.3)
railties (>= 6.0.0)
stringio (3.1.0)
Expand Down Expand Up @@ -340,6 +378,10 @@ GEM
activesupport
faraday (~> 2.0)
faraday-follow_redirects
webmock (3.23.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
websocket (1.2.10)
websocket-driver (0.7.6)
Expand All @@ -357,23 +399,30 @@ DEPENDENCIES
capybara
config
debug
factory_bot_rails
hash_mapper
importmap-rails
interactor (~> 3.0)
jbuilder
omniauth-rails_csrf_protection
omniauth_openid_connect
pg (~> 1.1)
puma (>= 5.0)
rails (~> 7.1.3, >= 7.1.3.2)
rspec-rails (~> 6.1.0)
rubocop-rails
selenium-webdriver
simplecov
spring
spring-commands-rspec
sprockets-rails
standard
standard (~> 1.36)
stimulus-rails
tailwindcss-rails
turbo-rails
tzinfo-data
web-console
webmock

RUBY VERSION
ruby 3.3.0p0
Expand Down
24 changes: 24 additions & 0 deletions app/controllers/claims_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
class ClaimsController < ApplicationController
def index
end

def quotient_familial
result = GetFamilyQuotient.call(identity: Current.user)

if result.success?
session["qf"] = result.qf
Current.quotient_familial = result.qf
else
raise
end
end

def send_qf
recipient = Hubee::Recipient.new(siren: "21040107100019", branch_code: "04107")

result = StoreQuotientFamilial.call(identity: Current.user, quotient_familial: Current.quotient_familial, recipient: recipient)

if result.success?
Rails.logger.debug "Noïce"
@folder = result.folder
else
raise
end
end
end
3 changes: 3 additions & 0 deletions app/interactors/base_interactor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class BaseInteractor
include Interactor
end
3 changes: 3 additions & 0 deletions app/interactors/base_organizer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class BaseOrganizer
include Interactor::Organizer
end
21 changes: 21 additions & 0 deletions app/interactors/get_family_quotient.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class GetFamilyQuotient < BaseInteractor
def call
context.qf = {
regime: "CNAF",
enfants: [
{
nomNaissance: "ROUX",
nomUsage: "ROUX",
prenoms: "ALEXIS VINCENT",
anneeDateDeNaissance: "2006",
moisDateDeNaissance: "04",
jourDateDeNaissance: "20",
sexe: "M",
},
],
quotientFamilial: 2550,
annee: 2024,
mois: 2,
}
end
end
7 changes: 7 additions & 0 deletions app/interactors/hubee/clean_attachments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Hubee::CleanAttachments < BaseInteractor
def call
context.folder.attachments.each do |attachment|
attachment.close_file
end
end
end
13 changes: 13 additions & 0 deletions app/interactors/hubee/create.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Hubee::Create < 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
5 changes: 5 additions & 0 deletions app/interactors/hubee/create_folder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Hubee
class CreateFolder < BaseOrganizer
organize PrepareFolder, PrepareAttachments, Create, UploadAttachments, MarkFolderComplete, CleanAttachments
end
end
5 changes: 5 additions & 0 deletions app/interactors/hubee/mark_folder_complete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Hubee::MarkFolderComplete < BaseInteractor
def call
context.session.mark_folder_complete(folder_id: context.folder.id)
end
end
22 changes: 22 additions & 0 deletions app/interactors/hubee/prepare_attachments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Hubee::PrepareAttachments < BaseInteractor
def call
context.folder = context.folder.with(attachments:)
end

def rollback
context.folder.attachments.each do |attachment|
attachment.close_file
end
end

private

def attachments
context.folder.attachments.map do |attachment|
file = Tempfile.create
file.write(attachment.file_content)
file.rewind
attachment.with(file:, file_size: file.size)
end
end
end
56 changes: 56 additions & 0 deletions app/interactors/hubee/prepare_folder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class Hubee::PrepareFolder < BaseInteractor
def call
context.folder = ::Hubee::Folder.new(**folder_params)
end

private

def case_external_id
@case_external_id ||= "#{external_id}-01"
end

def external_id
# HubEE's portal view greps 13 chars after two dashes
@external_id ||= "Formulaire-QF-#{SecureRandom.hex[0...13].upcase}"
end

def folder_params
{
applicant: context.identity,
attachments: [
json_file,
text_file,
],
cases: [
external_id: case_external_id,
recipient: context.recipient,
],
external_id:,
process_code:,
}
end

def json_file
::Hubee::Attachment.new(
file_name: "FormulaireQF.json",
mime_type: "application/json",
recipients: [case_external_id],
type: process_code,
file_content: '{"identite": "pivot"}'
)
end

def process_code
"FormulaireQF"
end

def text_file
::Hubee::Attachment.new(
file_name: "FormulaireQF.pdf",
mime_type: "application/pdf",
recipients: [case_external_id],
type: process_code,
file_content: "Identité pivot"
)
end
end
7 changes: 7 additions & 0 deletions app/interactors/hubee/upload_attachments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Hubee::UploadAttachments < BaseInteractor
def call
context.folder.attachments.each do |attachment|
context.session.upload_attachment(folder_id: context.folder.id, attachment:)
end
end
end
3 changes: 3 additions & 0 deletions app/interactors/store_quotient_familial.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class StoreQuotientFamilial < BaseOrganizer
organize Hubee::CreateFolder
end
Loading

0 comments on commit df545f7

Please sign in to comment.