Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocumentReference not compatible with @firebase/testing #44

Open
xXCalleManXx opened this issue Jul 26, 2019 · 1 comment
Open

DocumentReference not compatible with @firebase/testing #44

xXCalleManXx opened this issue Jul 26, 2019 · 1 comment

Comments

@xXCalleManXx
Copy link

Version info

firebase-functions-test: 0.1.6

firebase-functions: 3.2.0

firebase-admin: 8.3.0

@firebase/testing: 0.11.8

firebase-tools: 7.2.1

Test case

const firebase = require("@firebase/testing");
const test = require('firebase-functions-test')();
const admin = require('firebase-admin');

/**
 * @returns {firebase.firestore.Firestore}
 */
function adminApp() {
    return firebase.initializeAdminApp({projectId: "MyEmulatedProject"}).firestore()
}

const ref = adminApp().collection('users').doc('user1');

let data = { ref };

if (ref instanceof admin.firestore.DocumentReference) {
    console.log('DocumentRefrence of firebase-admin');
} else if (ref instanceof firebase.firestore.DocumentReference) {
    console.log('DocumentRefrence of @firebase/testing')
}

// Throws "Cannot encode [object Object]to a Firestore Value. Local testing does not yet support Firestore geo points."
test.firestore.makeDocumentSnapshot(data, '/collection/doc');

Steps to reproduce

  1. Start firestore emulator "firebase emulators:start --only firestore"
  2. Run the example above

Expected behavior

Should work the same way as with a DocumentReference from firebase-admin.

Actual behavior

Throws error

Error: Cannot encode [object Object]to a Firestore Value. Local testing does not yet support Firestore geo points.
    at encodeHelper (/node_modules/firebase-functions-test/lib/providers/firestore.js:165:15)
    at /node_modules/lodash/lodash.js:13401:38
    at /node_modules/lodash/lodash.js:4905:15
    at baseForOwn (node_modules/lodash/lodash.js:2990:24)
    at Function.mapValues (/node_modules/lodash/lodash.js:13400:7)
    at objectToValueProto (/node_modules/firebase-functions-test/lib/providers/firestore.js:168:21)
    at Object.makeDocumentSnapshot (/node_modules/firebase-functions-test/lib/providers/firestore.js:49:17)
    at Object.<anonymous> (/test/test2/test.js:22:16)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)

And it outputs DocumentRefrence of @firebase/testing as the DocumentReference is initialized with @firebase/testing

This error is resolved in issue #24, but only for DocumentReference and Timestamp initialized with firebase-admin.

@laurenzlong
Copy link
Contributor

Sorry for the very late response! Using this SDK with @firebase/testing is not supported. I'm marking this as a feature request.

@laurenzlong laurenzlong changed the title DocumentReference not working with @firebase/testing DocumentReference not compatible with @firebase/testing Dec 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants