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

Wrapped Gen 2 Firestore Trigger receives incorrect data #238

Open
MichaelJBerk opened this issue Jul 8, 2024 · 2 comments
Open

Wrapped Gen 2 Firestore Trigger receives incorrect data #238

MichaelJBerk opened this issue Jul 8, 2024 · 2 comments

Comments

@MichaelJBerk
Copy link

MichaelJBerk commented Jul 8, 2024

Version info

firebase-functions-test: 5.0.1

firebase-functions: 3.3.0

firebase-admin: 12.2.0

Test case

When calling a wrapped function set to a Gen 2 Firestore trigger, the function will receive the value for the exampleDocumentSnapshot, rather than the actual value provided by the test:

/// Test Code
test("Write Item V2", async () => {
	const db = getFirestore()
	const path = `items/${generateTempId()}`
	const data = {name: "MyTest"}
	
	await db.doc(path).set(data)
	testEnv.firestore.exampleDocumentSnapshotChange()
	const wrapped = testEnv.wrap(myOnWriteTrigger)
	const beforeSnap = testEnv.firestore.makeDocumentSnapshot({name:'blah'}, path)
	const afterSnap = testEnv.firestore.makeDocumentSnapshot(data, path)
	const change = testEnv.makeChange(beforeSnap, afterSnap)
	
	await wrapped(change)
})

/// Cloud Function
export const myOnWriteTrigger = onDocumentWritten("items/{itemid}", async (event) => {
	///This will output "{ aString: 'foo', anObject: { a: 'qux', b: 'faz' }, aNumber: 7 }"
	console.log(event.data.after.data())
	///...
}

Steps to reproduce

I've created a sample project with the issue at https://github.com/MichaelJBerk/FirestoreFunctionsTriggerBug. View the readme for details

Expected behavior

event.data.after.data() should contain the data provided in the test

Actual behavior

event.data.after.data() contains the exampleDocumentSnapshot value ({ aString: 'foo', anObject: { a: 'qux', b: 'faz' }, aNumber: 7 })

@anonimitoraf
Copy link

Lol I thought I was just doing something wrong.

@RohovDmytro
Copy link

RohovDmytro commented Sep 17, 2024

The Google Cloud CLI is defaulting to v2 as of now. Let's fix testing v2 functions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants