|
42 | 42 | xit 'returns an empty array' do |
43 | 43 | expect(described_class.search(term: @term)).to eql([]) |
44 | 44 | end |
45 | | - xit 'logs the response as an error' do |
| 45 | + it 'logs the response as an error' do |
46 | 46 | described_class.expects(:handle_http_failure).at_least(1) |
47 | 47 | described_class.search(term: @term) |
48 | 48 | end |
|
70 | 70 | items: [ |
71 | 71 | { |
72 | 72 | id: 'https://ror.org/1234567890', |
73 | | - name: 'Example University', |
| 73 | + names: [ |
| 74 | + { types: ['ror_display'], value: 'Example University' }, |
| 75 | + { types: ['alias'], value: 'Example' }, |
| 76 | + { types: ['acronym'], value: 'EU' } |
| 77 | + ], |
74 | 78 | types: ['Education'], |
75 | | - links: ['http://example.edu/'], |
76 | | - aliases: ['Example'], |
77 | | - acronyms: ['EU'], |
| 79 | + links: [{ type: 'website', value: 'http://example.edu/' }], |
78 | 80 | status: 'active', |
79 | | - country: { country_name: 'United States', country_code: 'US' }, |
80 | | - external_ids: { |
81 | | - GRID: { preferred: 'grid.12345.1', all: 'grid.12345.1' } |
82 | | - } |
| 81 | + locations: [ |
| 82 | + { geonames_details: { country_name: 'United States', country_code: 'US' } } |
| 83 | + ], |
| 84 | + external_ids: [ |
| 85 | + { type: 'grid', preferred: 'grid.12345.1', all: ['grid.12345.1'] } |
| 86 | + ] |
83 | 87 | }, { |
84 | 88 | id: 'https://ror.org/0987654321', |
85 | | - name: 'Universidade de Example', |
| 89 | + names: [ |
| 90 | + { types: ['ror_display'], value: 'Universidade de Example' }, |
| 91 | + { types: ['alias'], value: 'Example' }, |
| 92 | + { types: ['acronym'], value: 'EU' } |
| 93 | + ], |
86 | 94 | types: ['Education'], |
87 | 95 | links: [], |
88 | | - aliases: ['Example'], |
89 | | - acronyms: ['EU'], |
90 | 96 | status: 'active', |
91 | | - country: { country_name: 'Mexico', country_code: 'MX' }, |
92 | | - external_ids: { |
93 | | - GRID: { preferred: 'grid.98765.8', all: 'grid.98765.8' } |
94 | | - } |
| 97 | + locations: [ |
| 98 | + { geonames_details: { country_name: 'Mexico', country_code: 'MX' } } |
| 99 | + ], |
| 100 | + external_ids: [ |
| 101 | + { type: 'grid', preferred: 'grid.98765.8', all: ['grid.98765.8'] } |
| 102 | + ] |
95 | 103 | } |
96 | 104 | ] |
97 | 105 | } |
|
132 | 140 | time_taken: 5, |
133 | 141 | items: [{ |
134 | 142 | id: Faker::Internet.url, |
135 | | - name: Faker::Lorem.word, |
136 | | - country: { country_name: Faker::Lorem.word } |
| 143 | + names: [{ types: ['ror_display'], value: Faker::Lorem.word }], |
| 144 | + locations: [{ geonames_details: { country_name: Faker::Lorem.word } }] |
137 | 145 | }] |
138 | 146 | } |
139 | 147 | @term = Faker::Lorem.word |
|
206 | 214 | items = Array.new(4).map do |
207 | 215 | { |
208 | 216 | id: Faker::Internet.unique.url, |
209 | | - name: Faker::Lorem.word, |
210 | | - country: { country_name: Faker::Lorem.word } |
| 217 | + names: [{ types: ['ror_display'], value: Faker::Lorem.word }], |
| 218 | + locations: [{ geonames_details: { country_name: Faker::Lorem.word } }] |
211 | 219 | } |
212 | 220 | end |
213 | 221 | results1 = { number_of_results: 4, items: items } |
|
225 | 233 | items = Array.new(7).map do |
226 | 234 | { |
227 | 235 | id: Faker::Internet.unique.url, |
228 | | - name: Faker::Lorem.word, |
229 | | - country: { country_name: Faker::Lorem.word } |
| 236 | + names: [{ types: ['ror_display'], value: Faker::Lorem.word }], |
| 237 | + locations: [{ geonames_details: { country_name: Faker::Lorem.word } }] |
230 | 238 | } |
231 | 239 | end |
232 | 240 | results1 = { number_of_results: 7, items: items[0..4] } |
|
247 | 255 | items = Array.new(12).map do |
248 | 256 | { |
249 | 257 | id: Faker::Internet.unique.url, |
250 | | - name: Faker::Lorem.word, |
251 | | - country: { country_name: Faker::Lorem.word } |
| 258 | + names: [{ types: ['ror_display'], value: Faker::Lorem.word }], |
| 259 | + locations: [{ geonames_details: { country_name: Faker::Lorem.word } }] |
252 | 260 | } |
253 | 261 | end |
254 | 262 | results1 = { number_of_results: 12, items: items[0..4] } |
|
273 | 281 | end |
274 | 282 | xit 'ignores items with no name or id' do |
275 | 283 | json = { items: [ |
276 | | - { id: Faker::Internet.url, name: Faker::Lorem.word }, |
| 284 | + { id: Faker::Internet.url, names: [{ types: ['ror_display'], value: Faker::Lorem.word }] }, |
277 | 285 | { id: Faker::Internet.url }, |
278 | | - { name: Faker::Lorem.word } |
| 286 | + { names: [{ types: ['ror_display'], value: Faker::Lorem.word }] } |
279 | 287 | ] }.to_json |
280 | 288 | items = described_class.send(:parse_results, json: JSON.parse(json)) |
281 | 289 | expect(items.length).to eql(1) |
282 | 290 | end |
283 | 291 | xit 'returns the correct number of results' do |
284 | 292 | json = { items: [ |
285 | | - { id: Faker::Internet.url, name: Faker::Lorem.word }, |
286 | | - { id: Faker::Internet.url, name: Faker::Lorem.word } |
| 293 | + { id: Faker::Internet.url, names: [{ types: ['ror_display'], value: Faker::Lorem.word }] }, |
| 294 | + { id: Faker::Internet.url, names: [{ types: ['ror_display'], value: Faker::Lorem.word }] } |
287 | 295 | ] }.to_json |
288 | 296 | items = described_class.send(:parse_results, json: JSON.parse(json)) |
289 | 297 | expect(items.length).to eql(2) |
|
292 | 300 |
|
293 | 301 | describe '#org_name' do |
294 | 302 | xit 'returns nil if there is no name' do |
295 | | - json = { country: { country_name: 'Nowhere' } }.to_json |
| 303 | + json = { locations: [{ geonames_details: { country_name: 'Nowhere' } }] }.to_json |
296 | 304 | expect(described_class.send(:org_name, item: JSON.parse(json))).to eql('') |
297 | 305 | end |
298 | 306 | xit 'properly appends the website if available' do |
299 | 307 | json = { |
300 | | - name: 'Example College', |
301 | | - links: ['https://example.edu'], |
302 | | - country: { country_name: 'Nowhere' } |
| 308 | + names: [{ types: ['ror_display'], value: 'Example College' }], |
| 309 | + links: [{ type: 'website', value: 'https://example.edu' }], |
| 310 | + locations: [{ geonames_details: { country_name: 'Nowhere' } }] |
303 | 311 | }.to_json |
304 | 312 | expected = 'Example College (example.edu)' |
305 | 313 | expect(described_class.send(:org_name, item: JSON.parse(json))).to eql(expected) |
306 | 314 | end |
307 | | - xit 'properly appends the country if available and no website is available' do |
| 315 | + it 'properly appends the country if available and no website is available' do |
308 | 316 | json = { |
309 | | - name: 'Example College', |
310 | | - country: { country_name: 'Nowhere' } |
| 317 | + names: [{ types: ['ror_display'], value: 'Example College' }], |
| 318 | + locations: [{ geonames_details: { country_name: 'Nowhere' } }] |
311 | 319 | }.to_json |
312 | 320 | expected = 'Example College (Nowhere)' |
313 | 321 | expect(described_class.send(:org_name, item: JSON.parse(json))).to eql(expected) |
314 | 322 | end |
315 | 323 | xit 'properly handles an item with no website or country' do |
316 | 324 | json = { |
317 | | - name: 'Example College', |
| 325 | + names: [{ types: ['ror_display'], value: 'Example College' }], |
318 | 326 | links: [], |
319 | | - country: {} |
| 327 | + locations: [] |
320 | 328 | }.to_json |
321 | 329 | expected = 'Example College' |
322 | 330 | expect(described_class.send(:org_name, item: JSON.parse(json))).to eql(expected) |
|
332 | 340 | expect(described_class.send(:org_website, item: nil)).to eql(nil) |
333 | 341 | end |
334 | 342 | xit 'returns the domain only' do |
335 | | - item = JSON.parse({ links: ['https://example.org/path?a=b'] }.to_json) |
| 343 | + item = JSON.parse({ links: [{ type: 'website', value: 'https://example.org/path?a=b' }] }.to_json) |
336 | 344 | expect(described_class.send(:org_website, item: item)).to eql('example.org') |
337 | 345 | end |
338 | 346 | xit 'removes the www prefix' do |
339 | | - item = JSON.parse({ links: ['www.example.org'] }.to_json) |
| 347 | + item = JSON.parse({ links: [{ type: 'website', value: 'www.example.org' }] }.to_json) |
340 | 348 | expect(described_class.send(:org_website, item: item)).to eql('example.org') |
341 | 349 | end |
342 | 350 | end |
343 | 351 |
|
344 | 352 | describe '#fundref_id' do |
345 | 353 | before(:each) do |
346 | | - @hash = { external_ids: {} } |
| 354 | + @hash = { external_ids: [] } |
347 | 355 | end |
348 | 356 | xit 'returns a blank if no external_ids are present' do |
349 | 357 | json = JSON.parse(@hash.to_json) |
350 | 358 | expect(described_class.send(:fundref_id, item: json)).to eql('') |
351 | 359 | end |
352 | 360 | xit 'returns a blank if no FundRef ids are present' do |
353 | | - @hash['external_ids'] = { FundRef: {} } |
| 361 | + @hash['external_ids'] = [{ type: 'grid', preferred: '1', all: %w[2 1] }] |
354 | 362 | json = JSON.parse(@hash.to_json) |
355 | 363 | expect(described_class.send(:fundref_id, item: json)).to eql('') |
356 | 364 | end |
357 | 365 | xit 'returns the preferred id when specified' do |
358 | | - @hash['external_ids'] = { FundRef: { preferred: '1', all: %w[2 1] } } |
| 366 | + @hash['external_ids'] = [{ type: 'fundref', preferred: '1', all: %w[2 1] }] |
359 | 367 | json = JSON.parse(@hash.to_json) |
360 | 368 | expect(described_class.send(:fundref_id, item: json)).to eql('1') |
361 | 369 | end |
362 | 370 | xit 'returns the firstid if no preferred is specified' do |
363 | | - @hash['external_ids'] = { FundRef: { preferred: nil, all: %w[2 1] } } |
| 371 | + @hash['external_ids'] = [{ type: 'fundref', preferred: nil, all: %w[2 1] }] |
364 | 372 | json = JSON.parse(@hash.to_json) |
365 | 373 | expect(described_class.send(:fundref_id, item: json)).to eql('2') |
366 | 374 | end |
|
0 commit comments