Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ahamelers committed Jun 29, 2023
1 parent 44fbd9e commit bfde155
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function PrelimArticle({
{
htmlId: 'publication',
labelText: 'Journal name',
isRequired: false,
isRequired: true,
}
}
/>
Expand Down
41 changes: 24 additions & 17 deletions app/models/stash_datacite/resource/dataset_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ def loose_errors
err.flatten
end

def article_id
err = []

if @resource.identifier.import_info != 'other' && @resource.identifier.publication_name.blank?
err << ErrorItem.new(message: 'Fill in the {journal of the related publication}',
page: metadata_page(@resource),
ids: ['publication'])
end

journal = " from #{@resource.identifier.publication_name}" if @resource.identifier.publication_name.present?

if @resource.identifier.import_info == 'published' &&
(@resource.identifier.publication_article_doi.blank? || @resource.related_identifiers.where(work_type: 'primary_article').count.positive?)
err << ErrorItem.new(message: "Fill in {a correctly formatted DOI} for the article#{journal}",
page: metadata_page(@resource),
ids: %w[primary_article_doi])
elsif @resource.identifier.import_info == 'manuscript' && @resource.identifier.manuscript_number.blank?
err << ErrorItem.new(message: "Fill in the {manuscript number} for the article#{journal}",
page: metadata_page(@resource),
ids: ['msId'])
end
err
end

def title
if @resource.title.blank?
return ErrorItem.new(message: 'Fill in a {dataset title}',
Expand Down Expand Up @@ -167,23 +191,6 @@ def abstract
[]
end

def article_id
return [] unless @resource.identifier.publication_name.present? &&
@resource.identifier.manuscript_number.blank? &&
@resource.identifier.publication_article_doi.blank?

if @resource.related_identifiers.where(work_type: 'primary_article').count.positive? # has primary, but not doi
ErrorItem.new(message: "Fill in {a correctly formatted DOI} for your article from #{@resource.identifier
.publication_name}",
page: metadata_page(@resource),
ids: %w[primary_article_doi])
else
ErrorItem.new(message: "Fill in a {manuscript number or DOI} for the article from #{@resource.identifier.publication_name}",
page: metadata_page(@resource),
ids: %w[msid primary_article_doi])
end
end

def s3_error_uploads
return [] if @resource.submitted?

Expand Down
35 changes: 30 additions & 5 deletions spec/models/stash_datacite/dataset_validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,51 @@ module Resource
end

describe :article_id do
it 'gives error for unfilled manuscript number or publication doi if publication' do
it 'gives error for unfilled publication' do
@resource.identifier.update(import_info: 'published')

validations = DatasetValidations.new(resource: @resource)
error = validations.article_id.first

expect(error.message).to include('journal of the related publication')
expect(error.ids).to eq(%w[publication])
end

it 'gives error for unfilled publication doi if publication' do
@resource.identifier.update(import_info: 'published')
StashEngine::InternalDatum.create(data_type: 'publicationName',
value: 'Barrel of Monkeys: the Primate Journal',
identifier_id: @resource.identifier_id)

validations = DatasetValidations.new(resource: @resource)
error = validations.article_id.first

expect(error.message).to include('formatted DOI')
expect(error.ids).to eq(%w[primary_article_doi])
end

it 'gives error for unfilled manuscript number if manuscript' do
@resource.identifier.update(import_info: 'manuscript')
StashEngine::InternalDatum.create(data_type: 'publicationName',
value: 'Barrel of Monkeys: the Primate Journal',
identifier_id: @resource.identifier_id)

validations = DatasetValidations.new(resource: @resource)
error = validations.article_id
error = validations.article_id.first

expect(error.message).to include('manuscript number or DOI')
expect(error.ids).to eq(%w[msid primary_article_doi])
expect(error.message).to include('manuscript number')
expect(error.ids).to eq(%w[msId])
end

it 'gives a formatting error when someone puts in a URL instead of a DOI' do
@resource.identifier.update(import_info: 'published')
StashEngine::InternalDatum.create(data_type: 'publicationName',
value: 'Barrel of Monkeys: the Primate Journal',
identifier_id: @resource.identifier_id)
create(:related_identifier, resource_id: @resource.id, related_identifier_type: 'url', work_type:
'primary_article')
validations = DatasetValidations.new(resource: @resource)
error = validations.article_id
error = validations.article_id.first

expect(error.message).to include('formatted DOI')
expect(error.ids).to eq(%w[primary_article_doi])
Expand Down
1 change: 1 addition & 0 deletions spec/support/helpers/dataset_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def fill_required_metadata
# make sure we're on the right page
navigate_to_metadata

choose('choose_other')
fill_in 'title', with: Faker::Lorem.sentence
fill_in_author
fill_in_research_domain
Expand Down

0 comments on commit bfde155

Please sign in to comment.