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

Add MockCloudEvents for RTDB-V2 #156

Merged
merged 19 commits into from
Aug 2, 2022
Merged

Add MockCloudEvents for RTDB-V2 #156

merged 19 commits into from
Aug 2, 2022

Conversation

TheIronDev
Copy link
Contributor

This commit is a follow-up to firebase-function's addition of rtdb-v2.

This commit must wait for the RTDB-V2 updates to be published on npm.

This commit is a follow-up to firebase-function's addition of rtdb-v2.

This commit must wait for the RTDB-V2 updates to be published on npm.
spec/v2.spec.ts Outdated Show resolved Hide resolved
spec/v2.spec.ts Outdated Show resolved Hide resolved
spec/v2.spec.ts Outdated Show resolved Hide resolved
spec/v2.spec.ts Show resolved Hide resolved
spec/v2.spec.ts Outdated Show resolved Hide resolved
src/cloudevent/mocks/database/database-on-ref-created.ts Outdated Show resolved Hide resolved
(cloudEventPartial?.firebaseDatabaseHost as string) ||
'firebaseDatabaseHost';
const ref = (cloudEventPartial?.ref as string) || '/foo/bar';
const location = (cloudEventPartial?.location as string) || 'us-central1';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or function location

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unclear where on the function I should grab the location as a string. I'll follow up with you on this one.

src/cloudevent/mocks/helpers.ts Outdated Show resolved Hide resolved
@inlined
Copy link
Member

inlined commented Jul 1, 2022

Is this ready for re-review?
Also, unfortunately the V4 SDK is going to change the types of what you're forwarding and returning. We might want to target that and hold off on the current release.

@TheIronDev
Copy link
Contributor Author

Is this ready for re-review?
Also, unfortunately the V4 SDK is going to change the types of what you're forwarding and returning. We might want to target that and hold off on the current release.

The branch is unblocked, but this is not ready for re-review.

I'll take a look this weekend to clean things up, but I'll need to check and see how V4 mucks with what I wrote.

@TheIronDev
Copy link
Contributor Author

It is ready for re-review now (sorry for the loooooooong delay)

@TheIronDev TheIronDev requested a review from inlined July 28, 2022 15:21
@TheIronDev TheIronDev requested a review from taeold July 28, 2022 16:13
Copy link

@colerogers colerogers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome work! just one suggestion & question

spec/v2.spec.ts Outdated Show resolved Hide resolved
spec/v2.spec.ts Outdated Show resolved Hide resolved
src/cloudevent/mocks/database/helpers.ts Outdated Show resolved Hide resolved
src/cloudevent/mocks/database/helpers.ts Show resolved Hide resolved
Copy link
Contributor

@taeold taeold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

spec/v2.spec.ts Show resolved Hide resolved
spec/v2.spec.ts Show resolved Hide resolved
src/cloudevent/mocks/database/helpers.ts Outdated Show resolved Hide resolved
@@ -41,8 +41,11 @@ export namespace testApp {

getApp(): firebase.app.App {
if (typeof this.appSingleton === 'undefined') {
const config = process.env.FIREBASE_CONFIG
Copy link
Contributor

@taeold taeold Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know what happens when firebase.initializeApp() is initialized w/ an empty config?

I imagine some things won't work as intended in some strange way. Blowing up JSON.parse(undefined) isn't a great experience either, but curious what problem we are fixing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this one was interesting.

Tossing an empty config didn't seem to do much of anything. I'm down for any other alternative.

src/cloudevent/mocks/database/database-on-value-created.ts Outdated Show resolved Hide resolved
Copy link
Member

@inlined inlined left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the note about ref and params, this will have parity with the test SDK for the v1 API.

Totally out of left field, but working on a Python RTDB interface makes me wonder if we want a break from the past here (instead of? as well?) In v1 we required people to call the makeSnapshot method because the ref was a derived property of the snapshot. But in the v2 event, the ref is redundant with the "ref" field of the raw cloud event. I wonder if we should support literally passing JSON for before and after? And in that case we'd just create a DataShapshot with that JSON value and the ref location in event.ref. Thoughts @TheIronDev and @taeold ?

@@ -0,0 +1,15 @@
import { MockCloudEventAbstractFactory } from '../../types';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I started this with storage the last time I edited the codebase, but I think that this habit of having a file for every event type is probably overkill. In the CLI at least we have a map of event type to service and then the strategy object is per service.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats fair. Theres definitely DRYness that could get applied here, but I also wanted to push to make the code as easy-to-read and easy to add.

Adding a new event is a matter of creating a new AbstractFactory with generateMock and match implemented.

TBH I could go either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll follow up in a future cl.

src/cloudevent/mocks/database/helpers.ts Show resolved Hide resolved
@TheIronDev TheIronDev merged commit 7ca7e22 into master Aug 2, 2022
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

Successfully merging this pull request may close these issues.

None yet

4 participants