Skip to content

Commit

Permalink
SDK-1133: Add attribute_list method to BaseProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
emmas-yoti committed Jan 15, 2020
1 parent 4477c94 commit e047a36
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
11 changes: 11 additions & 0 deletions lib/yoti/data_type/base_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ def attributes
end.to_h
end

#
# Returns the full list of all attributes
#
# @return [Array<Yoti::Attribute>>]
#
def attribute_list
@attributes.map do |_, value|
[value]
end.flatten
end

#
# @param [Hash{String => Yoti::Attribute},Array<Yoti::Attribute>] profile_data
#
Expand Down
35 changes: 22 additions & 13 deletions spec/yoti/data_type/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,34 +187,43 @@
end
end

describe '.get_all_attributes_by_name' do
context 'with multiple attributes of the same name' do
let :multiname_profile do
Yoti::Profile.new([
Yoti::Attribute.new(Yoti::Attribute::FULL_NAME, 'Name 1', {}, {}),
Yoti::Attribute.new(Yoti::Attribute::FULL_NAME, 'Name 2', {}, {}),
Yoti::Attribute.new(Yoti::Attribute::FULL_NAME, 'Name 3', {}, {})
])
end
context 'with multiple attributes of the same name' do
let :multiname_profile do
Yoti::Profile.new([
Yoti::Attribute.new(Yoti::Attribute::FULL_NAME, 'Name 1', {}, {}),
Yoti::Attribute.new(Yoti::Attribute::FULL_NAME, 'Name 2', {}, {}),
Yoti::Attribute.new(Yoti::Attribute::FULL_NAME, 'Name 3', {}, {})
])
end

describe '.get_all_attributes_by_name' do
it 'returns all the names' do
expect(
multiname_profile.get_all_attributes_by_name(Yoti::Attribute::FULL_NAME)
.length
.length
).to eql 3
expect(
multiname_profile.get_all_attributes_by_name(Yoti::Attribute::FULL_NAME)[0]
.value
.value
).to eql 'Name 1'
expect(
multiname_profile.get_all_attributes_by_name(Yoti::Attribute::FULL_NAME)[1]
.value
.value
).to eql 'Name 2'
expect(
multiname_profile.get_all_attributes_by_name(Yoti::Attribute::FULL_NAME)[2]
.value
.value
).to eql 'Name 3'
end
end

describe '.attribute_list' do
it 'returns all the attributes' do
expect(multiname_profile.attribute_list.length).to eql 3
expect(multiname_profile.attribute_list[0].value).to eql 'Name 1'
expect(multiname_profile.attribute_list[1].value).to eql 'Name 2'
expect(multiname_profile.attribute_list[2].value).to eql 'Name 3'
end
end
end
end

0 comments on commit e047a36

Please sign in to comment.