From ae1abcb5bc874b5ef0c2d426a074ab0b6ef5127c Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Thu, 2 Jan 2025 10:30:40 +0000 Subject: [PATCH] ensure OL full name uses family name last --- app/models/one_login/core_identity_validator.rb | 10 +++++++++- .../one_login/core_identity_validator_spec.rb | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/models/one_login/core_identity_validator.rb b/app/models/one_login/core_identity_validator.rb index 4fbec78fbf..5bbaa5aab5 100644 --- a/app/models/one_login/core_identity_validator.rb +++ b/app/models/one_login/core_identity_validator.rb @@ -22,7 +22,15 @@ def date_of_birth end def full_name - name_parts.map { |hash| hash["value"] }.join(" ") + given_names = name_parts + .select { |hash| hash["type"] == "GivenName" } + .map { |hash| hash["value"] } + + family_names = name_parts + .select { |hash| hash["type"] == "FamilyName" } + .map { |hash| hash["value"] } + + (given_names + family_names).join(" ") end private diff --git a/spec/models/one_login/core_identity_validator_spec.rb b/spec/models/one_login/core_identity_validator_spec.rb index c6ba813db4..44eaa9d086 100644 --- a/spec/models/one_login/core_identity_validator_spec.rb +++ b/spec/models/one_login/core_identity_validator_spec.rb @@ -91,6 +91,19 @@ it "returns whole name" do expect(subject.full_name).to eql("KENNETH DECERQUEIRA") end + + context "if name parts is out of order" do + it "ensures family name is used as last name" do + out_of_order = [ + {"value" => "DECERQUEIRA", "type" => "FamilyName"}, + {"value" => "KENNETH", "type" => "GivenName"} + ] + + allow(subject).to receive(:name_parts).and_return(out_of_order) + + expect(subject.full_name).to eql("KENNETH DECERQUEIRA") + end + end end let(:stub_normal_did) do