Skip to content

Commit

Permalink
fix(app): adds additional state for data point re-verififications
Browse files Browse the repository at this point in the history
  • Loading branch information
aminah-io authored and nutrina committed Nov 25, 2022
1 parent 8c18162 commit 05322cc
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
48 changes: 46 additions & 2 deletions app/__tests__/components/GenericPlatform.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jest.mock("@gitcoin/passport-identity/dist/commonjs/src/credentials", () => ({
fetchVerifiableCredential: jest.fn(),
}));
jest.mock("../../utils/onboard.ts");
const handleFetchCredential = jest.fn();

const mockHandleConnection = jest.fn();
const mockCreatePassport = jest.fn();
Expand All @@ -34,8 +35,6 @@ const mockUserContext: UserContextState = makeTestUserContext({
signer: mockSigner,
});

const handleFetchCredential = jest.fn();

const mockCeramicContext: CeramicContextState = makeTestCeramicContext({
handleCreatePassport: mockCreatePassport,
handleAddStamp: mockHandleAddStamp,
Expand Down Expand Up @@ -100,6 +99,51 @@ describe.skip("when user has not verified with EnsProvider", () => {
});
});

// describe("when user attempts to re-verify their passport data point(s)", () => {
// beforeEach(() => {
// (fetchVerifiableCredential as jest.Mock).mockResolvedValue({
// credentials: [SUCCESFUL_ENS_RESULTS],
// });
// });

// it("should show 'Success!' done toast message if user still qualifies for data point", async () => {
// const drawer = () => (
// <Drawer isOpen={true} placement="right" size="sm" onClose={() => {}}>
// <DrawerOverlay />
// <GenericPlatform platform={new Ens.EnsPlatform()} platFormGroupSpec={Ens.EnsProviderConfig} />
// </Drawer>
// );

// renderWithContext(mockUserContext, mockCeramicContext, drawer());

// screen.queryByTestId("select-all");
// screen.getByText("Verify").focus();
// fireEvent.keyDown(document.activeElement || document.body);
// // Add mock handleFetchCredential function (???)

// // Wait to see the done toast
// await waitFor(() => {
// expect(screen.getByText("Success!"));
// });

// const secondSwitch = screen.queryByTestId("switch-0");
// await fireEvent.click(secondSwitch as HTMLElement);
// await fireEvent.click(secondSwitch as HTMLElement);

// const saveButton = screen.queryByTestId("button-verify-Ens");

// await fireEvent.click(saveButton as HTMLElement);
// // Wait to see the done toast
// await waitFor(() => {
// expect(screen.getByTestId("toast-done-ens")).toBeInTheDocument();
// }, {timeout: 3000});
// });

// it("should show 'Verification Failure' done toast message if user no longer qualifies for data point", async () => {

// });
// });

// describe("when user does not successfully verify an EnsProvider", () => {
// beforeEach(() => {
// (fetchVerifiableCredential as jest.Mock).mockResolvedValue({
Expand Down
25 changes: 21 additions & 4 deletions app/components/GenericPlatform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,19 @@ export const GenericPlatform = ({ platFormGroupSpec, platform }: PlatformProps):

// Create Set to check changed providers after verification
const updatedVerifiedProviders = new Set(actualVerifiedProviders);
// Initial providers set minus updated providers set to determine which data points were removed
// Initial providers Set minus updated providers Set to determine which data points were removed
const initialMinusUpdated = difference(initialVerifiedProviders, updatedVerifiedProviders);
// Updated providers set minus initial providers set to determine which data points were added
// Updated providers Set minus initial providers Set to determine which data points were added
const updatedMinusInitial = difference(updatedVerifiedProviders, initialVerifiedProviders);
// reset can submit state
setCanSubmit(false);

// Get the done toast messages
const { title, body, icon, platformId } = getDoneToastMessages(initialMinusUpdated, updatedMinusInitial);
const { title, body, icon, platformId } = getDoneToastMessages(
updatedVerifiedProviders,
initialMinusUpdated,
updatedMinusInitial
);

// Display done toast
doneToast(title, body, icon, platformId);
Expand All @@ -270,14 +274,27 @@ export const GenericPlatform = ({ platFormGroupSpec, platform }: PlatformProps):
};

// Done toast message getter
const getDoneToastMessages = (initialMinusUpdated: Set<PROVIDER_ID>, updatedMinusInitial: Set<PROVIDER_ID>) => {
const getDoneToastMessages = (
updatedVerifiedProviders: Set<PROVIDER_ID>,
initialMinusUpdated: Set<PROVIDER_ID>,
updatedMinusInitial: Set<PROVIDER_ID>
) => {
if (updatedMinusInitial.size === providerIds.length) {
return {
title: "Done!",
body: `All ${platform.platformId} data points verified.`,
icon: checkIcon,
platformId: platform.platformId as PLATFORM_ID,
};
} else if (updatedVerifiedProviders.size > 0 && updatedMinusInitial.size === 0 && initialMinusUpdated.size === 0) {
return {
title: "Success!",
body: `Successfully re-verified ${platform.platformId} data ${
updatedVerifiedProviders.size > 1 ? "points" : "point"
}.`,
icon: checkIcon,
platformId: platform.platformId as PLATFORM_ID,
};
} else if (updatedMinusInitial.size > 0 && initialMinusUpdated.size === 0) {
return {
title: "Success!",
Expand Down
4 changes: 4 additions & 0 deletions platforms/src/Google/Providers/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export type GoogleUserInfo = {
verified_email?: boolean;
};

export type GoogleErr = {
response?: { status: string; statusText: string; data: { error: { message: string }; error_description: string } };
};

// Export a Google Provider to carry out OAuth and return a record object
export class GoogleProvider implements Provider {
// Give the provider a type so that we can select it with a payload
Expand Down

0 comments on commit 05322cc

Please sign in to comment.