Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send original pivot identity #124

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 5 additions & 0 deletions app/interactors/setup_current_data.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class SetupCurrentData < BaseInteractor
def call
Current.pivot_identity = pivot_identity
Current.original_pivot_identity = original_pivot_identity
Current.quotient_familial = quotient_familial
Current.collectivity = collectivity
Current.user = user
Expand All @@ -22,6 +23,10 @@ def pivot_identity
PivotIdentity.new(**FranceConnect::IdentityMapper.normalize(session_raw_info))
end

def original_pivot_identity
session_raw_info.slice("birthcountry", "birthdate", "birthplace", "family_name", "given_name", "gender")
jbfeldis marked this conversation as resolved.
Show resolved Hide resolved
end

def quotient_familial
context.session.fetch("quotient_familial", {})
end
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
8 changes: 7 additions & 1 deletion app/models/current.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
class Current < ActiveSupport::CurrentAttributes
attribute :pivot_identity, :quotient_familial, :collectivity, :user, :external_id, :redirect_uri
attribute :pivot_identity,
: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
18 changes: 14 additions & 4 deletions spec/interactors/setup_current_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
before do
Current.user = nil
Current.pivot_identity = nil
Current.original_pivot_identity = nil
Current.quotient_familial = nil
Current.collectivity = nil
Current.external_id = nil
Expand All @@ -23,10 +24,6 @@
expect { call }.to change { Current.user }.from(nil).to(instance_of(User))
end

it "sets up the current pivot identity" do
expect { call }.to change { Current.pivot_identity }.from(nil).to(instance_of(PivotIdentity))
end

it "sets up the current quotient familial" do
expect { call }.to change { Current.quotient_familial }.from(nil).to({"quotient_familial" => 2550})
end
Expand All @@ -42,5 +39,18 @@
it "sets up the current redirect uri" do
expect { call }.to change { Current.redirect_uri }.from(nil).to("https://real_uri")
end

it "sets up the current pivot identity" do
expect { call }.to change { Current.pivot_identity }.from(nil).to(instance_of(PivotIdentity))
end

context "with a session from FranceConnect" do
let(:france_connect_payload) { build(: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"))
end
end
end
end
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,
JeSuisUnCaillou marked this conversation as resolved.
Show resolved Hide resolved
},
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/store_quotient_familial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
subject(:organizer) { 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(:params) do
{
quotient_familial:,
pivot_identity:,
original_pivot_identity:,
collectivity:,
user:,
}
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