forked from UTS-eResearch/ro-crate-js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchecker.spec.js
197 lines (190 loc) · 7.16 KB
/
checker.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/* This is part of Calcyte a tool for implementing the DataCrate data packaging
spec. Copyright (C) 2018 University of Technology Sydney
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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/>.
*/
const assert = require("assert");
const {Checker} = require("../lib/checker");
const chai = require("chai");
chai.use(require("chai-fs"));
const defaults = require("../lib/defaults");
const {ROCrate} = require("../lib/rocrate");
const {describe} = require("node:test");
describe("All test", async function() {
it("should test all the things", async function(){
this.timeout(5000);
var crate = new ROCrate();
var json = crate.toJSON(); // should be a minimal viable datacrate
var checker = new Checker(new ROCrate(json));
console.log(await checker.validate());
});
});
// describe("Incremental checking", async function () {
// it("should trigger all the right reporting", async function () {
// this.timeout(10000);
// //json = JSON.parse(fs.readFileSync("test_data/sample-ro-crate-metadata.jsonld"));
// var crate = new ROCrate();
// var json = crate.toJSON(); // should be a minimal viable datacrate
// json["@context"] = [];
// var checker = new Checker(new ROCrate(json));
// assert(!(await checker.hasContext()).status, "Does not have a @context");
// // Now with context
// json["@context"] = defaults.context;
// var checker = new Checker(new ROCrate(json));
// assert((await checker.hasContext()).status, "Has a @context");
// // Don't have a dataset tho yet
//
// var checker = new Checker(new ROCrate(json));
// assert(checker.hasRootDataset().status, "Does have a root dataset");
// // No name yet
// assert(!checker.hasName().status, "Does not have a name");
// //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"
// );
//
// // 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"
// );
//
// // License
// // No name, description
// assert(
// !checker.hasLicense().status,
// "Does not have a license with @type CreativeWork"
// );
// 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"
// );
// 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"
// );
//
// // 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)"
// );
//
// crate.rootDataset.datePublished = ["2017-07-21", "2019-08-09"]; // this should do it
// assert(
// !checker.hasDatePublished().status,
// "Does not have a single datePublished"
// );
//
// 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());
// });
// it("should check for invalid context", async function () {
// this.timeout(10000);
// var crate = new ROCrate({'@context': []});
// var checker = new Checker(crate);
// assert(!(await checker.hasContext()).status, "Does not have a @context");
// // Now with context
// crate = new ROCrate();
// var checker = new Checker(crate);
// assert((await checker.hasContext()).status, "Has a @context");
// // check for invalid context
// crate.addContext('https://w3id.org/ldac/profile');
// assert(!(await (new Checker(crate)).hasContext()).status, "Has invalid url in @context");
// });
// });
after(function () {
//TODO: destroy test repoPath
});