forked from UTS-eResearch/ro-crate-js
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at updating the validator
- Loading branch information
Showing
6 changed files
with
90 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,23 @@ GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
|
||
/* | ||
The Root Data Entity MUST have the following properties: | ||
@type: MUST be [Dataset] or an array that contain Dataset | ||
@id: SHOULD be the string ./ or an absolute URI (see below) | ||
name: SHOULD identify the dataset to humans well enough to disambiguate it from other RO-Crates | ||
description: SHOULD further elaborate on the name to provide a summary of the context in which the dataset is important. | ||
datePublished: MUST be a string in [ISO 8601 date format][DateTime] and SHOULD be specified to at least the precision of a day, MAY be a timestamp down to the millisecond. | ||
license: SHOULD link to a Contextual Entity or Data Entity in the RO-Crate Metadata Document with a name and description (see section on licensing). MAY, if necessary be a textual description of how the RO-Crate may be used. | ||
*/ | ||
|
||
const assert = require("assert"); | ||
|
@@ -44,93 +61,67 @@ describe("Incremental checking", async function () { | |
//var dataset = crate.getRootDataset(); | ||
var dataset = json["@graph"][0]; | ||
dataset.name = ""; | ||
|
||
|
||
var checker = new Checker(new ROCrate(json)); | ||
assert(!checker.hasName().status, "Does not have a name"); | ||
dataset.name = "Name!"; | ||
|
||
var checker = new Checker(new ROCrate(json)); | ||
assert(checker.hasName().status, "Does have a name"); | ||
assert(!checker.hasAuthor().status, "Does not have author"); | ||
|
||
// Author | ||
var author1 = { | ||
"@id": "http://orcid.org/some-orcid", | ||
name: "Some Person", | ||
}; | ||
dataset.author = [{ "@id": "http://orcid.org/some-orcid" }]; | ||
json["@graph"].push(author1); | ||
var checker = new Checker(new ROCrate(json)); | ||
assert( | ||
!checker.hasAuthor().status, | ||
"Does not have one or more authors with @type Person or Organization" | ||
); | ||
|
||
// One good author and one dodgy one | ||
var author2 = { | ||
"@id": "http://orcid.org/some-other-orcid", | ||
name: "Some Person", | ||
"@type": "Person", | ||
}; | ||
dataset.author = [{ "@id": "http://orcid.org/some-orcid" }, { "@id": "http://orcid.org/some-other-orcid" }]; | ||
json["@graph"].push(author1, author2); | ||
var checker = new Checker(new ROCrate(json)); | ||
assert( | ||
!checker.hasAuthor().status, | ||
"Does not have one or more authors with @type Person or Organization" | ||
); | ||
assert(!checker.hasDescription().status, "Does not have a description"); | ||
dataset.description = "Description!"; | ||
|
||
// One good author | ||
dataset.author = [author2]; | ||
json["@graph"] = [ | ||
defaults.metadataFileDescriptorTemplate, | ||
dataset, | ||
author2, | ||
]; | ||
var checker = new Checker(new ROCrate(json)); | ||
assert( | ||
checker.hasAuthor().status, | ||
"Does have a author with @type Person or Organization" | ||
); | ||
assert(checker.hasName().status, "Does have a description"); | ||
|
||
// License | ||
// No name, description | ||
console.log(checker.hasLicense()); | ||
assert( | ||
!checker.hasLicense().status, | ||
"Does not have a license with @type CreativeWork" | ||
"Has a license" | ||
); | ||
|
||
var license = { | ||
"@id": "http://example.com/some_kind_of_license", | ||
"@type": "CreativeWork", | ||
URL: "http://example.com/some_kind_of_license", | ||
}; | ||
dataset.license = { "@id": license["@id"] }; | ||
|
||
json["@graph"].push(license); | ||
crate = new ROCrate(json); | ||
var checker = new Checker(crate); | ||
assert( | ||
checker.hasLicense().status, | ||
"Has a license with @type CreativeWork" | ||
"Has a license" | ||
); | ||
|
||
license.name = "Some license"; | ||
license.description = "Description of at least 20 characters."; | ||
|
||
assert( | ||
checker.hasLicense().status, | ||
"Does have a license with @type CreativeWork and a name and description" | ||
"Has a license" | ||
); | ||
|
||
// datePublished | ||
assert( | ||
!checker.hasDatePublished().status, | ||
"Does not have a datePublished" | ||
); | ||
|
||
|
||
crate.rootDataset.datePublished = "2017"; // Not enough detail! | ||
assert( | ||
!checker.hasDatePublished().status, | ||
"Does not have a datePublished (not enough detail)" | ||
checker.hasDatePublished().status, | ||
); | ||
|
||
crate.rootDataset.datePublished = ["2017-07-21", "2019-08-09"]; // this should do it | ||
crate.rootDataset.datePublished = ["2017-07-21", "2019-08-09"]; | ||
assert( | ||
!checker.hasDatePublished().status, | ||
"Does not have a single datePublished" | ||
|
@@ -139,32 +130,10 @@ describe("Incremental checking", async function () { | |
crate.rootDataset.datePublished = ["2017-07-21"]; // this should do it | ||
assert(checker.hasDatePublished().status, "Does have a datePublished"); | ||
|
||
//contactPoint missing | ||
assert( | ||
!checker.hasContactPoint().status, | ||
"Does not have a single contact point" | ||
); | ||
var contact = { | ||
"@id": "[email protected]", | ||
"@type": "ContactPoint", | ||
}; // Not enough | ||
dataset.contactPoint = [{ "@id": "[email protected]" }]; | ||
json["@graph"].push(contact); | ||
var checker = new Checker(new ROCrate(json)); | ||
assert( | ||
!checker.hasContactPoint().status, | ||
"Does not have a contact point with enough properties" | ||
); | ||
contact.contactType = "customer service"; | ||
contact.email = "some@email"; // TODO: Not validated! | ||
var checker = new Checker(new ROCrate(json)); | ||
assert( | ||
checker.hasContactPoint().status, | ||
"Does have a proper contact point" | ||
); | ||
|
||
|
||
await checker.check(); | ||
//console.log(checker.report()); | ||
console.log(checker.report()); | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -497,6 +497,20 @@ describe("setProperty", function () { | |
assert.strictEqual(r.license.length, 2); | ||
|
||
}); | ||
|
||
it("Does not kill existing entities", function() { | ||
let crate = new ROCrate(testData, { link: true, replace: true }); | ||
let e = crate.getEntity('https://orcid.org/0000'); | ||
assert.ok(e); | ||
assert.strictEqual(e.contactPoint.email, "[email protected]"); | ||
crate.rootDataset.author = {'@id': 'https://orcid.org/0000'} | ||
let auth = crate.getEntity('https://orcid.org/0000'); | ||
assert.strictEqual(auth.contactPoint.email, "[email protected]"); | ||
|
||
|
||
}); | ||
|
||
|
||
it("can replace existing entities", function() { | ||
let crate = new ROCrate(testData, { link: true, replace: true }); | ||
let e = crate.getEntity('https://orcid.org/0000'); | ||
|
@@ -505,7 +519,7 @@ describe("setProperty", function () { | |
// ref only, don't replace | ||
crate.rootDataset.author = {'@id': 'https://orcid.org/0000'} | ||
let auth = crate.getEntity('https://orcid.org/0000'); | ||
assert.strictEqual(auth.name, "John Doe"); | ||
assert.strictEqual(auth.name, "John Doe"); | ||
assert.strictEqual(auth.contactPoint.email, "[email protected]"); | ||
// replace here | ||
crate.rootDataset.author = { | ||
|
@@ -517,6 +531,14 @@ describe("setProperty", function () { | |
assert.ok(!auth.contactPoint); | ||
assert.strictEqual(auth.name, "Jane Doe"); | ||
|
||
|
||
|
||
crate.rootDataset.author = {'@id': 'https://orcid.org/0000'} | ||
let auth1 = crate.getEntity('https://orcid.org/0000'); | ||
assert.strictEqual(auth1.name, "John Doe"); | ||
assert.strictEqual(auth1.contactPoint.email, "[email protected]"); | ||
|
||
|
||
}); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4000,4 +4000,4 @@ | |
"name": "pics/thumbs/sepia_fence.png" | ||
} | ||
] | ||
} | ||
} |