Skip to content

Commit

Permalink
ensure OL full name uses family name last
Browse files Browse the repository at this point in the history
  • Loading branch information
asmega committed Jan 2, 2025
1 parent 429c5b3 commit ae1abcb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/models/one_login/core_identity_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/models/one_login/core_identity_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae1abcb

Please sign in to comment.