Skip to content

Commit

Permalink
chore: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Sep 27, 2023
1 parent 80d42d1 commit 76edc8f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
5 changes: 4 additions & 1 deletion src/gConsent/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export const ACCESS_GRANT_CONTEXT_DEFAULT = [
instanciateContextVcEssTemplate("vc.inrupt.com"),
] as const;

export const MOCK_CONTEXT = [...ACCESS_GRANT_CONTEXT_DEFAULT, ...extraContext];
export const MOCK_CONTEXT = [
...ACCESS_GRANT_CONTEXT_DEFAULT,
...extraContext,
] as const;

// When issuing a VC using a given service,"https://schema.inrupt.com/credentials/v1.jsonld" be sure to set the context using the following.
export const instanciateEssAccessGrantContext = (
Expand Down
7 changes: 3 additions & 4 deletions src/gConsent/request/cancelAccessRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//

import { jest, describe, it, expect } from "@jest/globals";
import type { revokeVerifiableCredential } from "@inrupt/solid-client-vc";
import { Response } from "@inrupt/universal-fetch";
import type * as VcLibrary from "@inrupt/solid-client-vc";
import { cancelAccessRequest } from "./cancelAccessRequest";
Expand Down Expand Up @@ -50,7 +49,7 @@ jest.mock("@inrupt/solid-client-vc", () => {
describe("cancelAccessRequest", () => {
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 @@ -75,7 +74,7 @@ describe("cancelAccessRequest", () => {

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 @@ -111,7 +110,7 @@ describe("cancelAccessRequest", () => {

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
34 changes: 15 additions & 19 deletions src/gConsent/request/issueAccessRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
//

import { jest, describe, it, expect, beforeAll } from "@jest/globals";
import type {
issueVerifiableCredential,
JsonLd,
VerifiableCredential,
} from "@inrupt/solid-client-vc";
import type * as CrossFetch from "@inrupt/universal-fetch";
import type * as VcLibrary from "@inrupt/solid-client-vc";

Expand Down Expand Up @@ -163,7 +158,7 @@ describe("issueAccessRequest", () => {
mockAccessApiEndpoint();
const mockedIssue = jest.spyOn(
jest.requireMock("@inrupt/solid-client-vc") as {
issueVerifiableCredential: typeof issueVerifiableCredential;
issueVerifiableCredential: typeof VcLibrary.issueVerifiableCredential;
},
"issueVerifiableCredential",
);
Expand Down Expand Up @@ -202,7 +197,7 @@ describe("issueAccessRequest", () => {
mockAccessApiEndpoint();
const mockedIssue = jest.spyOn(
jest.requireMock("@inrupt/solid-client-vc") as {
issueVerifiableCredential: typeof issueVerifiableCredential;
issueVerifiableCredential: typeof VcLibrary.issueVerifiableCredential;
},
"issueVerifiableCredential",
);
Expand All @@ -229,7 +224,7 @@ describe("issueAccessRequest", () => {
mockAccessApiEndpoint();
const mockedIssue = jest.spyOn(
jest.requireMock("@inrupt/solid-client-vc") as {
issueVerifiableCredential: typeof issueVerifiableCredential;
issueVerifiableCredential: typeof VcLibrary.issueVerifiableCredential;
},
"issueVerifiableCredential",
);
Expand All @@ -254,7 +249,7 @@ describe("issueAccessRequest", () => {
mockAccessApiEndpoint();
const mockedIssue = jest.spyOn(
jest.requireMock("@inrupt/solid-client-vc") as {
issueVerifiableCredential: typeof issueVerifiableCredential;
issueVerifiableCredential: typeof VcLibrary.issueVerifiableCredential;
},
"issueVerifiableCredential",
);
Expand All @@ -273,9 +268,10 @@ describe("issueAccessRequest", () => {
);

// Casting is required because TS picks up the deprecated signature.
const subjectClaims = mockedIssue.mock.calls[0][1] as unknown as JsonLd;
const subjectClaims = mockedIssue.mock
.calls[0][1] as unknown as VcLibrary.JsonLd;
const credentialClaims = mockedIssue.mock.calls[0][2] as unknown as
| JsonLd
| VcLibrary.JsonLd
| undefined;

expect(subjectClaims).toStrictEqual(
Expand All @@ -300,7 +296,7 @@ describe("issueAccessRequest", () => {
mockAccessApiEndpoint();
const mockedIssue = jest.spyOn(
jest.requireMock("@inrupt/solid-client-vc") as {
issueVerifiableCredential: typeof issueVerifiableCredential;
issueVerifiableCredential: typeof VcLibrary.issueVerifiableCredential;
},
"issueVerifiableCredential",
);
Expand Down Expand Up @@ -345,7 +341,7 @@ describe("issueAccessRequest", () => {
mockAccessApiEndpoint();
const mockedIssue = jest.spyOn(
jest.requireMock("@inrupt/solid-client-vc") as {
issueVerifiableCredential: typeof issueVerifiableCredential;
issueVerifiableCredential: typeof VcLibrary.issueVerifiableCredential;
},
"issueVerifiableCredential",
);
Expand Down Expand Up @@ -381,7 +377,7 @@ describe("issueAccessRequest", () => {
mockAccessApiEndpoint();
const mockedIssue = jest.spyOn(
jest.requireMock("@inrupt/solid-client-vc") as {
issueVerifiableCredential: typeof issueVerifiableCredential;
issueVerifiableCredential: typeof VcLibrary.issueVerifiableCredential;
},
"issueVerifiableCredential",
);
Expand Down Expand Up @@ -411,7 +407,7 @@ describe("issueAccessRequest", () => {
mockAccessApiEndpoint();
const mockedIssue = jest.spyOn(
jest.requireMock("@inrupt/solid-client-vc") as {
issueVerifiableCredential: typeof issueVerifiableCredential;
issueVerifiableCredential: typeof VcLibrary.issueVerifiableCredential;
},
"issueVerifiableCredential",
);
Expand Down Expand Up @@ -441,7 +437,7 @@ describe("issueAccessRequest", () => {
mockAccessApiEndpoint();
const mockedIssue = jest.spyOn(
jest.requireMock("@inrupt/solid-client-vc") as {
issueVerifiableCredential: typeof issueVerifiableCredential;
issueVerifiableCredential: typeof VcLibrary.issueVerifiableCredential;
},
"issueVerifiableCredential",
);
Expand Down Expand Up @@ -490,7 +486,7 @@ describe("issueAccessRequest", () => {
mockAccessApiEndpoint();
const mockedIssue = jest.spyOn(
jest.requireMock("@inrupt/solid-client-vc") as {
issueVerifiableCredential: typeof issueVerifiableCredential;
issueVerifiableCredential: typeof VcLibrary.issueVerifiableCredential;
},
"issueVerifiableCredential",
);
Expand Down Expand Up @@ -519,7 +515,7 @@ describe("issueAccessRequest", () => {
mockAccessApiEndpoint();
const mockedIssue = jest.spyOn(
jest.requireMock("@inrupt/solid-client-vc") as {
issueVerifiableCredential: typeof issueVerifiableCredential;
issueVerifiableCredential: typeof VcLibrary.issueVerifiableCredential;
},
"issueVerifiableCredential",
);
Expand All @@ -545,7 +541,7 @@ describe("issueAccessRequest", () => {
).resolves.toStrictEqual(normalizedAccessRequest);
});

const mockCredentialProof = (): VerifiableCredential["proof"] => {
const mockCredentialProof = (): VcLibrary.VerifiableCredential["proof"] => {
return {
created: "some date",
proofPurpose: "some purpose",
Expand Down
15 changes: 11 additions & 4 deletions src/gConsent/util/access.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const mockAccessRequestVcObject = (options?: RequestVcOptions) => {
hasConsent.isConsentForDataSubject = options?.resourceOwner;
}

// We want to be able to mutate the record so we cannot set as a const
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const asObject: Record<string, any> = {
"@context": MOCK_CONTEXT,
id: "https://some.credential",
Expand Down Expand Up @@ -113,7 +115,9 @@ export const mockAccessRequestVc = async (
});

let accessRequest: VerifiableCredential & DatasetCore;
let nonNormalizedResponse: any;
let nonNormalizedResponse:
| Awaited<ReturnType<typeof getVerifiableCredentialFromResponse>>
| undefined;
try {
nonNormalizedResponse = await getVerifiableCredentialFromResponse(
asResponse,
Expand Down Expand Up @@ -215,11 +219,14 @@ export const mockAccessGrantVc = async (
}

if (framingOptions?.expandModeUri) {
// @ts-ignore
accessGrant.credentialSubject?.providedConsent?.mode = // @ts-ignore
accessGrant.credentialSubject?.providedConsent?.mode.map(
const providedConsent = accessGrant.credentialSubject?.providedConsent as
| { mode?: string[] | undefined }
| undefined;
if (providedConsent) {
providedConsent.mode = providedConsent.mode?.map(
(mode: string) => `http://www.w3.org/ns/auth/acl#${mode}`,
);
}
}

// FIXME type casting is bad
Expand Down
6 changes: 3 additions & 3 deletions src/parsing/contexts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import { getVerifiableCredential } from "@inrupt/solid-client-vc";

import vc from "./vc";
import integrity from "./data-integrity";
import ed25519 from "./ed25519-2020";
import revocation from "./revocation-list";
import status from "./status-list";
import statusList from "./status-list";

export const data = {
"https://vc.inrupt.com/credentials/v1": vc,
"https://w3id.org/security/data-integrity/v1": integrity,
"https://w3id.org/vc-revocation-list-2020/v1": revocation,
"https://w3id.org/vc/status-list/2021/v1": status,
"https://w3id.org/vc/status-list/2021/v1": statusList,
"https://w3id.org/security/suites/ed25519-2020/v1": ed25519,
};

0 comments on commit 76edc8f

Please sign in to comment.