Skip to content

Commit

Permalink
send original pivot identity to hubee
Browse files Browse the repository at this point in the history
  • Loading branch information
JeSuisUnCaillou committed Sep 18, 2024
1 parent 0a6a312 commit fc61646
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 127 deletions.
1 change: 1 addition & 0 deletions app/controllers/shipments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def create
collectivity: @collectivity,
external_id: Current.external_id,
pivot_identity: Current.pivot_identity,
original_pivot_identity: Current.original_pivot_identity,
quotient_familial: Current.quotient_familial,
user: Current.user
)
Expand Down
7 changes: 6 additions & 1 deletion app/interactors/prepare_quotient_familial_hubee_folder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ def process_code
end

def shipment_data
ShipmentData.new(external_id: context.external_id, pivot_identity: context.pivot_identity, quotient_familial: context.quotient_familial)
ShipmentData.new(
external_id: context.external_id,
pivot_identity: context.pivot_identity,
original_pivot_identity: context.original_pivot_identity,
quotient_familial: context.quotient_familial
)
end

def xml_file
Expand Down
2 changes: 1 addition & 1 deletion app/interactors/setup_current_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def pivot_identity
end

def original_pivot_identity
session_raw_info.slice('birthcountry', 'birthdate', 'birthplace', 'family_name', 'given_name', 'gender')
session_raw_info.slice("birthcountry", "birthdate", "birthplace", "family_name", "given_name", "gender")
end

def quotient_familial
Expand Down
18 changes: 17 additions & 1 deletion app/jobs/populate_hubee_sandbox_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ def perform(*args)
Rails.logger.debug { "### Adding data to #{name} ###" }

collectivity = Collectivity.find_or_initialize_by(siret:, code_cog:, name:, status: :active)
result = UploadQuotientFamilialToHubEE.call(collectivity: collectivity, pivot_identity: pivot_identity, quotient_familial: quotient_familial)
result = UploadQuotientFamilialToHubEE.call(
collectivity:,
pivot_identity:,
original_pivot_identity:,
quotient_familial:
)

if result.success?
Rails.logger.debug { " >>> Data added to #{name}, id: #{result.folder.id} ###" }
Expand All @@ -28,6 +33,17 @@ def pivot_identity
PivotIdentity.new(first_names: ["David"], last_name: "Heinemeier Hansson", birth_country: "99135", birthplace: nil, birthdate: Date.new(1979, 10, 15), gender: :male)
end

def original_pivot_identity
{
family_name: "Heinemeier Hansson",
given_name: "David",
gender: "male",
birthdate: "1979-10-15",
birthplace: nil,
birthcountry: "99135",
}
end

def quotient_familial
FactoryBot.build(:quotient_familial_v2_payload)
end
Expand Down
12 changes: 6 additions & 6 deletions app/models/current.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Current < ActiveSupport::CurrentAttributes
attribute :pivot_identity,
:original_pivot_identity,
:quotient_familial,
:collectivity,
:user,
:external_id,
:redirect_uri
:original_pivot_identity,
:quotient_familial,
:collectivity,
:user,
:external_id,
:redirect_uri
end
6 changes: 4 additions & 2 deletions app/models/shipment_data.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class ShipmentData
attr_reader :external_id, :pivot_identity, :quotient_familial
attr_reader :external_id, :pivot_identity, :original_pivot_identity, :quotient_familial

def initialize(pivot_identity:, quotient_familial:, external_id: nil)
def initialize(pivot_identity:, original_pivot_identity:, quotient_familial:, external_id: nil)
@external_id = external_id
@pivot_identity = pivot_identity
@original_pivot_identity = original_pivot_identity
@quotient_familial = quotient_familial.with_indifferent_access
end

Expand All @@ -19,6 +20,7 @@ def to_h
prenoms: pivot_identity.first_names,
sexe: (pivot_identity.gender == :female) ? "F" : "M",
nomUsuel: pivot_identity.last_name,
**original_pivot_identity,
},
quotient_familial:,
}
Expand Down
7 changes: 5 additions & 2 deletions spec/factories/france_connect_payload.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
FactoryBot.define do
factory :france_connect_payload, class: Hash do
factory :original_pivot_identity, class: Hash do
initialize_with { attributes.deep_stringify_keys }

sub { "some_sub" }
family_name { "TESTMAN" }
given_name { "Johnny Paul René" }
gender { "male" }
birthdate { "1989-10-08" }
birthplace { "75107" }
birthcountry { "99100" }

factory :france_connect_payload, class: Hash do
sub { "some_sub" }
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
let(:recipient) { double(HubEE::Recipient) }
let(:kase) { build(:hubee_case, recipient:) }
let(:pivot_identity) { PivotIdentity.new(first_names: ["David"], last_name: "Heinemeier Hansson", birth_country: "99135", birthplace: nil, birthdate: Date.new(1979, 10, 15), gender: :male) }
let(:original_pivot_identity) { build(:original_pivot_identity) }
let(:quotient_familial) { FactoryBot.build(:quotient_familial_v2_payload) }
let(:collectivity) { create(:collectivity) }
let(:params) do
{
pivot_identity:,
original_pivot_identity:,
quotient_familial:,
collectivity:,
}
Expand Down
5 changes: 2 additions & 3 deletions spec/interactors/setup_current_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@

context "with a session from FranceConnect" do
let(:france_connect_payload) { build(:france_connect_payload) }
let(:session) { { "raw_info" => france_connect_payload } }

let(:session) { {"raw_info" => france_connect_payload} }

it "sets up the current original pivot identity" do
expect { call }.to change { Current.original_pivot_identity }.from(nil).to(france_connect_payload.except('sub'))
expect { call }.to change { Current.original_pivot_identity }.from(nil).to(france_connect_payload.except("sub"))
end
end
end
Expand Down
159 changes: 48 additions & 111 deletions spec/models/shipment_data_spec.rb
Original file line number Diff line number Diff line change
@@ -1,127 +1,64 @@
RSpec.describe ShipmentData, type: :model do
subject(:shipment_data) { described_class.new(external_id:, pivot_identity:, quotient_familial:) }
subject(:shipment_data) { described_class.new(external_id:, pivot_identity:, original_pivot_identity:, quotient_familial:) }

let(:external_id) { "external_id" }
let(:pivot_identity) { PivotIdentity.new(first_names: ["David"], last_name: "Heinemeier Hansson", birth_country: "99135", birthplace: nil, birthdate: Date.new(1979, 10, 15), gender: :male) }
let(:original_pivot_identity) { build(:original_pivot_identity) }
let(:quotient_familial) { FactoryBot.build(:quotient_familial_v2_payload) }
let(:expected_hash) do
{
external_id: "external_id",
pivot_identity: {
codePaysLieuDeNaissance: "99135",
anneeDateDeNaissance: 1979,
moisDateDeNaissance: 10,
jourDateDeNaissance: 15,
codeInseeLieuDeNaissance: nil,
prenoms: ["David"],
sexe: "M",
nomUsuel: "Heinemeier Hansson",
**original_pivot_identity,
},
quotient_familial: {
regime: "CNAF",
allocataires: [
{
nomNaissance: "DUBOIS",
nomUsuel: "DUBOIS",
prenoms: "ANGELA",
anneeDateDeNaissance: "1962",
moisDateDeNaissance: "08",
jourDateDeNaissance: "24",
sexe: "F",
},
],
enfants: [
{
nomNaissance: "Dujardin",
nomUsuel: "Dujardin",
prenoms: "Jean",
sexe: "M",
anneeDateDeNaissance: "2016",
moisDateDeNaissance: "12",
jourDateDeNaissance: "13",
},
],
quotientFamilial: 2550,
annee: 2024,
mois: 2,
version: "v2",
},
}
end

describe "to_h" do
it "returns the shipment data as a hash" do
expect(shipment_data.to_h.with_indifferent_access).to match(
external_id: "external_id",
pivot_identity: {
codePaysLieuDeNaissance: "99135",
anneeDateDeNaissance: 1979,
moisDateDeNaissance: 10,
jourDateDeNaissance: 15,
codeInseeLieuDeNaissance: nil,
prenoms: ["David"],
sexe: "M",
nomUsuel: "Heinemeier Hansson",
},
quotient_familial: {
regime: "CNAF",
allocataires: [
{
nomNaissance: "DUBOIS",
nomUsuel: "DUBOIS",
prenoms: "ANGELA",
anneeDateDeNaissance: "1962",
moisDateDeNaissance: "08",
jourDateDeNaissance: "24",
sexe: "F",
},
],
enfants: [
{
nomNaissance: "Dujardin",
nomUsuel: "Dujardin",
prenoms: "Jean",
sexe: "M",
anneeDateDeNaissance: "2016",
moisDateDeNaissance: "12",
jourDateDeNaissance: "13",
},
],
quotientFamilial: 2550,
annee: 2024,
mois: 2,
version: "v2",
}
expected_hash.with_indifferent_access
)
end
end

describe "#to_json" do
subject(:to_json) { shipment_data.to_json }

let(:expected_json) do
'{"external_id":"external_id","pivot_identity":{"codePaysLieuDeNaissance":"99135","anneeDateDeNaissance":1979,"moisDateDeNaissance":10,"jourDateDeNaissance":15,"codeInseeLieuDeNaissance":null,"prenoms":["David"],"sexe":"M","nomUsuel":"Heinemeier Hansson"},"quotient_familial":{"version":"v2","regime":"CNAF","quotientFamilial":2550,"annee":2024,"mois":2,"allocataires":[{"nomNaissance":"DUBOIS","nomUsuel":"DUBOIS","prenoms":"ANGELA","anneeDateDeNaissance":"1962","moisDateDeNaissance":"08","jourDateDeNaissance":"24","sexe":"F"}],"enfants":[{"nomNaissance":"Dujardin","nomUsuel":"Dujardin","prenoms":"Jean","sexe":"M","anneeDateDeNaissance":"2016","moisDateDeNaissance":"12","jourDateDeNaissance":"13"}]}}'
end

it "returns the shipment data as a json" do
expect(to_json).to eq(expected_json)
end
end

describe "#to_xml" do
subject(:to_xml) { shipment_data.to_xml }

let(:expected_xml) do
<<~XML
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<external-id>external_id</external-id>
<pivot-identity>
<codePaysLieuDeNaissance>99135</codePaysLieuDeNaissance>
<anneeDateDeNaissance type="integer">1979</anneeDateDeNaissance>
<moisDateDeNaissance type="integer">10</moisDateDeNaissance>
<jourDateDeNaissance type="integer">15</jourDateDeNaissance>
<codeInseeLieuDeNaissance nil="true"/>
<prenoms type="array">
<prenom>David</prenom>
</prenoms>
<sexe>M</sexe>
<nomUsuel>Heinemeier Hansson</nomUsuel>
</pivot-identity>
<quotient-familial>
<version>v2</version>
<regime>CNAF</regime>
<quotientFamilial type="integer">2550</quotientFamilial>
<annee type="integer">2024</annee>
<mois type="integer">2</mois>
<allocataires type="array">
<allocataire>
<nomNaissance>DUBOIS</nomNaissance>
<nomUsuel>DUBOIS</nomUsuel>
<prenoms>ANGELA</prenoms>
<anneeDateDeNaissance>1962</anneeDateDeNaissance>
<moisDateDeNaissance>08</moisDateDeNaissance>
<jourDateDeNaissance>24</jourDateDeNaissance>
<sexe>F</sexe>
</allocataire>
</allocataires>
<enfants type="array">
<enfant>
<nomNaissance>Dujardin</nomNaissance>
<nomUsuel>Dujardin</nomUsuel>
<prenoms>Jean</prenoms>
<sexe>M</sexe>
<anneeDateDeNaissance>2016</anneeDateDeNaissance>
<moisDateDeNaissance>12</moisDateDeNaissance>
<jourDateDeNaissance>13</jourDateDeNaissance>
</enfant>
</enfants>
</quotient-familial>
</hash>
XML
end

it "returns the shipment data as a xml" do
expect(to_xml).to eq(expected_xml)
end
end

describe "#to_s" do
subject(:human_readable_string) { shipment_data.to_s }

Expand Down
2 changes: 2 additions & 0 deletions spec/organizers/upload_quotient_familial_to_hubee_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
subject { described_class.call(**params) }

let(:pivot_identity) { PivotIdentity.new(first_names: ["David"], last_name: "Heinemeier Hansson", birth_country: "99135", birthplace: nil, birthdate: Date.new(1979, 10, 15), gender: :male) }
let(:original_pivot_identity) { build(:original_pivot_identity) }
let(:quotient_familial) { FactoryBot.build(:quotient_familial_v2_payload) }
let(:collectivity) { create(:collectivity) }
let(:params) do
{
quotient_familial:,
pivot_identity:,
original_pivot_identity:,
collectivity:,
}
end
Expand Down

0 comments on commit fc61646

Please sign in to comment.