File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ describe('Document validation', function() {
3939 ) ;
4040 cy . get ( '#validateCodemeta' ) . click ( ) ;
4141
42-
4342 cy . get ( '#name' ) . should ( 'have.value' , '' ) ;
4443 cy . get ( '#errorMessage' ) . should ( 'have.text' , '' ) ;
4544 } ) ;
@@ -105,6 +104,20 @@ describe('Document validation', function() {
105104
106105 cy . get ( '#errorMessage' ) . should ( 'have.text' , 'Unknown field "foobar".' ) ;
107106 } ) ;
107+
108+ it ( 'errors when both "type" and "@type" are present' , function ( ) {
109+ cy . get ( '#codemetaText' ) . then ( ( elem ) =>
110+ elem . text ( JSON . stringify ( {
111+ "@context" : "https://doi.org/10.5063/schema/codemeta-2.0" ,
112+ "type" : "SoftwareSourceCode" ,
113+ "@type" : "SoftwareSourceCode" ,
114+ "name" : "Conflicting types example" ,
115+ } ) )
116+ ) ;
117+ cy . get ( '#validateCodemeta' ) . click ( ) ;
118+
119+ cy . get ( '#errorMessage' ) . should ( 'have.text' , 'Document must use either "type" or "@type", not both.' ) ;
120+ } ) ;
108121} ) ;
109122
110123describe ( 'URLs validation' , function ( ) {
Original file line number Diff line number Diff line change @@ -20,7 +20,13 @@ function validateDocument(doc) {
2020 }
2121 // TODO: validate id/@id
2222
23- // TODO: check there is either type or @type but not both
23+ // Ensure either "type" or "@type" is used, but not both
24+ const typeKeys = [ 'type' , '@type' ] ;
25+ if ( typeKeys . filter ( k => Object . prototype . hasOwnProperty . call ( doc , k ) ) . length > 1 ) {
26+ setError ( `Document must use either "type" or "@type", not both.` ) ;
27+ return false ;
28+ }
29+
2430 var type = getDocumentType ( doc ) ;
2531 if ( type === undefined ) {
2632 setError ( "Missing type (must be SoftwareSourceCode or SoftwareApplication)." )
You can’t perform that action at this time.
0 commit comments