Skip to content

Commit

Permalink
chore: fix code coverage errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Oct 18, 2023
1 parent df52507 commit eac7d5d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
39 changes: 37 additions & 2 deletions src/common/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ describe("getVerifiableCredential", () => {
);
});

it("should handle credential subject with a blank node", async () => {
it("should handle credential subject with a blank node and a boolean", async () => {
const store = await jsonLdToStore(mockDefaultCredential());

store.add(
Expand All @@ -1001,6 +1001,38 @@ describe("getVerifiableCredential", () => {
),
);

store.add(
DataFactory.quad(
DataFactory.namedNode("https://some.webid.provider/strelka"),
DataFactory.namedNode("https://example.org/predicateTrue"),
DataFactory.literal("true", DataFactory.namedNode("http://www.w3.org/2001/XMLSchema#boolean")),
),
);

store.add(
DataFactory.quad(
DataFactory.namedNode("https://some.webid.provider/strelka"),
DataFactory.namedNode("https://example.org/predicateFalse"),
DataFactory.literal("false", DataFactory.namedNode("http://www.w3.org/2001/XMLSchema#boolean")),
),
);

store.add(
DataFactory.quad(
DataFactory.namedNode("https://some.webid.provider/strelka"),
DataFactory.namedNode("https://example.org/predicateFalse"),
DataFactory.literal("false", DataFactory.namedNode("http://www.w3.org/2001/XMLSchema#boolean")),
),
);

store.add(
DataFactory.quad(
DataFactory.namedNode("https://some.webid.provider/strelka"),
DataFactory.namedNode("https://w3id.org/GConsent#forPurpose"),
DataFactory.namedNode("http://example.org/known/to/be/iri/from/predicate"),
),
);

store.add(
DataFactory.quad(
DataFactory.namedNode("https://some.webid.provider/strelka"),
Expand All @@ -1013,7 +1045,7 @@ describe("getVerifiableCredential", () => {
await getVerifiableCredentialFromStore(store, "https://some.vc"),
).toMatchObject(
Object.assign(mockDefaultCredential(), {
size: 15,
size: 18,
// We always re-frame w.r.t to this context
"@context": [
"https://www.w3.org/2018/credentials/v1",
Expand All @@ -1033,6 +1065,9 @@ describe("getVerifiableCredential", () => {
"@id": "https://example.org/object",
},
"https://example.org/predicateBnode": {},
"https://example.org/predicateFalse": false,
"https://example.org/predicateTrue": true,
forPurpose: "http://example.org/known/to/be/iri/from/predicate"
},
// Any types outside of those in our VC and Inrupt context are removed
type: ["VerifiableCredential"],
Expand Down
17 changes: 17 additions & 0 deletions src/parser/jsonld.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ describe("jsonLdResponseToStore", () => {
).toBe(true);
});

it("should error if trying to fetch a remote context when allowContextFetching is disabled", async () => {
const response = new Response(
JSON.stringify({
"@context": [
"https://www.w3.org/2018/credentials/v1",
"http://example.org/my/remote/context",
],
id: "https://some.example#credential",
type: ["VerifiableCredential"],
issuer: "https://some.example",
}),
);
await expect(jsonLdResponseToStore(response, {
allowContextFetching: false
})).rejects.toThrowError('Unexpected context requested [http://example.org/my/remote/context]');
});

it("converting fetch response with custom prefix definition to a store", async () => {
const response = new Response(JSON.stringify(dataWithPrefix));
const quads = [...(await jsonLdResponseToStore(response))];
Expand Down
2 changes: 1 addition & 1 deletion src/parser/jsonld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CachedFetchDocumentLoader extends FetchDocumentLoader {
...args: ConstructorParameters<typeof FetchDocumentLoader>
) {
super(...args);
this.contexts = contexts ? { ...contexts, ...CONTEXTS } : CONTEXTS;
this.contexts = { ...contexts, ...CONTEXTS };
}

public async load(url: string): Promise<IJsonLdContext> {
Expand Down

0 comments on commit eac7d5d

Please sign in to comment.