Skip to content

Commit

Permalink
add EmtExtractorTest for invalid json files
Browse files Browse the repository at this point in the history
  • Loading branch information
whomingbird committed Sep 17, 2024
1 parent ce3149c commit 7218918
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"title": "study metadata demo",
"supported_type": "Study",
"enabled": true,
"attributes": [
{
"title": "resource_type_general",
"label": "Resource type general",
"description": "resource type general",
"type": "Controlled Vocabulary",
"required": true,
"pos": 1,
"ID": -1
},
{
"title": "resource_study_country",
"label": "Study country",
"description": "study country",
"type": "Controlled Vocabulary List",
"required": true,
"pos": 2,
"ID": -1
}
]
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"title": "person",
"supported_type": "ExtendedMetadata",
"enabled": true,
"attributes": [
{
"title": "first_name",
"type": "String1",
"required": true
},
{
"title": "last_name",
"label": "Last Name",
"type": "String",
"required": true
}
]
}
33 changes: 33 additions & 0 deletions test/unit/extended_metadatas/emt_extractor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,43 @@ class EmtExtractorTest < ActiveSupport::TestCase
errorfile = Rails.root.join(Seek::Config.append_filestore_path('emt_files'), 'result.error')
assert File.exist?(errorfile)
assert_equal '', File.read(errorfile)
end


test 'handles invalid json file with wrong attr type' do
invalid_emt_file = open_fixture_file('extended_metadata_type/invalid_emt_with_wrong_type.json')

assert_no_difference('ExtendedMetadataType.count') do
Seek::ExtendedMetadataType::EMTExtractor.extract_extended_metadata_type(invalid_emt_file)
end

errorfile = Rails.root.join(Seek::Config.append_filestore_path('emt_files'), 'result.error')
assert File.exist?(errorfile)


error_message = "The property '#/attributes/0/type' value \"String1\" did not match one of the following values: Date time, Date, Real number, Integer, Web link, Email address, Text, String, ChEBI, ECN, MetaNetX chemical, MetaNetX reaction, MetaNetX compartment, InChI, ENA custom date, Boolean, URI, DOI, NCBI ID, Registered Strain, Registered Data file"
assert_includes File.read(errorfile), error_message

end


test 'handles invalid json file with wrong id' do
invalid_emt_file = open_fixture_file('extended_metadata_type/invalid_emt_with_wrong_id.json')

assert_no_difference('ExtendedMetadataType.count') do
Seek::ExtendedMetadataType::EMTExtractor.extract_extended_metadata_type(invalid_emt_file)
end

errorfile = Rails.root.join(Seek::Config.append_filestore_path('emt_files'), 'result.error')
assert File.exist?(errorfile)


error_message = "Couldn't find SampleControlledVocab with 'id'=-1"
assert_includes File.read(errorfile), error_message

end


end


0 comments on commit 7218918

Please sign in to comment.