Skip to content

Commit

Permalink
jskos-convert: warn if scheme misses namespace/uriPattern (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Oct 1, 2024
1 parent a4d4bc7 commit aa377ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/jskos-convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ function convert (opts) {
destination = selectScheme(registry, destination)
}

if (type === "concept" && (!scheme?.namespace && !scheme?.uriPattern)) {
throw new Error("Converting concepts requires `namespace` or `uriPattern` on the associated scheme.")
}

// build steps
let steps = []
if (from === "csv") {
Expand Down
13 changes: 12 additions & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("jskos-convert", () => {

it("should return ndjson by default", (done) => {
let input = file("test/valid-mapping.ndjson")
convert([input], (error, stdout, stderr) => {
convert(["mapping", input], (error, stdout, stderr) => {
let expect = JSON.parse(fs.readFileSync(input))
let output = JSON.parse(""+stdout)
assert.deepEqual(expect, output)
Expand All @@ -76,5 +76,16 @@ describe("jskos-convert", () => {
})
}

it("should not convert when namespace for scheme is missing", (done) => {
const input = file("test/test-concepts.csv")
const scheme = file("test/test-scheme-fail.json")
convert(["concepts", "-s", scheme, "-t", "ndjson", "-m", input], (error, stdout, stderr) => {
assert.equal(error?.code, 1)
// Make sure error messages mentions "namespace"
assert.ok(stderr.includes("namespace"))
done()
})
})


})
3 changes: 3 additions & 0 deletions test/test-scheme-fail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"uri": "http://example.com/"
}

0 comments on commit aa377ab

Please sign in to comment.