-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
feat(callFirestore): create document with reference to another using cy.callFirestore #232
Comments
Yeah, definitely a valid use case, thanks for reaching out! Returning the snapshot (which contains a reference) is what I was describing in #128, but as noted that would mean either an option or a change to the API. The firebase instance is initialized in cypress (since it is running in the browser) - so we should be able to fix things so you could just use the browser SDK directly like with timestamps: import firebase from "firebase/app";
import "firebase/firestore";
const personRef = db.doc('people/tom')
const carRef = db.doc('cars/car1')
cy.callFirestore('set', 'people/tom', { name: "Tom" })
cy.callFirestore('set', 'cars/car1', make: 'Honda Civic', owner: person }) NOTE: I don't believe this will work yet, but I will start testing and looking into the change |
Wonderful, thanks! |
Hello, I'm kinda stuck at the moment with the same issue. When I call const db = firebase.firestore() inside a test a got the ERROR that initilizeApp wasn't call. Is it legit ? Thanks for the help, Regards -- EDIT ---- I workedaround the problem by exporting the db object of the command.js file and importing it inside my test, but when i run
|
Hi, perhaps we could do something like Line 257 in c991748
Something like function getDataWithReference(adminInstance, data) {
const isDoc = (value) => value.split('/').length === 3 // should be a better way to do this
const isString = (value) => typeof value === 'string'
return Object.entries(data).reduce((acc, [currKey, currData]) => {
if(isString(currData) && isDoc(currData)) {
return {
...acc,
[currKey]: adminInstance.firestore().doc(currData)
}
}
if(Array.isArray(currData)) {
return {
...acc,
[currKey]: currData.map(dataSet => isString(dataSet) && isDoc(dataSet)
? adminInstance.firestore().doc(dataSet)
: dataSet)
}
}
return {
...acc,
[currKey]: currData
}
}, {})
} Then use cy.callFirestore('set', 'cars/car1', make: 'Honda Civic', owner: '/people/tom' }) |
@delete I think this will potentially cause issues if someone is trying to just write a slash path to a parameter instead of having that point to a document - We may need to pass along some additional information about which params should be converted into references. It would be good to have this happen automatically within the task/plugin, but it is going from the browser through to the node environment, so there is that parsing to deal with (why a reference isn't currently being passed straight through) |
Is your feature request related to a problem? Please describe.
I would like to be able to use
callFirestore
to create one document, then create another with a field of type reference (see https://firebase.google.com/docs/firestore/manage-data/data-types) that points to that document. For example:I don't think it's possible right now, because I'd need access to the firestore instance. In an application, I would do something like this:
Perhaps the set call could return a reference? Or we could have access to the firebase instance? I'm not sure what the most elegant solution would be.
Describe alternatives you've considered
I tried doing the following:
but this just adds the person as an object, rather than a reference (presumably because
cy.callFirestore('get')
returns the data, not a reference).Additional context
The text was updated successfully, but these errors were encountered: