Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion cypress/integration/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ describe('Document validation', function() {
);
cy.get('#validateCodemeta').click();


cy.get('#name').should('have.value', '');
cy.get('#errorMessage').should('have.text', '');
});
Expand Down Expand Up @@ -105,6 +104,20 @@ describe('Document validation', function() {

cy.get('#errorMessage').should('have.text', 'Unknown field "foobar".');
});

it('errors when both "type" and "@type" are present', function() {
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"type": "SoftwareSourceCode",
"@type": "SoftwareSourceCode",
"name": "Conflicting types example",
}))
);
cy.get('#validateCodemeta').click();

cy.get('#errorMessage').should('have.text', 'Document must use either "type" or "@type", not both.');
});
});

describe('URLs validation', function() {
Expand Down
8 changes: 7 additions & 1 deletion js/validation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ function validateDocument(doc) {
}
// TODO: validate id/@id

// TODO: check there is either type or @type but not both
// Ensure either "type" or "@type" is used, but not both
const typeKeys = ['type', '@type'];
if (typeKeys.filter(k => Object.prototype.hasOwnProperty.call(doc, k)).length > 1) {
setError(`Document must use either "type" or "@type", not both.`);
return false;
}

var type = getDocumentType(doc);
if (type === undefined) {
setError("Missing type (must be SoftwareSourceCode or SoftwareApplication).")
Expand Down