firebase / firebase-functions-test

MIT License
232 stars 48 forks source link

Implement firebase-functions-test wrapV2 #131

Closed TheIronDev closed 2 years ago

TheIronDev commented 2 years ago

Description

Implement wrap function for v2 CloudFuntions.

Code sample

const cloudEventInstance = {..._getDefaultCloudEvent(), data};
const handler = (cloudEvent) => ({cloudEvent});
const cloudFn = storage.onObjectMetadataUpdated('bucket', handler);
expect(cloudFn(cloudEventInstance).cloudEvent).equal(cloudEventInstance);
TheIronDev commented 2 years ago

Requesting a review from @inlined

TheIronDev commented 2 years ago

@inlined Providing a default data might fix that then? I'll follow up with you on that.

TheIronDev commented 2 years ago

I suspect you'll have an easier time if you use a strategy pattern. For example, you can look up a Service (e.g. Pub/Sub or GCS) given an eventType and then call into that service's "generateMockEvent" method. This will help you, for example, only insert params on RTDB events or to insert appId as a field in FireAlerts events.

We're possibly going to have a lot of event types given that 3P events are coming. I think a little over-engineering to have a codebase where changes are decoupled from the rest of the codebase and have an obvious way to grow organically would be in our best interest.

I agree with the strategy pattern. We need a little more signal to differentiate some of the alerts, so I'm planning on also using eventTrigger?.eventFilters as well.

Will ping you when I get closer to cleaning everything up.

TheIronDev commented 2 years ago

Alright, Storage data is done! Still working on generating data for....

TheIronDev commented 2 years ago

I think this is fine for a checkpoint. I may dig in later to play with the type system, DRY things out, and/or improve the way one field can be generated from another.

Sounds good to me! I'm going to submit to unblock the other team members.