sbatson5 / firestore-jest-mock

Jest Helper library for mocking Cloud Firestore

Home Page:https://www.npmjs.com/package/firestore-jest-mock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

QueryDocumentSnapshot that passed to trigger functions doesn't contain createTime element

ndpdarshana opened this issue · comments

Description

QueryDocumentSnapshot that passed to trigger functions doesn't contain createTime element

Steps to reproduce

Call createTime in snapshot passed into a trigger function.

Expected result

The createTime should contain a value of the document created in the original scenario.
https://googleapis.dev/nodejs/firestore/latest/QueryDocumentSnapshot.html

Actual result

createTime element is not available within the queryDocumentSnapshot that passed to trigger functions

Fix suggesstion

For mocking purposes, we can provide the current time of the test suit or createdAt time if available on the FakeFirestore database.
In order to correct the issue, buildDocFromHash.js file should return an object containing populated createTime.
For example:

module.exports = function buildDocFromHash(hash = {}, id = 'abc123') {
  const exists = !!hash || false;
  return {
    exists,
    id: (hash && hash.id) || id,
    ref: hash && hash._ref,
    createTime: hash.createdAt,
    metadata: {
      hasPendingWrites: 'Server',
    },
  ...

Fixed by #127