Skip to content

Commit

Permalink
feat: schema cover letter (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
simboonlong authored Jul 11, 2023
1 parent 811410a commit 0510b66
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/io/tradetrust/cover-letter/1.0/context.test.ts
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 src/io/tradetrust/cover-letter/1.0/cover-letter-context.json
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"
}
]
}
Loading

0 comments on commit 0510b66

Please sign in to comment.