forked from passportxyz/passport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app,iam,platforms): WIP - first working version for the new refe… (
passportxyz#1721) * feat(app,iam,platforms): WIP - first working version for the new referify flow * feat(app): cleanup & bug fixes - remove console logs - removing unused code - bug fixing cleanPassport in CeramicContext * fix(app): fix failing test due to EIP712 VC configuration * fix(app): fix failing test case * feat(app): adding tests for the stamp claiming context * feat(app): testing ExpiredStampsPanel - also his the "Reverify" button in the panel when there are no expired stamps * feat(app,identity): remove try-catch in _issueEd25519Credential, fixing linter complaints * fix(app): fix typescript errors * fix(app): fixing build errors * feat(app): remove unused variables * fix(app): remove TODOs * fix(app): adding back code that was commented out for debugging
- Loading branch information
Showing
24 changed files
with
758 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from "react"; | ||
import { screen } from "@testing-library/react"; | ||
|
||
import { UserContextState } from "../../context/userContext"; | ||
import { CardList, CardListProps } from "../../components/CardList"; | ||
import { | ||
makeTestCeramicContext, | ||
makeTestUserContext, | ||
renderWithContext, | ||
makeTestCeramicContextWithExpiredStamps, | ||
} from "../../__test-fixtures__/contextTestHelpers"; | ||
import { CeramicContextState } from "../../context/ceramicContext"; | ||
import { ExpiredStampsPanel } from "../../components/ExpiredStampsPanel"; | ||
|
||
jest.mock("../../utils/onboard.ts"); | ||
|
||
jest.mock("@didtools/cacao", () => ({ | ||
Cacao: { | ||
fromBlockBytes: jest.fn(), | ||
}, | ||
})); | ||
|
||
jest.mock("next/router", () => ({ | ||
useRouter: () => ({ | ||
query: { filter: "" }, | ||
}), | ||
})); | ||
|
||
const mockUserContext: UserContextState = makeTestUserContext(); | ||
const mockCeramicContext: CeramicContextState = makeTestCeramicContext(); | ||
|
||
describe("<ExpiredStampsPanel />", () => { | ||
it("renders the text informing use he does not have any expired stamps", () => { | ||
console.log("mockCeramicContext", mockCeramicContext); | ||
renderWithContext(mockUserContext, mockCeramicContext, <ExpiredStampsPanel className="col-span-full" />); | ||
expect(screen.queryByText("Expired Stamps")).toBeInTheDocument(); | ||
expect(screen.queryByText("Reverify stamps")).not.toBeInTheDocument(); | ||
expect(screen.queryByAltText("Platform Icon")).not.toBeInTheDocument(); | ||
expect(screen.queryByText("You don't have any expired stamps")).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders the button to re-verify expired stamps, when there are expired stamps", () => { | ||
console.log("mockCeramicContext", mockCeramicContext); | ||
renderWithContext( | ||
mockUserContext, | ||
makeTestCeramicContextWithExpiredStamps(), | ||
<ExpiredStampsPanel className="col-span-full" /> | ||
); | ||
expect(screen.queryByText("Expired Stamps")).toBeInTheDocument(); | ||
expect(screen.queryByText("Reverify stamps")).toBeInTheDocument(); | ||
expect(screen.queryByAltText("Platform Icon")).toBeInTheDocument(); | ||
expect(screen.queryByText("You don't have any expired stamps")).not.toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
import { render, waitFor, screen, fireEvent } from "@testing-library/react"; | ||
import { useContext } from "react"; | ||
import { | ||
makeTestCeramicContext, | ||
makeTestClaimingContext, | ||
makeTestUserContext, | ||
} from "../../__test-fixtures__/contextTestHelpers"; | ||
|
||
import { UserContext } from "../../context/userContext"; | ||
import { CeramicContext, platforms } from "../../context/ceramicContext"; | ||
import { StampClaimingContext, StampClaimingContextProvider } from "../../context/stampClaimingContext"; | ||
import { fetchVerifiableCredential } from "@gitcoin/passport-identity/dist/commonjs/src/credentials"; | ||
|
||
import { PLATFORM_ID } from "@gitcoin/passport-types"; | ||
import { PlatformProps } from "../../components/GenericPlatform"; | ||
import { AppContext, PlatformClass, ProviderPayload } from "@gitcoin/passport-platforms"; | ||
|
||
jest.mock("../../utils/helpers", () => ({ | ||
generateUID: jest.fn((length: number) => "some random string"), | ||
})); | ||
|
||
jest.mock("@gitcoin/passport-identity/dist/commonjs/src/credentials", () => ({ | ||
fetchVerifiableCredential: jest.fn(), | ||
})); | ||
|
||
jest.mock("../../utils/onboard.ts"); | ||
|
||
jest.mock("../../context/ceramicContext", () => { | ||
const originalModule = jest.requireActual("../../context/ceramicContext"); | ||
let newPlatforms = new Map<PLATFORM_ID, PlatformProps>(); | ||
|
||
originalModule.platforms.forEach((value: PlatformProps, key: PLATFORM_ID) => { | ||
let platform: PlatformClass = { | ||
...value.platform, | ||
getProviderPayload: jest.fn(async (appContext: AppContext) => { | ||
return {}; | ||
}), | ||
getOAuthUrl: jest.fn(async (state, providers) => { | ||
return ""; | ||
}), | ||
}; | ||
let newValue: PlatformProps = { ...value }; | ||
|
||
platform.getProviderPayload = jest.fn(async (appContext: AppContext) => { | ||
return {}; | ||
}); | ||
|
||
newValue.platform = platform; | ||
newPlatforms.set(key, newValue); | ||
}); | ||
|
||
return { | ||
__esModule: true, | ||
...originalModule, | ||
platforms: newPlatforms, | ||
}; | ||
}); | ||
|
||
const TestingComponent = () => { | ||
const { claimCredentials } = useContext(StampClaimingContext); | ||
|
||
return ( | ||
<div> | ||
<button | ||
data-testid="claim-button" | ||
onClick={() => { | ||
claimCredentials([ | ||
{ | ||
platformId: "Google", | ||
selectedProviders: ["Google"], | ||
}, | ||
{ | ||
platformId: "Gitcoin", | ||
selectedProviders: ["GitcoinContributorStatistics#numGrantsContributeToGte#1"], | ||
}, | ||
]); | ||
}} | ||
> | ||
Claim | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
const TestingComponentWithEvmStamp = () => { | ||
const { claimCredentials } = useContext(StampClaimingContext); | ||
|
||
return ( | ||
<div> | ||
<button | ||
data-testid="claim-button" | ||
onClick={() => { | ||
claimCredentials([ | ||
{ | ||
platformId: "Google", | ||
selectedProviders: ["Google"], | ||
}, | ||
{ | ||
platformId: "Gitcoin", | ||
selectedProviders: ["GitcoinContributorStatistics#numGrantsContributeToGte#1"], | ||
}, | ||
{ | ||
platformId: "EVMBulkVerify", | ||
selectedProviders: ["ethPossessionsGte#32"], | ||
}, | ||
]); | ||
}} | ||
> | ||
Claim | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
const mockCeramicContext = makeTestCeramicContext({ | ||
passport: { | ||
issuanceDate: new Date(), | ||
expiryDate: new Date(), | ||
stamps: [], | ||
}, | ||
}); | ||
|
||
const mockStampClaimingContext = makeTestClaimingContext({}); | ||
|
||
const mockTestUserContext = makeTestUserContext({}); | ||
|
||
describe("<StampClaimingContext>", () => { | ||
const renderTestComponent = () => | ||
render( | ||
<UserContext.Provider value={mockTestUserContext}> | ||
<CeramicContext.Provider value={mockCeramicContext}> | ||
<StampClaimingContextProvider> | ||
<TestingComponent /> | ||
</StampClaimingContextProvider> | ||
</CeramicContext.Provider> | ||
</UserContext.Provider> | ||
); | ||
|
||
const renderTestComponentWithEvmStamp = () => | ||
render( | ||
<UserContext.Provider value={mockTestUserContext}> | ||
<CeramicContext.Provider value={mockCeramicContext}> | ||
<StampClaimingContextProvider> | ||
<TestingComponentWithEvmStamp /> | ||
</StampClaimingContextProvider> | ||
</CeramicContext.Provider> | ||
</UserContext.Provider> | ||
); | ||
|
||
beforeEach(() => { | ||
(fetchVerifiableCredential as jest.Mock).mockImplementation(() => { | ||
return { credentials: [] }; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should fetch all credentials specified when calling claimCredentials (non-EVM only)", async () => { | ||
renderTestComponent(); | ||
|
||
// Click the claim button, which should call the `claimCredentials` function in the context | ||
await waitFor(async () => { | ||
const claimButton = screen.getByTestId("claim-button"); | ||
await fireEvent.click(claimButton); | ||
}); | ||
|
||
// Verify that the `fetchVerifiableCredential` function has been called | ||
// Expect 1 call for each platform in the array | ||
expect(fetchVerifiableCredential).toHaveBeenCalledTimes(2); | ||
|
||
// Verify that the `handlePatchStamps` function has been called for the ceramic context | ||
expect(mockCeramicContext.handlePatchStamps).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
it("should fetch all credentials specified when calling claimCredentials (evm credentials included)", async () => { | ||
renderTestComponentWithEvmStamp(); | ||
|
||
// Click the claim button, which should call the `claimCredentials` function in the context | ||
await waitFor(async () => { | ||
const claimButton = screen.getByTestId("claim-button"); | ||
await fireEvent.click(claimButton); | ||
}); | ||
|
||
// Verify that the `fetchVerifiableCredential` function has been called | ||
// Expect 1 call for each platform in the array | ||
expect(fetchVerifiableCredential).toHaveBeenCalledTimes(3); | ||
|
||
// Verify that the `handlePatchStamps` function has been called for the ceramic context | ||
expect(mockCeramicContext.handlePatchStamps).toHaveBeenCalledTimes(3); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.