Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

Delete Account unit tests: added tests related to Google reauthentication

gianantoniopini9e63d0b2c769
diff --git a/__mocks__/__tests__/gatsby-plugin-firebase/database.test.js b/__mocks__/__tests__/gatsby-plugin-firebase/database.test.js
index 8a97c0a94..e0f219af1 100644
--- a/__mocks__/__tests__/gatsby-plugin-firebase/database.test.js
+++ b/__mocks__/__tests__/gatsby-plugin-firebase/database.test.js
@@ -24,7 +24,7 @@ test('initializing data sets up resumes and users', async () => {
const resumesDataSnapshot = await resumesRef.once('value');
const resumes = resumesDataSnapshot.val();
expect(resumes).toBeTruthy();
- expect(Object.keys(resumes)).toHaveLength(3);
+ expect(Object.keys(resumes)).toHaveLength(5);
const demoStateResume1 = resumes[DatabaseConstants.demoStateResume1Id];
expect(demoStateResume1).toBeTruthy();
expect(demoStateResume1.id).toEqual(DatabaseConstants.demoStateResume1Id);
@@ -33,20 +33,35 @@ test('initializing data sets up resumes and users', async () => {
expect(demoStateResume2).toBeTruthy();
expect(demoStateResume2.id).toEqual(DatabaseConstants.demoStateResume2Id);
expect(demoStateResume2.user).toEqual(DatabaseConstants.user2.uid);
- const initialStateResume = resumes[DatabaseConstants.initialStateResumeId];
- expect(initialStateResume).toBeTruthy();
- expect(initialStateResume.id).toEqual(DatabaseConstants.initialStateResumeId);
- expect(initialStateResume.user).toEqual(DatabaseConstants.user1.uid);
+ const initialStateResume1 = resumes[DatabaseConstants.initialStateResume1Id];
+ expect(initialStateResume1).toBeTruthy();
+ expect(initialStateResume1.id).toEqual(
+ DatabaseConstants.initialStateResume1Id,
+ );
+ expect(initialStateResume1.user).toEqual(DatabaseConstants.user1.uid);
+ const demoStateResume3 = resumes[DatabaseConstants.demoStateResume3Id];
+ expect(demoStateResume3).toBeTruthy();
+ expect(demoStateResume3.id).toEqual(DatabaseConstants.demoStateResume3Id);
+ expect(demoStateResume3.user).toEqual(DatabaseConstants.user3.uid);
+ const initialStateResume2 = resumes[DatabaseConstants.initialStateResume2Id];
+ expect(initialStateResume2).toBeTruthy();
+ expect(initialStateResume2.id).toEqual(
+ DatabaseConstants.initialStateResume2Id,
+ );
+ expect(initialStateResume2.user).toEqual(DatabaseConstants.user3.uid);
const usersRef = FirebaseStub.database().ref(DatabaseConstants.usersPath);
const usersDataSnapshot = await usersRef.once('value');
const users = usersDataSnapshot.val();
expect(users).toBeTruthy();
- expect(Object.keys(users)).toHaveLength(2);
+ expect(Object.keys(users)).toHaveLength(3);
const anonymousUser1 = users[DatabaseConstants.user1.uid];
expect(anonymousUser1).toBeTruthy();
expect(anonymousUser1).toEqual(DatabaseConstants.user1);
const anonymousUser2 = users[DatabaseConstants.user2.uid];
expect(anonymousUser2).toBeTruthy();
expect(anonymousUser2).toEqual(DatabaseConstants.user2);
+ const googleUser3 = users[DatabaseConstants.user3.uid];
+ expect(googleUser3).toBeTruthy();
+ expect(googleUser3).toEqual(DatabaseConstants.user3);
});
diff --git a/__mocks__/gatsby-plugin-firebase.js b/__mocks__/gatsby-plugin-firebase.js
index 556b9917d..84340d70d 100644
--- a/__mocks__/gatsby-plugin-firebase.js
+++ b/__mocks__/gatsby-plugin-firebase.js
@@ -1,4 +1,5 @@
import Auth from './gatsby-plugin-firebase/auth/auth';
+import GoogleAuthProvider from './gatsby-plugin-firebase/auth/googleAuthProvider';
import Database from './gatsby-plugin-firebase/database/database';
import Functions from './gatsby-plugin-firebase/functions/functions';
import AuthConstants from './gatsby-plugin-firebase/constants/auth';
@@ -19,6 +20,8 @@ class FirebaseStub {
}
}
+FirebaseStub.auth.GoogleAuthProvider = GoogleAuthProvider;
+
FirebaseStub.database.ServerValue = {};
Object.defineProperty(FirebaseStub.database.ServerValue, 'TIMESTAMP', {
get() {
diff --git a/__mocks__/gatsby-plugin-firebase/auth/auth.js b/__mocks__/gatsby-plugin-firebase/auth/auth.js
index 1dc0db674..b8217a012 100644
--- a/__mocks__/gatsby-plugin-firebase/auth/auth.js
+++ b/__mocks__/gatsby-plugin-firebase/auth/auth.js
@@ -2,6 +2,8 @@
import { v4 as uuidv4 } from 'uuid';
import Constants from '../constants/auth';
+import AuthProvider from './authProvider';
+import GoogleAuthProvider from './googleAuthProvider';
import User from './user';
import { delay } from '../../../src/utils/index';
@@ -55,8 +57,47 @@ class Auth {
this._currentUser = new User(
user.displayName,
user.email,
+ user.providerId,
+ user.uid,
user.isAnonymous,
+ this.signOut,
+ );
+
+ await delay(Constants.defaultDelayInMilliseconds);
+
+ this.onAuthStateChangedObservers.forEach((observer) =>
+ observer(this._currentUser),
+ );
+
+ return this._currentUser;
+ }
+
+ /**
+ * Authenticates with popup.
+ *
+ * @param {AuthProvider} provider The provider to authenticate.
+ */
+ async signInWithPopup(provider) {
+ if (!provider) {
+ throw new Error('provider must be provided.');
+ } else if (!(provider instanceof AuthProvider)) {
+ throw new Error('provider should be an AuthProvider.');
+ }
+
+ if (!(provider instanceof GoogleAuthProvider)) {
+ throw new Error(
+ `${provider.constructor.name} is currently not supported.`,
+ );
+ }
+
+ const user = Constants.googleUser3;
+
+ this._currentUser = new User(
+ user.displayName,
+ user.email,
+ user.providerId,
user.uid,
+ user.isAnonymous,
this.signOut,
);
diff --git a/__mocks__/gatsby-plugin-firebase/auth/authProvider.js b/__mocks__/gatsby-plugin-firebase/auth/authProvider.js
new file mode 100644
index 000000000..e9b77a6cf
--- /dev/null
+++ b/__mocks__/gatsby-plugin-firebase/auth/authProvider.js
@@ -0,0 +1,23 @@
+/* eslint-disable no-underscore-dangle */
+class AuthProvider {
+ /**
+ * Creates a new auth provider.
+ *
+ * @param {string} providerId Provider ID.
+ */
+ constructor(providerId) {
+ if (!providerId) {
+ throw new Error('providerId must be provided.');
+ } else if (typeof providerId !== 'string') {
+ throw new Error('providerId should be a string.');
+ } else {
+ this._providerId = providerId;
+ }
+ }
+
+ get providerId() {
+ return this._providerId;
+ }
+}
+
+export default AuthProvider;
diff --git a/__mocks__/gatsby-plugin-firebase/auth/googleAuthProvider.js b/__mocks__/gatsby-plugin-firebase/auth/googleAuthProvider.js
new file mode 100644
index 000000000..f98ea3c66
--- /dev/null
+++ b/__mocks__/gatsby-plugin-firebase/auth/googleAuthProvider.js
@@ -0,0 +1,10 @@
+import AuthProvider from './authProvider';
+import Constants from '../constants/auth';
+
+class GoogleAuthProvider extends AuthProvider {
+ constructor() {
+ super(Constants.googleAuthProviderId);
+ }
+}
+
+export default GoogleAuthProvider;
diff --git a/__mocks__/gatsby-plugin-firebase/auth/user.js b/__mocks__/gatsby-plugin-firebase/auth/user.js
index 33f438459..05843cb47 100644
--- a/__mocks__/gatsby-plugin-firebase/auth/user.js
+++ b/__mocks__/gatsby-plugin-firebase/auth/user.js
@@ -1,25 +1,23 @@
/* eslint-disable no-underscore-dangle */
import Constants from '../constants/auth';
+// eslint-disable-next-line no-unused-vars
+import AuthProvider from './authProvider';
+import UserInfo from './userInfo';
import { delay } from '../../../src/utils/index';
-class User {
+class User extends UserInfo {
/**
* Creates a new user.
*
* @param {string|null} displayName Display name.
* @param {string|null} email Email.
- * @param {boolean} isAnonymous Is anonymous.
+ * @param {string} providerId Auth provider ID.
* @param {string} uid The user's unique ID.
+ * @param {boolean} isAnonymous Is anonymous.
* @param {function():Promise<void>} deleteUser Delete user callback.
*/
- constructor(displayName, email, isAnonymous, uid, deleteUser) {
- if (!uid) {
- throw new Error('uid must be provided.');
- } else if (typeof uid !== 'string') {
- throw new Error('uid should be a string.');
- } else {
- this._uid = uid;
- }
+ constructor(displayName, email, providerId, uid, isAnonymous, deleteUser) {
+ super(displayName, email, providerId, uid);
if (!deleteUser) {
throw new Error('deleteUser must be provided.');
@@ -29,25 +27,22 @@ class User {
this._deleteUser = deleteUser;
}
- this._displayName = displayName;
- this._email = email;
this._isAnonymous = isAnonymous;
- }
-
- get displayName() {
- return this._displayName;
- }
- get email() {
- return this._email;
+ this._providerData = [];
+ if (!isAnonymous) {
+ this._providerData.push(
+ new UserInfo(displayName, email, providerId, uid),
+ );
+ }
}
get isAnonymous() {
return this._isAnonymous;
}
- get uid() {
- return this._uid;
+ get providerData() {
+ return this._providerData;
}
async delete() {
@@ -55,6 +50,18 @@ class User {
await this._deleteUser();
}
+
+ /**
+ * Reauthenticates the user with popup.
+ *
+ * @param {AuthProvider} provider The provider to authenticate.
+ */
+ // eslint-disable-next-line no-unused-vars
+ async reauthenticateWithPopup(provider) {
+ await delay(Constants.defaultDelayInMilliseconds);
+
+ return this;
+ }
}
export default User;
diff --git a/__mocks__/gatsby-plugin-firebase/auth/userInfo.js b/__mocks__/gatsby-plugin-firebase/auth/userInfo.js
new file mode 100644
index 000000000..c648698de
--- /dev/null
+++ b/__mocks__/gatsby-plugin-firebase/auth/userInfo.js
@@ -0,0 +1,47 @@
+/* eslint-disable no-underscore-dangle */
+class UserInfo {
+ /**
+ * Creates a new user profile information.
+ *
+ * @param {string|null} displayName Display name.
+ * @param {string|null} email Email.
+ * @param {string} providerId Auth provider ID.
+ * @param {string} uid The user's unique ID.
+ */
+ constructor(displayName, email, providerId, uid) {
+ if (!uid) {
+ throw new Error('uid must be provided.');
+ } else if (typeof uid !== 'string') {
+ throw new Error('uid should be a string.');
+ } else {
+ this._uid = uid;
+ }
+
+ if (typeof providerId !== 'string') {
+ throw new Error('providerId should be a string.');
+ } else {
+ this._providerId = providerId;
+ }
+
+ this._displayName = displayName;
+ this._email = email;
+ }
+
+ get displayName() {
+ return this._displayName;
+ }
+
+ get email() {
+ return this._email;
+ }
+
+ get providerId() {
+ return this._providerId;
+ }
+
+ get uid() {
+ return this._uid;
+ }
+}
+
+export default UserInfo;
diff --git a/__mocks__/gatsby-plugin-firebase/constants/auth.js b/__mocks__/gatsby-plugin-firebase/constants/auth.js
index 685fba3f3..072d04a7d 100644
--- a/__mocks__/gatsby-plugin-firebase/constants/auth.js
+++ b/__mocks__/gatsby-plugin-firebase/constants/auth.js
@@ -1,20 +1,36 @@
+const googleAuthProviderId = 'google.com';
+
const anonymousUser1 = {
displayName: 'Anonymous User 1',
isAnonymous: true,
- uid: 'anonym123',
+ providerId: '',
+ uid: 'anonym1',
};
const anonymousUser2 = {
displayName: 'Anonymous User 2',
isAnonymous: true,
- uid: 'anonym456',
+ providerId: '',
+ uid: 'anonym2',
+};
+
+const googleUser3 = {
+ displayName: 'Google User 3',
+ email: '[email protected]',
+ isAnonymous: false,
+ providerId: googleAuthProviderId,
+ uid: 'google3',
};
const defaultDelayInMilliseconds = 100;
class Auth {
+ static get googleAuthProviderId() {
+ return googleAuthProviderId;
+ }
+
static get anonymousUser1() {
return anonymousUser1;
}
@@ -23,6 +39,10 @@ class Auth {
return anonymousUser2;
}
+ static get googleUser3() {
+ return googleUser3;
+ }
+
static get defaultDelayInMilliseconds() {
return defaultDelayInMilliseconds;
}
diff --git a/__mocks__/gatsby-plugin-firebase/constants/database.js b/__mocks__/gatsby-plugin-firebase/constants/database.js
index 62a5459e0..e4417175b 100644
--- a/__mocks__/gatsby-plugin-firebase/constants/database.js
+++ b/__mocks__/gatsby-plugin-firebase/constants/database.js
@@ -9,7 +9,9 @@ const connectedPath = '.info/connected';
const demoStateResume1Id = 'demo_1';
const demoStateResume2Id = 'demo_2';
-const initialStateResumeId = 'initst';
+const demoStateResume3Id = 'demo_3';
+const initialStateResume1Id = 'init_1';
+const initialStateResume2Id = 'init_2';
const user1 = {
uid: AuthConstants.anonymousUser1.uid,
@@ -19,6 +21,10 @@ const user2 = {
uid: AuthConstants.anonymousUser2.uid,
isAnonymous: AuthConstants.anonymousUser2.isAnonymous,
};
+const user3 = {
+ uid: AuthConstants.googleUser3.uid,
+ isAnonymous: AuthConstants.googleUser3.isAnonymous,
+};
const defaultDelayInMilliseconds = 100;
@@ -51,8 +57,16 @@ class Database {
return demoStateResume2Id;
}
- static get initialStateResumeId() {
- return initialStateResumeId;
+ static get demoStateResume3Id() {
+ return demoStateResume3Id;
+ }
+
+ static get initialStateResume1Id() {
+ return initialStateResume1Id;
+ }
+
+ static get initialStateResume2Id() {
+ return initialStateResume2Id;
}
static get user1() {
@@ -63,6 +77,10 @@ class Database {
return user2;
}
+ static get user3() {
+ return user3;
+ }
+
static get defaultDelayInMilliseconds() {
return defaultDelayInMilliseconds;
}
diff --git a/__mocks__/gatsby-plugin-firebase/database/database.js b/__mocks__/gatsby-plugin-firebase/database/database.js
index 69125d2d0..6df9ea5ab 100644
--- a/__mocks__/gatsby-plugin-firebase/database/database.js
+++ b/__mocks__/gatsby-plugin-firebase/database/database.js
@@ -101,9 +101,9 @@ class Database {
initializeData() {
const resumes = {};
+ const date = new Date('December 15, 2020 11:20:25');
const demoStateResume1 = readFile('../../../src/data/demoState.json');
- const date = new Date('December 15, 2020 11:20:25');
demoStateResume1.updatedAt = date.valueOf();
date.setMonth(date.getMonth() - 2);
demoStateResume1.createdAt = date.valueOf();
@@ -114,11 +114,24 @@ class Database {
demoStateResume2.user = DatabaseConstants.user2.uid;
resumes[DatabaseConstants.demoStateResume2Id] = demoStateResume2;
- const initialStateResume = readFile('../../../src/data/initialState.json');
- initialStateResume.updatedAt = date.valueOf();
- initialStateResume.createdAt = date.valueOf();
- initialStateResume.user = DatabaseConstants.user1.uid;
- resumes[DatabaseConstants.initialStateResumeId] = initialStateResume;
+ const initialStateResume1 = readFile('../../../src/data/initialState.json');
+ initialStateResume1.updatedAt = date.valueOf();
+ initialStateResume1.createdAt = date.valueOf();
+ initialStateResume1.user = DatabaseConstants.user1.uid;
+ resumes[DatabaseConstants.initialStateResume1Id] = initialStateResume1;
+
+ const demoStateResume3 = readFile('../../../src/data/demoState.json');
+ demoStateResume3.updatedAt = date.valueOf();
+ date.setMonth(date.getMonth() - 2);
+ demoStateResume3.createdAt = date.valueOf();
+ demoStateResume3.user = DatabaseConstants.user3.uid;
+ resumes[DatabaseConstants.demoStateResume3Id] = demoStateResume3;
+
+ const initialStateResume2 = readFile('../../../src/data/initialState.json');
+ initialStateResume2.updatedAt = date.valueOf();
+ initialStateResume2.createdAt = date.valueOf();
+ initialStateResume2.user = DatabaseConstants.user3.uid;
+ resumes[DatabaseConstants.initialStateResume2Id] = initialStateResume2;
Object.keys(resumes).forEach((key) => {
const resume = resumes[key];
@@ -131,6 +144,7 @@ class Database {
const users = {};
users[DatabaseConstants.user1.uid] = DatabaseConstants.user1;
users[DatabaseConstants.user2.uid] = DatabaseConstants.user2;
+ users[DatabaseConstants.user3.uid] = DatabaseConstants.user3;
this._data[DatabaseConstants.usersPath] = users;
}
diff --git a/src/pages/app/__tests__/builder.dataPersistence.test.js b/src/pages/app/__tests__/builder.dataPersistence.test.js
index 9f1fef644..26748c590 100644
--- a/src/pages/app/__tests__/builder.dataPersistence.test.js
+++ b/src/pages/app/__tests__/builder.dataPersistence.test.js
@@ -7,13 +7,14 @@ import {
expectDatabaseUpdateToHaveCompleted,
} from './helpers/builder';
-const testTimeoutInMilliseconds = 20000;
+const testTimeoutInMilliseconds = 30000;
jest.setTimeout(testTimeoutInMilliseconds);
test('when input value is changed, updates database', async () => {
const resumeId = DatabaseConstants.demoStateResume1Id;
const { mockDatabaseUpdateFunction } = await setupAndWait(
resumeId,
+ false,
true,
true,
);
diff --git a/src/pages/app/__tests__/builder.rendering.test.js b/src/pages/app/__tests__/builder.rendering.test.js
index 950296522..3a5e82bdb 100644
--- a/src/pages/app/__tests__/builder.rendering.test.js
+++ b/src/pages/app/__tests__/builder.rendering.test.js
@@ -20,6 +20,7 @@ jest.setTimeout(testTimeoutInMilliseconds);
test('renders first and last name', async () => {
const { resume } = await setupAndWait(
DatabaseConstants.demoStateResume1Id,
+ false,
true,
true,
);
@@ -53,7 +54,7 @@ test('renders loading screen', async () => {
});
test('if resume is in initial state, renders load demo data notification', async () => {
- await setup(DatabaseConstants.initialStateResumeId);
+ await setup(DatabaseConstants.initialStateResume1Id);
const notification = await screen.findByRole('alert');
expect(
diff --git a/src/pages/app/__tests__/builder.settings.deleteAccount.test.js b/src/pages/app/__tests__/builder.settings.deleteAccount.test.js
index 7c5f8f1dd..72bc54fe9 100644
--- a/src/pages/app/__tests__/builder.settings.deleteAccount.test.js
+++ b/src/pages/app/__tests__/builder.settings.deleteAccount.test.js
@@ -14,9 +14,32 @@ import { delay } from '../../../utils/index';
const testTimeoutInMilliseconds = 60000;
jest.setTimeout(testTimeoutInMilliseconds);
-async function setup() {
- const resumeId = DatabaseConstants.demoStateResume1Id;
- await setupAndWait(resumeId, true, true);
+async function setup(signInWithGoogle, failReauthentication) {
+ const resumeId = signInWithGoogle
+ ? DatabaseConstants.demoStateResume3Id
+ : DatabaseConstants.demoStateResume1Id;
+
+ await setupAndWait(resumeId, signInWithGoogle, true, true);
+
+ let mockFirebaseCurrentUserReauthenticateWithPopupErrorMessage;
+ let mockFirebaseCurrentUserReauthenticateWithPopup;
+ if (failReauthentication) {
+ mockFirebaseCurrentUserReauthenticateWithPopupErrorMessage =
+ 'Error occurred while reauthenticating.';
+ mockFirebaseCurrentUserReauthenticateWithPopup = jest.fn(async () => {
+ await delay(AuthConstants.defaultDelayInMilliseconds);
+ throw new Error(
+ mockFirebaseCurrentUserReauthenticateWithPopupErrorMessage,
+ );
+ });
+ FirebaseStub.auth().currentUser.reauthenticateWithPopup = mockFirebaseCurrentUserReauthenticateWithPopup;
+ } else {
+ mockFirebaseCurrentUserReauthenticateWithPopupErrorMessage = null;
+ mockFirebaseCurrentUserReauthenticateWithPopup = jest.spyOn(
+ FirebaseStub.auth().currentUser,
+ 'reauthenticateWithPopup',
+ );
+ }
const mockFirebaseDeleteUserCloudFunction = jest.fn(async () => {
await delay(FunctionsConstants.defaultDelayInMilliseconds);
@@ -61,6 +84,8 @@ async function setup() {
areYouSureButtonText,
deleteAccountButtonText,
waitForDeleteAccountButtonTextToChangeTo,
+ mockFirebaseCurrentUserReauthenticateWithPopup,
+ mockFirebaseCurrentUserReauthenticateWithPopupErrorMessage,
mockFirebaseDeleteUserCloudFunction,
mockFirebaseCurrentUserDelete,
mockFirebaseAuthSignOut,
@@ -78,7 +103,7 @@ test('prompts for confirmation', async () => {
mockFirebaseCurrentUserDelete,
mockFirebaseAuthSignOut,
mockToastError,
- } = await setup();
+ } = await setup(false, false);
fireEvent.click(deleteAccountButton);
@@ -98,7 +123,7 @@ test('calls Firebase delete user cloud function', async () => {
deleteAccountButtonText,
mockFirebaseDeleteUserCloudFunction,
waitForDeleteAccountButtonTextToChangeTo,
- } = await setup();
+ } = await setup(false, false);
fireEvent.click(deleteAccountButton);
fireEvent.click(deleteAccountButton);
@@ -116,7 +141,7 @@ test('calls Firebase current user delete', async () => {
deleteAccountButtonText,
mockFirebaseCurrentUserDelete,
waitForDeleteAccountButtonTextToChangeTo,
- } = await setup();
+ } = await setup(false, false);
fireEvent.click(deleteAccountButton);
fireEvent.click(deleteAccountButton);
@@ -134,7 +159,7 @@ test('calls Firebase auth sign out', async () => {
deleteAccountButtonText,
mockFirebaseAuthSignOut,
waitForDeleteAccountButtonTextToChangeTo,
- } = await setup();
+ } = await setup(false, false);
fireEvent.click(deleteAccountButton);
fireEvent.click(deleteAccountButton);
@@ -150,7 +175,7 @@ describe('if an error occurs while signing out the current user', () => {
deleteAccountButton,
deleteAccountButtonText,
waitForDeleteAccountButtonTextToChangeTo,
- } = await setup();
+ } = await setup(false, false);
fireEvent.click(deleteAccountButton);
fireEvent.click(deleteAccountButton);
@@ -167,7 +192,7 @@ describe('if an error occurs while signing out the current user', () => {
mockFirebaseAuthSignOutErrorMessage,
waitForDeleteAccountButtonTextToChangeTo,
mockToastError,
- } = await setup();
+ } = await setup(false, false);
fireEvent.click(deleteAccountButton);
fireEvent.click(deleteAccountButton);
@@ -185,3 +210,75 @@ describe('if an error occurs while signing out the current user', () => {
);
});
});
+
+describe('if the current user is signed in with Google', () => {
+ test('reauthenticates the user', async () => {
+ const googleAuthProvider = new FirebaseStub.auth.GoogleAuthProvider();
+ const {
+ deleteAccountButton,
+ deleteAccountButtonText,
+ mockFirebaseCurrentUserReauthenticateWithPopup,
+ waitForDeleteAccountButtonTextToChangeTo,
+ } = await setup(true, false);
+
+ fireEvent.click(deleteAccountButton);
+ fireEvent.click(deleteAccountButton);
+
+ await waitForDeleteAccountButtonTextToChangeTo(deleteAccountButtonText);
+
+ expect(
+ mockFirebaseCurrentUserReauthenticateWithPopup,
+ ).toHaveBeenCalledTimes(1);
+ expect(mockFirebaseCurrentUserReauthenticateWithPopup).toHaveBeenCalledWith(
+ googleAuthProvider,
+ );
+ });
+
+ describe('and reauthentication fails', () => {
+ test('does not proceed further', async () => {
+ const {
+ deleteAccountButton,
+ deleteAccountButtonText,
+ waitForDeleteAccountButtonTextToChangeTo,
+ mockFirebaseDeleteUserCloudFunction,
+ mockFirebaseCurrentUserDelete,
+ mockFirebaseAuthSignOut,
+ } = await setup(true, true);
+
+ fireEvent.click(deleteAccountButton);
+ fireEvent.click(deleteAccountButton);
+
+ await waitForDeleteAccountButtonTextToChangeTo(deleteAccountButtonText);
+
+ expect(mockFirebaseDeleteUserCloudFunction).not.toHaveBeenCalled();
+ expect(mockFirebaseCurrentUserDelete).not.toHaveBeenCalled();
+ expect(mockFirebaseAuthSignOut).not.toHaveBeenCalled();
+ expect(mockNavigateFunction).not.toHaveBeenCalled();
+ });
+
+ test('displays error notifications', async () => {
+ const {
+ deleteAccountButton,
+ deleteAccountButtonText,
+ waitForDeleteAccountButtonTextToChangeTo,
+ mockFirebaseCurrentUserReauthenticateWithPopupErrorMessage,
+ mockToastError,
+ } = await setup(true, true);
+
+ fireEvent.click(deleteAccountButton);
+ fireEvent.click(deleteAccountButton);
+
+ await waitForDeleteAccountButtonTextToChangeTo(deleteAccountButtonText);
+
+ expect(mockToastError).toHaveBeenCalledTimes(2);
+ expect(mockToastError).toHaveBeenNthCalledWith(
+ 1,
+ mockFirebaseCurrentUserReauthenticateWithPopupErrorMessage,
+ );
+ expect(mockToastError).toHaveBeenNthCalledWith(
+ 2,
+ 'An error occurred deleting your account.',
+ );
+ });
+ });
+});
diff --git a/src/pages/app/__tests__/builder.settings.test.js b/src/pages/app/__tests__/builder.settings.test.js
index 7db8a1c1a..6bb4e7a1d 100644
--- a/src/pages/app/__tests__/builder.settings.test.js
+++ b/src/pages/app/__tests__/builder.settings.test.js
@@ -16,6 +16,7 @@ test('allows to change the language', async () => {
const resumeId = DatabaseConstants.demoStateResume1Id;
const { mockDatabaseUpdateFunction } = await setupAndWait(
resumeId,
+ false,
true,
true,
);
diff --git a/src/pages/app/__tests__/builder.skills.test.js b/src/pages/app/__tests__/builder.skills.test.js
index 1677ac366..535b5284b 100644
--- a/src/pages/app/__tests__/builder.skills.test.js
+++ b/src/pages/app/__tests__/builder.skills.test.js
@@ -19,6 +19,7 @@ test('allows to drag & drop', async () => {
const resumeId = DatabaseConstants.demoStateResume1Id;
const { resume, mockDatabaseUpdateFunction } = await setupAndWait(
resumeId,
+ false,
true,
true,
);
diff --git a/src/pages/app/__tests__/dashboard.deleteResume.test.js b/src/pages/app/__tests__/dashboard.deleteResume.test.js
index 1b84ac1d5..d4561f3d3 100644
--- a/src/pages/app/__tests__/dashboard.deleteResume.test.js
+++ b/src/pages/app/__tests__/dashboard.deleteResume.test.js
@@ -44,7 +44,7 @@ async function setup() {
);
const resumeToDeleteId = resumeToDelete.id;
const [undeletedResume] = Object.values(userResumes).filter(
- (resume) => resume.id === DatabaseConstants.initialStateResumeId,
+ (resume) => resume.id === DatabaseConstants.initialStateResume1Id,
);
const mockDatabaseRemoveFunction = jest.spyOn(
diff --git a/src/pages/app/__tests__/helpers/builder.js b/src/pages/app/__tests__/helpers/builder.js
index e63c93468..e9cdf4db9 100644
--- a/src/pages/app/__tests__/helpers/builder.js
+++ b/src/pages/app/__tests__/helpers/builder.js
@@ -80,6 +80,7 @@ const dragAndDropListItem = (listItemElement, direction) => {
// eslint-disable-next-line no-underscore-dangle
async function _setup(
resumeId,
+ signInWithGoogle,
waitForLoadingScreenToDisappear,
waitForDatabaseUpdateToHaveCompleted,
) {
@@ -96,7 +97,12 @@ async function _setup(
'update',
);
- FirebaseStub.auth().signInAnonymously();
+ if (signInWithGoogle) {
+ const provider = new FirebaseStub.auth.GoogleAuthProvider();
+ FirebaseStub.auth().signInWithPopup(provider);
+ } else {
+ FirebaseStub.auth().signInAnonymously();
+ }
render(
<SettingsProvider>
@@ -132,17 +138,19 @@ async function _setup(
}
async function setup(resumeId) {
- const returnValue = await _setup(resumeId, false, false);
+ const returnValue = await _setup(resumeId, false, false, false);
return returnValue;
}
async function setupAndWait(
resumeId,
+ signInWithGoogle,
waitForLoadingScreenToDisappear,
waitForDatabaseUpdateToHaveCompleted,
) {
const returnValue = await _setup(
resumeId,
+ signInWithGoogle,
waitForLoadingScreenToDisappear,
waitForDatabaseUpdateToHaveCompleted,
);
diff --git a/src/templates/__tests__/Castform.test.js b/src/templates/__tests__/Castform.test.js
index 51cc84c0e..026636c88 100644
--- a/src/templates/__tests__/Castform.test.js
+++ b/src/templates/__tests__/Castform.test.js
@@ -21,7 +21,7 @@ async function setup(resumeId) {
}
test('renders correctly', async () => {
- const resume = await setup(DatabaseConstants.initialStateResumeId);
+ const resume = await setup(DatabaseConstants.initialStateResume1Id);
const { container } = render(<Castform data={resume} />);
@@ -30,7 +30,7 @@ test('renders correctly', async () => {
});
test('date of birth is not shown if not provided', async () => {
- const resume = await setup(DatabaseConstants.initialStateResumeId);
+ const resume = await setup(DatabaseConstants.initialStateResume1Id);
render(<Castform data={resume} />);
@@ -38,7 +38,7 @@ test('date of birth is not shown if not provided', async () => {
});
test('date of birth is shown if provided', async () => {
- const resume = await setup(DatabaseConstants.initialStateResumeId);
+ const resume = await setup(DatabaseConstants.initialStateResume1Id);
const birthDate = new Date(1990, 0, 20);
const birthDateFormatted = '20 January 1990';