Skip to content

Commit

Permalink
add tests to verify the programmatic validation of supported_type
Browse files Browse the repository at this point in the history
  • Loading branch information
whomingbird committed Oct 16, 2024
1 parent d29e83c commit 8d29371
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"title": "publication",
"supported_type": "Publication",
"enabled": true,
"attributes": [
{
"title": "title",
"type": "String",
"required": true
},
{
"title": "DOI",
"type": "DOI"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "publication",
"supported_type": "Publication",
"supported_type": "Journal",
"enabled": true,
"attributes": [
{
Expand Down
17 changes: 15 additions & 2 deletions test/functional/extended_metadata_types_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,27 @@ class ExtendedMetadataTypesControllerTest < ActionController::TestCase
person = FactoryBot.create(:admin)
login_as(person)

file = fixture_file_upload('extended_metadata_type/invalid_supported_type_emt.json', 'application/json')
file = fixture_file_upload('extended_metadata_type/invalid_not_supported_type_emt.json', 'application/json')

assert_no_difference('ExtendedMetadataType.count') do
post :create, params: { emt_json_file: file }
end

assert_match(/\"Publication\" did not match one of the following values/, flash[:error])
assert_equal "Supported type 'Publication' does not support extended metadata!", flash[:error]

end

test 'should not create when the supported type is invalid' do
person = FactoryBot.create(:admin)
login_as(person)

file = fixture_file_upload('extended_metadata_type/invalid_supported_type_emt.json', 'application/json')

assert_no_difference('ExtendedMetadataType.count') do
post :create, params: { emt_json_file: file }
end

assert_equal "Supported type 'Journal' is not a valid support type!", flash[:error]
end


Expand Down
2 changes: 1 addition & 1 deletion test/unit/extended_metadatas/emt_extractor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class EmtExtractorTest < ActiveSupport::TestCase
Seek::ExtendedMetadataType::EMTExtractor.extract_extended_metadata_type(invalid_emt_file)
end

assert_match /Invalid JSON file: The property '#\/attributes\/0' of type object did not match any of the required schemas/, error.message
assert_equal "The attribute type 'String1' does not exist.", error.message
end
end

Expand Down

0 comments on commit 8d29371

Please sign in to comment.