Skip to content

Commit

Permalink
WIP: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Sep 27, 2023
1 parent 04f38d7 commit 80d42d1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 37 deletions.
14 changes: 10 additions & 4 deletions src/gConsent/manage/denyAccessRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ describe("denyAccessRequest", () => {

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

it("throws if the provided VC isn't a Solid access request", async () => {
Expand Down Expand Up @@ -197,7 +200,8 @@ describe("denyAccessRequest", () => {
mode: accessRequestVcExpanded.credentialSubject.hasConsent.mode,
hasStatus: "https://w3id.org/GConsent#ConsentStatusDenied",
forPersonalData:
accessRequestVcExpanded.credentialSubject.hasConsent.forPersonalData,
accessRequestVcExpanded.credentialSubject.hasConsent
.forPersonalData,
}),
inbox: accessRequestVcExpanded.credentialSubject.inbox,
}),
Expand Down Expand Up @@ -232,7 +236,8 @@ describe("denyAccessRequest", () => {
mode: accessRequestVcExpanded.credentialSubject.hasConsent.mode,
hasStatus: "https://w3id.org/GConsent#ConsentStatusDenied",
forPersonalData:
accessRequestVcExpanded.credentialSubject.hasConsent.forPersonalData,
accessRequestVcExpanded.credentialSubject.hasConsent
.forPersonalData,
}),
inbox: accessRequestVcExpanded.credentialSubject.inbox,
}),
Expand Down Expand Up @@ -264,7 +269,8 @@ describe("denyAccessRequest", () => {
mode: accessRequestVcExpanded.credentialSubject.hasConsent.mode,
hasStatus: "https://w3id.org/GConsent#ConsentStatusDenied",
forPersonalData:
accessRequestVcExpanded.credentialSubject.hasConsent.forPersonalData,
accessRequestVcExpanded.credentialSubject.hasConsent
.forPersonalData,
isProvidedTo: "https://some.requestor",
},
inbox: accessRequestVcExpanded.credentialSubject.inbox,
Expand Down
4 changes: 2 additions & 2 deletions src/gConsent/manage/denyAccessRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ async function denyAccessRequest(
typeof options !== "undefined" ||
(typeof resourceOwnerOrVc === "string" &&
typeof vcOrOptions === "string") ||
// FIXME: Understand why adding this typeof vcOrOptions === "object" && was necessary before
// making a release. Without it we were passing undefined to isVerifiableCredential
// FIXME: Understand why adding this typeof vcOrOptions === "object" && was necessary before
// making a release. Without it we were passing undefined to isVerifiableCredential
(typeof vcOrOptions === "object" && isVerifiableCredential(vcOrOptions))
) {
// The deprecated signature is being used: ignore the first parameter
Expand Down
25 changes: 15 additions & 10 deletions src/gConsent/manage/getAccessGrant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
mockAccessGrantObject,
mockAccessGrantVc,
mockConsentRequestObject,
mockConsentRequestVc,
} from "../util/access.mock";
import { getAccessGrant } from "./getAccessGrant";

Expand All @@ -45,7 +44,7 @@ function withoutDataset(data: any) {
has: undefined,
[Symbol.iterator]: undefined,
delete: undefined,
}
};
}

jest.mock("@inrupt/universal-fetch", () => {
Expand Down Expand Up @@ -147,9 +146,9 @@ describe("getAccessGrant", () => {
...withoutDataset(mockAccessGrant).credentialSubject,
providedConsent: {
...withoutDataset(mockAccessGrant).credentialSubject.providedConsent,
hasStatus: 'Consent:StatusDenied'
}
}
hasStatus: "Consent:StatusDenied",
},
},
});
});

Expand All @@ -164,7 +163,9 @@ describe("getAccessGrant", () => {
const accessGrant = await getAccessGrant("https://some.vc.url", {
fetch: mockedFetch,
});
expect(withoutDataset(accessGrant)).toEqual(withoutDataset(mockAccessGrant));
expect(withoutDataset(accessGrant)).toEqual(
withoutDataset(mockAccessGrant),
);
});

it("normalizes equivalent JSON-LD VCs", async () => {
Expand Down Expand Up @@ -196,9 +197,11 @@ describe("getAccessGrant", () => {
);

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

Expand All @@ -213,6 +216,8 @@ describe("getAccessGrant", () => {
const accessGrant = await getAccessGrant(new URL("https://some.vc.url"), {
fetch: mockedFetch,
});
expect(withoutDataset(accessGrant)).toMatchObject(withoutDataset(mockAccessGrant));
expect(withoutDataset(accessGrant)).toMatchObject(
withoutDataset(mockAccessGrant),
);
});
});
9 changes: 3 additions & 6 deletions src/gConsent/manage/getAccessGrantAll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ import { mockAccessGrantVc } from "../util/access.mock";
const otherFetch = jest.fn(global.fetch);

jest.mock("@inrupt/solid-client-vc", () => {
const {
getVerifiableCredentialFromResponse,
getVerifiableCredentialAllFromShape,
} = jest.requireActual("@inrupt/solid-client-vc") as jest.Mocked<
typeof VcLibrary
>;
const { getVerifiableCredentialFromResponse } = jest.requireActual(
"@inrupt/solid-client-vc",
) as jest.Mocked<typeof VcLibrary>;
return {
getVerifiableCredentialFromResponse,
issueVerifiableCredential: jest.fn(),
Expand Down
7 changes: 3 additions & 4 deletions src/gConsent/manage/revokeAccessGrant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import type { revokeVerifiableCredential } from "@inrupt/solid-client-vc";
import { jest, describe, it, expect } from "@jest/globals";
import { Response } from "@inrupt/universal-fetch";

Expand All @@ -41,7 +40,7 @@ jest.mock("@inrupt/solid-client-vc", () => {
describe("revokeAccessGrant", () => {
it("uses the provided fetch if any", async () => {
const mockedVcModule = jest.requireMock("@inrupt/solid-client-vc") as {
revokeVerifiableCredential: typeof revokeVerifiableCredential;
revokeVerifiableCredential: (typeof VcLibrary)["revokeVerifiableCredential"];
};
const spiedRevoke = jest.spyOn(
mockedVcModule,
Expand All @@ -66,7 +65,7 @@ describe("revokeAccessGrant", () => {

it("looks up the VC if provided as an IRI", async () => {
const mockedVcModule = jest.requireMock("@inrupt/solid-client-vc") as {
revokeVerifiableCredential: typeof revokeVerifiableCredential;
revokeVerifiableCredential: (typeof VcLibrary)["revokeVerifiableCredential"];
};
const spiedRevoke = jest.spyOn(
mockedVcModule,
Expand Down Expand Up @@ -110,7 +109,7 @@ describe("revokeAccessGrant", () => {

it("gets the VC identifier if provided as a full credential", async () => {
const mockedVcModule = jest.requireMock("@inrupt/solid-client-vc") as {
revokeVerifiableCredential: typeof revokeVerifiableCredential;
revokeVerifiableCredential: (typeof VcLibrary)["revokeVerifiableCredential"];
};
const spiedRevoke = jest.spyOn(
mockedVcModule,
Expand Down
16 changes: 5 additions & 11 deletions src/gConsent/util/access.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ type RequestVcOptions = Partial<{
resourceOwner: string | null;
inherit: boolean;
purpose: UrlString[];
}>
}>;

export const mockAccessRequestVcObject = (
options?: RequestVcOptions
) => {
export const mockAccessRequestVcObject = (options?: RequestVcOptions) => {
const hasConsent = {
forPersonalData: options?.resources ?? ["https://some.resource"],
hasStatus: GC_CONSENT_STATUS_REQUESTED,
Expand Down Expand Up @@ -96,8 +94,8 @@ export const mockAccessRequestVcObject = (
asObject.credentialSubject.hasConsent.forPurpose = options.purpose;
}

return asObject
}
return asObject;
};

export const mockAccessRequestVc = async (
options?: RequestVcOptions,
Expand Down Expand Up @@ -228,18 +226,14 @@ export const mockAccessGrantVc = async (
return accessGrant as unknown as AccessGrant & DatasetCore<Quad, Quad>;
};


export const mockConsentRequestObject = (
options?: RequestVcOptions,
) => {
export const mockConsentRequestObject = (options?: RequestVcOptions) => {
const requestVc = mockAccessRequestVcObject(options);
requestVc.credentialSubject.hasConsent.forPurpose = ["https://some.purpose"];
requestVc.expirationDate = new Date(2021, 8, 14).toISOString();
requestVc.issuanceDate = new Date(2021, 8, 13).toISOString();
return requestVc;
};


export const mockConsentRequestVc = async (
options?: RequestVcOptions,
framingOptions?: {
Expand Down

0 comments on commit 80d42d1

Please sign in to comment.