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!
TypeScript agent-skillsaidsh-pluginhacktoberfestjavascriptmcp-serverreactresume-builderself-hostedtypescript
Firebase Stub refactoring
gianantoniopini69f0338b1925
diff --git a/__mocks__/__tests__/gatsby-plugin-firebase.test.js b/__mocks__/__tests__/gatsby-plugin-firebase.test.jsindex 9094c01ad..0979ab6d0 100644--- a/__mocks__/__tests__/gatsby-plugin-firebase.test.js+++ b/__mocks__/__tests__/gatsby-plugin-firebase.test.js@@ -4,10 +4,6 @@ import FirebaseStub, {} from '../gatsby-plugin-firebase';describe('FirebaseStub', () => {- const { resumesPath } = FirebaseStub.database();- const { usersPath } = FirebaseStub.database();- const { connectedPath } = FirebaseStub.database();-describe('auth', () => {afterEach(() => {FirebaseStub.auth().dispose();@@ -74,8 +70,12 @@ describe('FirebaseStub', () => {});it('reuses existing Reference instance', () => {- const ref1 = FirebaseStub.database().ref(`${resumesPath}/123`);- const ref2 = FirebaseStub.database().ref(`${resumesPath}/123`);+ const ref1 = FirebaseStub.database().ref(+ `${DatabaseConstants.resumesPath}/123`,+ );+ const ref2 = FirebaseStub.database().ref(+ `${DatabaseConstants.resumesPath}/123`,+ );expect(ref1.uuid).toBeTruthy();expect(ref2.uuid).toBeTruthy();@@ -91,7 +91,7 @@ describe('FirebaseStub', () => {});it("can spy on Reference 'update' function", async () => {- const referencePath = `${resumesPath}/123456`;+ const referencePath = `${DatabaseConstants.resumesPath}/123456`;const functionSpy = jest.spyOn(FirebaseStub.database().ref(referencePath),'update',@@ -109,7 +109,9 @@ describe('FirebaseStub', () => {it('initializing data sets up resumes and users', async () => {FirebaseStub.database().initializeData();- const resumesRef = FirebaseStub.database().ref(resumesPath);+ const resumesRef = FirebaseStub.database().ref(+ DatabaseConstants.resumesPath,+ );const resumesDataSnapshot = await resumesRef.once('value');const resumes = resumesDataSnapshot.val();expect(resumes).toBeTruthy();@@ -136,7 +138,7 @@ describe('FirebaseStub', () => {FirebaseStub.database().anonymousUser1.uid,);- const usersRef = FirebaseStub.database().ref(usersPath);+ const usersRef = FirebaseStub.database().ref(DatabaseConstants.usersPath);const usersDataSnapshot = await usersRef.once('value');const users = usersDataSnapshot.val();expect(users).toBeTruthy();@@ -154,7 +156,9 @@ describe('FirebaseStub', () => {const resume = (await FirebaseStub.database()- .ref(`${resumesPath}/${DatabaseConstants.demoStateResume1Id}`)+ .ref(+ `${DatabaseConstants.resumesPath}/${DatabaseConstants.demoStateResume1Id}`,+ ).once('value')).val();@@ -168,7 +172,7 @@ describe('FirebaseStub', () => {const resume = (await FirebaseStub.database()- .ref(`${resumesPath}/${resumeId}`)+ .ref(`${DatabaseConstants.resumesPath}/${resumeId}`).once('value')).val();@@ -180,7 +184,11 @@ describe('FirebaseStub', () => {const user = (await FirebaseStub.database()- .ref(`${usersPath}/${FirebaseStub.database().anonymousUser1.uid}`)+ .ref(+ `${DatabaseConstants.usersPath}/${+ FirebaseStub.database().anonymousUser1.uid+ }`,+ ).once('value')).val();@@ -194,7 +202,7 @@ describe('FirebaseStub', () => {const user = (await FirebaseStub.database()- .ref(`${usersPath}/${userId}`)+ .ref(`${DatabaseConstants.usersPath}/${userId}`).once('value')).val();@@ -205,7 +213,7 @@ describe('FirebaseStub', () => {let snapshotValue = null;FirebaseStub.database()- .ref(connectedPath)+ .ref(DatabaseConstants.connectedPath).on('value', (snapshot) => {snapshotValue = snapshot.val();});@@ -215,13 +223,13 @@ describe('FirebaseStub', () => {it('triggers callback with resumes when listening for data changes on the resumes reference path', async () => {const resumesDataSnapshot = await FirebaseStub.database()- .ref(resumesPath)+ .ref(DatabaseConstants.resumesPath).once('value');const resumes = resumesDataSnapshot.val();let snapshotValue = null;FirebaseStub.database()- .ref(resumesPath)+ .ref(DatabaseConstants.resumesPath).on('value', (snapshot) => {snapshotValue = snapshot.val();});@@ -233,7 +241,7 @@ describe('FirebaseStub', () => {let snapshotValue = null;FirebaseStub.database()- .ref(resumesPath)+ .ref(DatabaseConstants.resumesPath).orderByChild('user').equalTo(FirebaseStub.database().anonymousUser1.uid).on('value', (snapshot) => {diff --git a/__mocks__/gatsby-plugin-firebase.js b/__mocks__/gatsby-plugin-firebase.jsindex 8494e4859..3278a857d 100644--- a/__mocks__/gatsby-plugin-firebase.js+++ b/__mocks__/gatsby-plugin-firebase.js@@ -79,18 +79,6 @@ class Database {};}- get resumesPath() {- return Reference.resumesPath;- }-- get usersPath() {- return Reference.usersPath;- }-- get connectedPath() {- return Reference.connectedPath;- }-get anonymousUser1() {return this.#anonymousUser1;}@@ -140,12 +128,12 @@ class Database {resume.name = `Test Resume ${key}`;}- this.#data[this.resumesPath] = resumes;+ this.#data[DatabaseConstants.resumesPath] = resumes;const users = {};users[this.anonymousUser1.uid] = this.anonymousUser1;users[this.anonymousUser2.uid] = this.anonymousUser2;- this.#data[this.usersPath] = users;+ this.#data[DatabaseConstants.usersPath] = users;}ref(path) {@@ -161,9 +149,6 @@ class Database {}class Reference {- static resumesPath = 'resumes';- static usersPath = 'users';- static connectedPath = '/.info/connected';#rootPath = '.';#path = '';#uuid = '';@@ -211,8 +196,8 @@ class Reference {let data = null;if (- this.#path === Reference.resumesPath ||- this.#path === Reference.usersPath+ this.#path === DatabaseConstants.resumesPath ||+ this.#path === DatabaseConstants.usersPath) {data = this.#path in databaseData ? databaseData[this.#path] : null;@@ -229,8 +214,8 @@ class Reference {}if (- this.#path.startsWith(`${Reference.resumesPath}/`) ||- this.#path.startsWith(`${Reference.usersPath}/`)+ this.#path.startsWith(`${DatabaseConstants.resumesPath}/`) ||+ this.#path.startsWith(`${DatabaseConstants.usersPath}/`)) {const databaseLocationId = this.#path.substring(this.#path.indexOf('/') + 1,@@ -259,9 +244,9 @@ class Reference {let snapshot = new DataSnapshot(eventType, this, null);- if (this.#path === Reference.connectedPath) {+ if (this.#path === DatabaseConstants.connectedPath) {snapshot = new DataSnapshot(eventType, this, true);- } else if (this.#path === Reference.resumesPath) {+ } else if (this.#path === DatabaseConstants.resumesPath) {snapshot = new DataSnapshot(eventType, this);}diff --git a/__mocks__/gatsby-plugin-firebase/constants/database.js b/__mocks__/gatsby-plugin-firebase/constants/database.jsindex edcb65ec5..57e1e8c35 100644--- a/__mocks__/gatsby-plugin-firebase/constants/database.js+++ b/__mocks__/gatsby-plugin-firebase/constants/database.js@@ -1,8 +1,23 @@+const resumesPath = 'resumes';+const usersPath = 'users';+const connectedPath = '/.info/connected';const demoStateResume1Id = 'demo_1';const demoStateResume2Id = 'demo_2';const initialStateResumeId = 'initst';class Database {+ static get resumesPath() {+ return resumesPath;+ }++ static get usersPath() {+ return usersPath;+ }++ static get connectedPath() {+ return connectedPath;+ }+static get demoStateResume1Id() {return demoStateResume1Id;}diff --git a/src/pages/app/__tests__/builder.test.js b/src/pages/app/__tests__/builder.test.jsindex 45f0f619c..ef96a1d43 100644--- a/src/pages/app/__tests__/builder.test.js+++ b/src/pages/app/__tests__/builder.test.js@@ -25,7 +25,6 @@ beforeEach(() => {});describe('Builder', () => {- const { resumesPath } = FirebaseStub.database();let resumeId = null;let resume = null;let mockUpdateFunction = null;@@ -34,11 +33,13 @@ describe('Builder', () => {resumeId = DatabaseConstants.demoStateResume1Id;resume = (await FirebaseStub.database()- .ref(`${resumesPath}/${resumeId}`)+ .ref(`${DatabaseConstants.resumesPath}/${resumeId}`).once('value')).val();mockUpdateFunction = jest.spyOn(- FirebaseStub.database().ref(`${resumesPath}/${resumeId}`),+ FirebaseStub.database().ref(+ `${DatabaseConstants.resumesPath}/${resumeId}`,+ ),'update',);diff --git a/src/pages/app/__tests__/dashboard.test.js b/src/pages/app/__tests__/dashboard.test.jsindex fe4c5490d..c65060a22 100644--- a/src/pages/app/__tests__/dashboard.test.js+++ b/src/pages/app/__tests__/dashboard.test.js@@ -1,7 +1,7 @@import React from 'react';import { act, render, screen } from '@testing-library/react';-import FirebaseStub from 'gatsby-plugin-firebase';+import FirebaseStub, { DatabaseConstants } from 'gatsby-plugin-firebase';import '../../../i18n/index';import { SettingsProvider } from '../../../contexts/SettingsContext';@@ -17,14 +17,13 @@ beforeEach(() => {});describe('Dashboard', () => {- const { resumesPath } = FirebaseStub.database();let resumes = null;const user = FirebaseStub.database().anonymousUser1;beforeEach(async () => {resumes = (await FirebaseStub.database()- .ref(resumesPath)+ .ref(DatabaseConstants.resumesPath).orderByChild('user').equalTo(user.uid).once('value')diff --git a/src/templates/__tests__/Castform.test.js b/src/templates/__tests__/Castform.test.jsindex 53327b444..1b199609e 100644--- a/src/templates/__tests__/Castform.test.js+++ b/src/templates/__tests__/Castform.test.js@@ -10,11 +10,10 @@ describe('Castform', () => {beforeEach(async () => {FirebaseStub.database().initializeData();- const { resumesPath } = FirebaseStub.database();const resumeId = DatabaseConstants.initialStateResumeId;resume = (await FirebaseStub.database()- .ref(`${resumesPath}/${resumeId}`)+ .ref(`${DatabaseConstants.resumesPath}/${resumeId}`).once('value')).val();});