Skip to content

Commit

Permalink
chore: fix object matching with dataset properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Sep 27, 2023
1 parent e5ebf68 commit 6e37421
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
23 changes: 13 additions & 10 deletions src/gConsent/manage/denyAccessRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ jest.mock("@inrupt/universal-fetch", () => {
// TODO: Extract the fetch VC function and related tests
describe("denyAccessRequest", () => {
let accessRequestVc: Awaited<ReturnType<typeof mockAccessRequestVc>>;
let accessRequestVcExpanded: Awaited<ReturnType<typeof mockAccessRequestVc>>;

beforeAll(async () => {
accessRequestVc = await mockAccessRequestVc({}, { expandModeUri: true });
accessRequestVc = await mockAccessRequestVc();
accessRequestVcExpanded = await mockAccessRequestVc({}, { expandModeUri: true });
});

it("throws if the provided VC isn't a Solid access request", async () => {
Expand All @@ -84,6 +86,7 @@ describe("denyAccessRequest", () => {

it("throws if there is no well known access endpoint", async () => {
mockAccessApiEndpoint(false);
console.log('the access request vc is', accessRequestVc)
await expect(denyAccessRequest(accessRequestVc)).rejects.toThrow(
"No access issuer listed for property [verifiable_credential_issuer] in",
);
Expand Down Expand Up @@ -192,12 +195,12 @@ describe("denyAccessRequest", () => {
`${MOCKED_ACCESS_ISSUER}/issue`,
expect.objectContaining({
providedConsent: expect.objectContaining({
mode: accessRequestVc.credentialSubject.hasConsent.mode,
mode: accessRequestVcExpanded.credentialSubject.hasConsent.mode,
hasStatus: "https://w3id.org/GConsent#ConsentStatusDenied",
forPersonalData:
accessRequestVc.credentialSubject.hasConsent.forPersonalData,
accessRequestVcExpanded.credentialSubject.hasConsent.forPersonalData,
}),
inbox: accessRequestVc.credentialSubject.inbox,
inbox: accessRequestVcExpanded.credentialSubject.inbox,
}),
expect.objectContaining({
type: ["SolidAccessDenial"],
Expand Down Expand Up @@ -227,12 +230,12 @@ describe("denyAccessRequest", () => {
`${MOCKED_ACCESS_ISSUER}/issue`,
expect.objectContaining({
providedConsent: expect.objectContaining({
mode: accessRequestVc.credentialSubject.hasConsent.mode,
mode: accessRequestVcExpanded.credentialSubject.hasConsent.mode,
hasStatus: "https://w3id.org/GConsent#ConsentStatusDenied",
forPersonalData:
accessRequestVc.credentialSubject.hasConsent.forPersonalData,
accessRequestVcExpanded.credentialSubject.hasConsent.forPersonalData,
}),
inbox: accessRequestVc.credentialSubject.inbox,
inbox: accessRequestVcExpanded.credentialSubject.inbox,
}),
expect.objectContaining({
type: ["SolidAccessDenial"],
Expand All @@ -259,13 +262,13 @@ describe("denyAccessRequest", () => {
`${MOCKED_ACCESS_ISSUER}/issue`,
expect.objectContaining({
providedConsent: {
mode: accessRequestVc.credentialSubject.hasConsent.mode,
mode: accessRequestVcExpanded.credentialSubject.hasConsent.mode,
hasStatus: "https://w3id.org/GConsent#ConsentStatusDenied",
forPersonalData:
accessRequestVc.credentialSubject.hasConsent.forPersonalData,
accessRequestVcExpanded.credentialSubject.hasConsent.forPersonalData,
isProvidedTo: "https://some.requestor",
},
inbox: accessRequestVc.credentialSubject.inbox,
inbox: accessRequestVcExpanded.credentialSubject.inbox,
}),
expect.objectContaining({
type: ["SolidAccessDenial"],
Expand Down
1 change: 1 addition & 0 deletions src/gConsent/manage/denyAccessRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ async function denyAccessRequest(
vcOrOptions?: VerifiableCredential | URL | UrlString | AccessBaseOptions,
options?: AccessBaseOptions,
): Promise<VerifiableCredential> {
console.log(options, resourceOwnerOrVc, vcOrOptions)
if (
typeof options !== "undefined" ||
(typeof resourceOwnerOrVc === "string" &&
Expand Down
31 changes: 24 additions & 7 deletions src/gConsent/manage/getAccessGrant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ import {
} from "../util/access.mock";
import { getAccessGrant } from "./getAccessGrant";

/**
* Remove the properties of an RDF.DatasetCore from an object so that
* we can do equality matches in jest without those functions causing
* problems
*/
function withoutDataset(data: any) {
return {
...data,
add: undefined,
match: undefined,
has: undefined,
[Symbol.iterator]: undefined,
delete: undefined,
}
}

jest.mock("@inrupt/universal-fetch", () => {
const crossFetch = jest.requireActual(
"@inrupt/universal-fetch",
Expand Down Expand Up @@ -124,7 +140,7 @@ describe("getAccessGrant", () => {
const accessGrant = await getAccessGrant("https://some.vc.url", {
fetch: mockedFetch,
});
expect(accessGrant).toEqual(mockAccessGrant);
expect(withoutDataset(accessGrant)).toEqual(withoutDataset(mockAccessGrant));
});

it("returns the access grant with the given IRI", async () => {
Expand All @@ -138,7 +154,7 @@ describe("getAccessGrant", () => {
const accessGrant = await getAccessGrant("https://some.vc.url", {
fetch: mockedFetch,
});
expect(accessGrant).toEqual(mockAccessGrant);
expect(withoutDataset(accessGrant)).toEqual(withoutDataset(mockAccessGrant));
});

it("normalizes equivalent JSON-LD VCs", async () => {
Expand Down Expand Up @@ -168,11 +184,12 @@ describe("getAccessGrant", () => {
},
),
);
await expect(
getAccessGrant("https://some.vc.url", {

expect(
withoutDataset(await getAccessGrant("https://some.vc.url", {
fetch: mockedFetch,
}),
).resolves.toEqual(normalizedAccessGrant);
})),
).toEqual(withoutDataset(mockAccessGrant));
});

it("returns the access grant with the given URL object", async () => {
Expand All @@ -186,6 +203,6 @@ describe("getAccessGrant", () => {
const accessGrant = await getAccessGrant(new URL("https://some.vc.url"), {
fetch: mockedFetch,
});
expect(accessGrant).toMatchObject(mockAccessGrant);
expect(withoutDataset(accessGrant)).toMatchObject(withoutDataset(mockAccessGrant));
});
});

0 comments on commit 6e37421

Please sign in to comment.