Skip to content

Commit 4f29add

Browse files
Copilotfbacall
andcommitted
Fix tests to work with new Author model
Co-authored-by: fbacall <503373+fbacall@users.noreply.github.com>
1 parent ce9c351 commit 4f29add

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

test/controllers/materials_controller_test.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class MaterialsControllerTest < ActionController::TestCase
253253
date_published: test_material.date_published,
254254
doi: test_material.doi,
255255
subsets: test_material.subsets,
256-
authors: test_material.authors,
256+
authors_attributes: test_material.authors.map { |a| { first_name: a.first_name, last_name: a.last_name, orcid: a.orcid } },
257257
contributors: test_material.contributors,
258258
prerequisites: test_material.prerequisites,
259259
syllabus: test_material.syllabus,
@@ -291,7 +291,15 @@ class MaterialsControllerTest < ActionController::TestCase
291291
assert_equal test_material.other_types, JSON.parse(response.body)['other_types'], 'other_types not matched'
292292
#assert_equal test_material.events, JSON.parse(response.body)['events'], 'events not matched'
293293
assert_equal test_material.target_audience, JSON.parse(response.body)['target_audience'], 'target audience not matched'
294-
assert_equal test_material.authors, JSON.parse(response.body)['authors'], 'authors not matched'
294+
# Authors is now an array of objects with id, first_name, last_name, orcid, full_name
295+
response_authors = JSON.parse(response.body)['authors']
296+
assert_equal test_material.authors.size, response_authors.size, 'authors count not matched'
297+
response_authors.each_with_index do |author_json, i|
298+
expected_author = test_material.authors[i]
299+
assert_equal expected_author.first_name, author_json['first_name'], "author #{i} first_name not matched"
300+
assert_equal expected_author.last_name, author_json['last_name'], "author #{i} last_name not matched"
301+
assert_equal expected_author.full_name, author_json['full_name'], "author #{i} full_name not matched"
302+
end
295303
assert_equal test_material.contributors, JSON.parse(response.body)['contributors'], 'contributors not matched'
296304
assert_equal test_material.subsets, JSON.parse(response.body)['subsets'], 'subsets not matched'
297305
assert_equal test_material.prerequisites, JSON.parse(response.body)['prerequisites'], 'prerequisites not matched'

test/unit/ingestors/zenodo_ingestor_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ZenodoIngestorTest < ActiveSupport::TestCase
4848
assert_equal 'CC-BY-4.0', material.licence, 'material licence not matched'
4949
assert_equal 'active', material.status, 'material status not matched'
5050
assert_equal 1, material.authors.size, 'material authors count not matched.'
51-
assert material.authors.include?('Australian Research Data Commons')
51+
assert material.authors.any? { |a| a.full_name == 'Australian Research Data Commons' }, 'author not found'
5252
assert_equal '10.5281/zenodo.10656276', material.doi, 'material.doi not matched.'
5353

5454
# check material with contributors
@@ -62,7 +62,7 @@ class ZenodoIngestorTest < ActiveSupport::TestCase
6262

6363
# check material from page 2
6464
material = get_zenodo_id(10052012, 'Privacy focused health data storage and access control through personal online datastores', 'Portal Provider')
65-
assert material.authors.include?('Vidanage, Anushka (orcid: 0000-0002-5386-5871)'), 'material contributors[0] missing.'
65+
assert material.authors.any? { |a| a.full_name == 'Vidanage, Anushka' && a.orcid == '0000-0002-5386-5871' }, 'author with ORCID not found'
6666
end
6767

6868
private

0 commit comments

Comments
 (0)