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!

Firebase Stub: resolving ESLint errors

gianantoniopinidce5d2c59100
diff --git a/__mocks__/gatsby-plugin-firebase/database/dataSnapshot.js b/__mocks__/gatsby-plugin-firebase/database/dataSnapshot.js
index c8069fe59..255bad24c 100644
--- a/__mocks__/gatsby-plugin-firebase/database/dataSnapshot.js
+++ b/__mocks__/gatsby-plugin-firebase/database/dataSnapshot.js
@@ -1,7 +1,5 @@
-import Reference from './reference';
-
class DataSnapshot {
- constructor(eventType, reference, value = undefined) {
+ constructor(eventType, getDataCallback, value = undefined) {
if (!eventType) {
throw new Error('eventType must be provided.');
} else if (typeof eventType !== 'string') {
@@ -10,13 +8,13 @@ class DataSnapshot {
this.eventTypeField = eventType;
- if (!reference) {
- throw new Error('reference must be provided.');
- } else if (!(reference instanceof Reference)) {
- throw new Error('reference must be an instance of the Reference class.');
+ if (!getDataCallback) {
+ throw new Error('getDataCallback must be provided.');
+ } else if (typeof getDataCallback !== 'function') {
+ throw new Error('getDataCallback should be a function.');
}
- this.referenceField = reference;
+ this.getDataCallbackField = getDataCallback;
this.valueField = value;
}
@@ -33,7 +31,7 @@ class DataSnapshot {
if (this.eventType === 'value') {
return typeof this.value !== 'undefined'
? this.value
- : this.referenceField.getData();
+ : this.getDataCallbackField();
}
return undefined;
diff --git a/__mocks__/gatsby-plugin-firebase/database/reference.js b/__mocks__/gatsby-plugin-firebase/database/reference.js
index 0888d7365..f4deb3cf4 100644
--- a/__mocks__/gatsby-plugin-firebase/database/reference.js
+++ b/__mocks__/gatsby-plugin-firebase/database/reference.js
@@ -6,7 +6,7 @@ import DataSnapshot from './dataSnapshot';
const rootPath = '.';
class Reference {
- constructor(path, getDatabaseData) {
+ constructor(path, getDatabaseDataCallback) {
if (typeof path === 'undefined' || path === null) {
this.pathField = rootPath;
} else if (typeof path !== 'string') {
@@ -16,15 +16,16 @@ class Reference {
}
this.uuidField = uuidv4();
+
this.dataSnapshotsField = {};
- if (!getDatabaseData) {
- throw new Error('getDatabaseData must be provided.');
- } else if (typeof getDatabaseData !== 'function') {
- throw new Error('getDatabaseData should be a function.');
+ if (!getDatabaseDataCallback) {
+ throw new Error('getDatabaseDataCallback must be provided.');
+ } else if (typeof getDatabaseDataCallback !== 'function') {
+ throw new Error('getDatabaseDataCallback should be a function.');
}
- this.getDatabaseDataField = getDatabaseData;
+ this.getDatabaseDataCallbackField = getDatabaseDataCallback;
this.orderByChildPathField = '';
this.equalToValueField = '';
@@ -39,7 +40,7 @@ class Reference {
}
getData() {
- const databaseData = this.getDatabaseDataField();
+ const databaseData = this.getDatabaseDataCallbackField();
if (!databaseData) {
return null;
@@ -99,19 +100,19 @@ class Reference {
return;
}
- let snapshot = new DataSnapshot(eventType, this, null);
+ let snapshot = new DataSnapshot(eventType, () => this.getData(), null);
if (this.path === DatabaseConstants.connectedPath) {
- snapshot = new DataSnapshot(eventType, this, true);
+ snapshot = new DataSnapshot(eventType, () => this.getData(), true);
} else if (this.path === DatabaseConstants.resumesPath) {
- snapshot = new DataSnapshot(eventType, this);
+ snapshot = new DataSnapshot(eventType, () => this.getData());
}
callback(snapshot);
}
async once(eventType) {
- const newDataSnapshot = new DataSnapshot(eventType, this);
+ const newDataSnapshot = new DataSnapshot(eventType, () => this.getData());
const existingDataSnapshot = this.dataSnapshotsField[
newDataSnapshot.eventType
];