From 52cce8bbf839ce1e91033b4514974667a76493d7 Mon Sep 17 00:00:00 2001 From: Pablo Costa Date: Mon, 6 Nov 2023 20:11:47 -0300 Subject: [PATCH 1/6] Add onResendConfirmationClick function on the toast message --- .../userContext/UserContextProvider.js | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/site/gatsby-site/src/contexts/userContext/UserContextProvider.js b/site/gatsby-site/src/contexts/userContext/UserContextProvider.js index b514875dda..9973d63804 100644 --- a/site/gatsby-site/src/contexts/userContext/UserContextProvider.js +++ b/site/gatsby-site/src/contexts/userContext/UserContextProvider.js @@ -6,9 +6,10 @@ import { ApolloProvider, ApolloClient, HttpLink, InMemoryCache } from '@apollo/c import config from '../../../config'; import fetch from 'cross-fetch'; import useToastContext, { SEVERITY } from '../../hooks/useToast'; -import { useTranslation } from 'react-i18next'; +import { Trans, useTranslation } from 'react-i18next'; import { navigate } from 'gatsby'; import useLocalizePath from '../../components/i18n/useLocalizePath'; +import CustomButton from '../../elements/Button'; // https://github.com/mongodb-university/realm-graphql-apollo-react/blob/master/src/index.js @@ -98,7 +99,17 @@ export const UserContextProvider = ({ children }) => { addToast({ message: ( - + <> + + onResendConfirmationClick(email)} + className="underline text-sm pl-0 border-0" + > + Resend Verification email + + ), severity: SEVERITY.danger, error: e, @@ -107,6 +118,25 @@ export const UserContextProvider = ({ children }) => { } }; + const onResendConfirmationClick = async (email) => { + try { + await realmApp.emailPasswordAuth.retryCustomConfirmation(email); + + addToast({ + message: `${t('Verification email sent to')} ${email}`, + severity: SEVERITY.success, + }); + } catch (e) { + addToast({ + message: ( + + ), + severity: SEVERITY.danger, + error: e, + }); + } + }; + const loginWithEmail = async ({ email, password, redirectTo }) => { return await login({ email, password, redirectTo }); }; From 0df72093db6554c07829bcda430d7e54ca8da9a7 Mon Sep 17 00:00:00 2001 From: Pablo Costa Date: Tue, 7 Nov 2023 14:35:46 -0300 Subject: [PATCH 2/6] Display resend option only on 'confirmation required' error --- .../userContext/UserContextProvider.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/site/gatsby-site/src/contexts/userContext/UserContextProvider.js b/site/gatsby-site/src/contexts/userContext/UserContextProvider.js index 9973d63804..02d6e53cc1 100644 --- a/site/gatsby-site/src/contexts/userContext/UserContextProvider.js +++ b/site/gatsby-site/src/contexts/userContext/UserContextProvider.js @@ -101,14 +101,16 @@ export const UserContextProvider = ({ children }) => { message: ( <> - onResendConfirmationClick(email)} - className="underline text-sm pl-0 border-0" - > - Resend Verification email - + {e.statusCode === 401 && e.error == 'confirmation required' && ( + onResendConfirmationClick(email)} + className="underline text-sm pl-0 border-0" + > + Resend Verification email + + )} ), severity: SEVERITY.danger, From 564f492cb60e2b1d89f7ee9500ce20a9500a938e Mon Sep 17 00:00:00 2001 From: Pablo Costa Date: Tue, 7 Nov 2023 14:36:03 -0300 Subject: [PATCH 3/6] Add tests to the confirmation email --- .../cypress/e2e/integration/login.cy.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/site/gatsby-site/cypress/e2e/integration/login.cy.js b/site/gatsby-site/cypress/e2e/integration/login.cy.js index 7d592170ad..ba310e60d6 100644 --- a/site/gatsby-site/cypress/e2e/integration/login.cy.js +++ b/site/gatsby-site/cypress/e2e/integration/login.cy.js @@ -84,4 +84,45 @@ describe('Login', () => { cy.contains('Forgot password?').click(); cy.location('pathname').should('eq', '/forgotpassword/'); }); + + it('Should give the option to resend Email verification if the user is not confirmed', () => { + cy.conditionalIntercept( + '**/login', + (req) => req.body.username == Cypress.env('e2eUsername'), + 'Login', + { + statusCode: 401, + body: { + error: 'confirmation required', + error_code: 'AuthError', + link: 'https://realm.mongodb.com/groups/633205e6aecbcc4b2c2067c3/apps/633207f10d438f13ab3ab4d6/logs?co_id=6549772172bdb9e8eadeea95', + }, + } + ); + + cy.conditionalIntercept( + '**/auth/providers/local-userpass/confirm/call', + (req) => req.body.email == Cypress.env('e2eUsername'), + 'Confirmation', + { + statusCode: 204, + } + ); + + cy.visit(url); + cy.get('input[name=email]').type(Cypress.env('e2eUsername')); + cy.get('input[name=password]').type(Cypress.env('e2ePassword')); + cy.get('[data-cy="login-btn"]').click(); + + cy.wait('@Login'); + + cy.get('[data-cy="toast"]').contains('Resend Verification email').should('exist'); + cy.get('[data-cy="toast"]').contains('Resend Verification email').click(); + + cy.wait('@Confirmation'); + + cy.get('[data-cy="toast"]') + .contains(`Verification email sent to ${Cypress.env('e2eUsername')}`) + .should('exist'); + }); }); From b7138022e470f12ca5eee752d8f6016af7648165 Mon Sep 17 00:00:00 2001 From: Pablo Costa Date: Wed, 8 Nov 2023 15:43:02 -0300 Subject: [PATCH 4/6] Move discover.cy.js file to test --- .../cypress/e2e/{integration => }/discover.cy.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename site/gatsby-site/cypress/e2e/{integration => }/discover.cy.js (98%) diff --git a/site/gatsby-site/cypress/e2e/integration/discover.cy.js b/site/gatsby-site/cypress/e2e/discover.cy.js similarity index 98% rename from site/gatsby-site/cypress/e2e/integration/discover.cy.js rename to site/gatsby-site/cypress/e2e/discover.cy.js index 65e8a04535..4d82149e7a 100644 --- a/site/gatsby-site/cypress/e2e/integration/discover.cy.js +++ b/site/gatsby-site/cypress/e2e/discover.cy.js @@ -1,10 +1,10 @@ -import flaggedReport from '../../fixtures/reports/flagged.json'; -import unflaggedReport from '../../fixtures/reports/unflagged.json'; -import config from '../../../config'; +import flaggedReport from '../fixtures/reports/flagged.json'; +import unflaggedReport from '../fixtures/reports/unflagged.json'; +import config from '../../config'; import path from 'path'; import { format, getUnixTime } from 'date-fns'; -import { deleteReportTypenames, transformReportData } from '../../../src/utils/reports'; -import { conditionalIt } from '../../support/utils'; +import { deleteReportTypenames, transformReportData } from '../../src/utils/reports'; +import { conditionalIt } from '../support/utils'; describe('The Discover app', () => { const url = '/apps/discover'; From 221f035ec40fda9e1c40f6d0b43758edf712eb1e Mon Sep 17 00:00:00 2001 From: Pablo Costa Date: Wed, 8 Nov 2023 17:04:17 -0300 Subject: [PATCH 5/6] Revert "Move discover.cy.js file to test" This reverts commit b7138022e470f12ca5eee752d8f6016af7648165. --- .../cypress/e2e/{ => integration}/discover.cy.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename site/gatsby-site/cypress/e2e/{ => integration}/discover.cy.js (98%) diff --git a/site/gatsby-site/cypress/e2e/discover.cy.js b/site/gatsby-site/cypress/e2e/integration/discover.cy.js similarity index 98% rename from site/gatsby-site/cypress/e2e/discover.cy.js rename to site/gatsby-site/cypress/e2e/integration/discover.cy.js index 4d82149e7a..65e8a04535 100644 --- a/site/gatsby-site/cypress/e2e/discover.cy.js +++ b/site/gatsby-site/cypress/e2e/integration/discover.cy.js @@ -1,10 +1,10 @@ -import flaggedReport from '../fixtures/reports/flagged.json'; -import unflaggedReport from '../fixtures/reports/unflagged.json'; -import config from '../../config'; +import flaggedReport from '../../fixtures/reports/flagged.json'; +import unflaggedReport from '../../fixtures/reports/unflagged.json'; +import config from '../../../config'; import path from 'path'; import { format, getUnixTime } from 'date-fns'; -import { deleteReportTypenames, transformReportData } from '../../src/utils/reports'; -import { conditionalIt } from '../support/utils'; +import { deleteReportTypenames, transformReportData } from '../../../src/utils/reports'; +import { conditionalIt } from '../../support/utils'; describe('The Discover app', () => { const url = '/apps/discover'; From 39e69dc02ccbbc978bc231b6237eb637895aab1e Mon Sep 17 00:00:00 2001 From: Pablo Costa Date: Thu, 9 Nov 2023 16:37:54 -0300 Subject: [PATCH 6/6] Improve flakiness on discover test --- site/gatsby-site/cypress/e2e/integration/discover.cy.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/site/gatsby-site/cypress/e2e/integration/discover.cy.js b/site/gatsby-site/cypress/e2e/integration/discover.cy.js index d5faa2adbf..b949b58e1a 100644 --- a/site/gatsby-site/cypress/e2e/integration/discover.cy.js +++ b/site/gatsby-site/cypress/e2e/integration/discover.cy.js @@ -35,6 +35,8 @@ describe('The Discover app', () => { () => { cy.visit(url); + cy.waitForStableDOM(); + cy.location('search', { timeout: 8000 }).should('contain', 'is_incident_report=true'); cy.waitForStableDOM();