Skip to content

Commit

Permalink
Remove context validation on import (#36)
Browse files Browse the repository at this point in the history
We don't need it since 858cc4e
  • Loading branch information
progval authored Mar 29, 2024
1 parent 858cc4e commit 047b35e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 57 deletions.
42 changes: 0 additions & 42 deletions cypress/integration/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,46 +216,4 @@ describe('JSON Import', function() {
cy.get('#name').should('have.value', 'My Test Software');
});

it('errors on invalid context URL', function() {
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": "https://doi.org/10.5063/schema/codemeta-100000",
"@type": "SoftwareSourceCode",
"name": "My Test Software",
}))
);
cy.get('#importCodemeta').click();

cy.get('#errorMessage').should('have.text', '@context must be "https://doi.org/10.5063/schema/codemeta-2.0", not "https://doi.org/10.5063/schema/codemeta-100000"');
});

it('errors on invalid context URL in array', function() {
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": ["https://doi.org/10.5063/schema/codemeta-100000"],
"@type": "SoftwareSourceCode",
"name": "My Test Software",
}))
);
cy.get('#importCodemeta').click();

cy.get('#errorMessage').should('have.text', '@context must be "https://doi.org/10.5063/schema/codemeta-2.0", not ["https://doi.org/10.5063/schema/codemeta-100000"]');
});

it('errors nicely when there are other contexts', function() {
cy.get('#codemetaText').then((elem) =>
elem.text(JSON.stringify({
"@context": [
"https://doi.org/10.5063/schema/codemeta-2.0",
"https://schema.org/",
],
"@type": "SoftwareSourceCode",
"name": "My Test Software",
}))
);
cy.get('#importCodemeta').click();

cy.get('#errorMessage').should('have.text', 'Multiple values in @context are not supported (@context should be "https://doi.org/10.5063/schema/codemeta-2.0", not ["https://doi.org/10.5063/schema/codemeta-2.0","https://schema.org/"])');
});

});
15 changes: 0 additions & 15 deletions js/validation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ function validateDocument(doc) {
}
// TODO: validate id/@id

context = doc["@context"];
if (context == "https://doi.org/10.5063/schema/codemeta-2.0") {
// Correct
}
else if (Array.isArray(context) && context.includes("https://doi.org/10.5063/schema/codemeta-2.0")) {
if (context.length !== 1) {
setError(`Multiple values in @context are not supported (@context should be "https://doi.org/10.5063/schema/codemeta-2.0", not ${JSON.stringify(context)})`);
return false;
}
}
else {
setError(`@context must be "https://doi.org/10.5063/schema/codemeta-2.0", not ${JSON.stringify(context)}`);
return false;
}

// TODO: check there is either type or @type but not both
var type = getDocumentType(doc);
if (type === undefined) {
Expand Down

0 comments on commit 047b35e

Please sign in to comment.