-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
811410a
commit 0510b66
Showing
5 changed files
with
132 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import context from "./cover-letter-context.json"; | ||
import sampleDocument from "./cover-letter-data.json"; | ||
import { expand, JsonLdDocument } from "jsonld"; | ||
|
||
const expandDocument = async (mergedDocument: JsonLdDocument) => { | ||
return await expand(mergedDocument, { | ||
expansionMap: function(info) { | ||
if (info.unmappedProperty) { | ||
throw new Error( | ||
'"The property ' + | ||
(info.activeProperty ? info.activeProperty + "." : "") + | ||
info.unmappedProperty + | ||
' in the input was not defined in the context"' | ||
); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
describe("cover letter context", () => { | ||
it("should work with valid cover letter", async () => { | ||
const mergedDocument = { | ||
"@context": context["@context"], | ||
...sampleDocument | ||
} as JsonLdDocument; | ||
|
||
expect(await expandDocument(mergedDocument)).toBeTruthy(); | ||
}); | ||
|
||
it("should throw error when property not defined in context", async () => { | ||
const modifiedSampleDocument = { | ||
...sampleDocument, | ||
invalidCoverLetterProperties: "Random String" | ||
}; | ||
|
||
const mergedDocument = { | ||
"@context": context["@context"], | ||
...modifiedSampleDocument | ||
} as JsonLdDocument; | ||
|
||
return expect(expandDocument(mergedDocument)).rejects.toThrowError( | ||
"The property invalidCoverLetterProperties in the input was not defined in the context" | ||
); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/io/tradetrust/cover-letter/1.0/cover-letter-context.json
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"@context": [ | ||
{ | ||
"@version": 1.1 | ||
}, | ||
"https://www.w3.org/ns/odrl.jsonld", | ||
{ | ||
"name": "xsd:string", | ||
"logo": "xsd:string", | ||
"title": "xsd:string", | ||
"remarks": "xsd:string", | ||
"backgroundColor": "xsd:string", | ||
"titleColor": "xsd:string", | ||
"remarksColor": "xsd:string" | ||
} | ||
] | ||
} |
Oops, something went wrong.