I am trying to write a function that references existing data to make certain calculations before updating other data. Unfortunately makeDataSnapshot does not actually create data in the database. Is there any other way to invoke this data without creating real data or would I need to set it in the before block?
Steps to reproduce
index.js
exports.incrementClassStarted = functions.database
.ref("/users_progress/{uid}/class_progress/{classId}/started")
.onCreate((snapshot, context) => {
const db = admin.database();
return db
.ref(`/users_progress/${context.params.uid}/class_progress`)
.once("value")
.then(progressSnap => {
const classProgress = progressSnap.val(); // this returns null
const startedClassesCount = _.filter(
classProgress,
progress => progress.started,
).length; // this is 0
return db.ref(`/users_progress/${context.params.uid}`).update({
classes_started: startedClassesCount,
});
});
});
Version info
firebase-functions-test: ^0.1.6
firebase-functions: ^2.3.0
firebase-admin: ~6.0.0
Test case
I am trying to write a function that references existing data to make certain calculations before updating other data. Unfortunately
makeDataSnapshot
does not actually create data in the database. Is there any other way to invoke this data without creating real data or would I need to set it in thebefore
block?Steps to reproduce
index.js
index.test.js
Expected behavior
admin.database().ref("/users_progress/${context.params.uid}/class_progress").
returns{ started: "FAKE_TIMESTAMP" }
Actual behavior
admin.database().ref("/users_progress/${context.params.uid}/class_progress").
returns null