···7171 def parse_services(service_data)
7272 raise FormatError, "Invalid service data" unless service_data.is_a?(Array) && service_data.all? { |x| x.is_a?(Hash) }
73737474- service_data.map do |x|
7474+ services = []
7575+7676+ service_data.each do |x|
7577 id, type, endpoint = x.values_at('id', 'type', 'serviceEndpoint')
76787779 if id.is_a?(String) && id.start_with?('#') && type.is_a?(String) && endpoint.is_a?(String)
7878- ServiceRecord.new(id.gsub(/^#/, ''), type, endpoint)
7979- else
8080- raise FormatError, "Invalid service data"
8080+ services << ServiceRecord.new(id.gsub(/^#/, ''), type, endpoint)
8181 end
8282 end
8383+8484+ services
8385 end
8486 end
8587end
+8-5
spec/document_spec.rb
···120120 end
121121 end
122122123123- context 'when some service entries are not valid' do
123123+ context 'when service entries are partially valid' do
124124 let(:services) {
125125 [
126126 { 'id' => '#atproto_pds', 'type' => 'AtprotoPersonalDataServer', 'serviceEndpoint' => 'https://pds.dholms.xyz' },
···133133134134 let(:json) { base_json.merge('service' => services) }
135135136136- it 'should raise a format error' do
137137- expect {
138138- subject.new(did, json)
139139- }.to raise_error(DIDKit::FormatError)
136136+ it 'should only keep the valid records' do
137137+ doc = subject.new(did, json)
138138+139139+ doc.services.length.should == 2
140140+ doc.services.map(&:key).should == ['atproto_pds', 'lycan']
141141+ doc.services.map(&:type).should == ['AtprotoPersonalDataServer', 'LycanService']
142142+ doc.services.map(&:endpoint).should == ['https://pds.dholms.xyz', 'https://lycan.feeds.blue']
140143 end
141144 end
142145 end