Skip to content

Implement firebase-functions-test wrapV2 #131

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

Merged
merged 31 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
26bef11
Implement firebase-functions-test wrapV2
TheIronDev Apr 11, 2022
620efec
Minor updates (per pr comments.)
TheIronDev Apr 14, 2022
25f1686
Implement createMockCloudEvent for v2 wrap
TheIronDev Apr 20, 2022
da6d7f6
Fix how V2 CloudEventSource gets populated
TheIronDev Apr 25, 2022
5ead878
Fix CloudEvent.subject and CloudEvent.source
TheIronDev Apr 25, 2022
173244e
Bumped semver to 1.0.0
TheIronDev Apr 25, 2022
7a6a36b
Added support for eventarc custom events
TheIronDev Apr 25, 2022
7a43876
Fix follow ups from PR feedback
TheIronDev Apr 26, 2022
c6bc418
Handle V2 function behavior within the main.ts#wrap call
TheIronDev Apr 26, 2022
2614eb5
Decouple wrapV1 logic from main.ts#wrap
TheIronDev Apr 26, 2022
c535541
Add in Partial Typing instead of CloudEventOverride
TheIronDev Apr 26, 2022
4cb0038
Fix issue with broken typing (CloudBaseEvent isn't exported)
TheIronDev Apr 27, 2022
5c873ea
Follow up items from PR feedback
TheIronDev Apr 28, 2022
6865768
Create and Implement MockCloudEvent
TheIronDev Apr 28, 2022
eac837e
Refactor V2 wrap function
TheIronDev Apr 28, 2022
7c40120
Implemented StorageObjectData and improved typing
TheIronDev Apr 28, 2022
14805af
Introduce DeepPartial
TheIronDev Apr 29, 2022
8d232d9
Wire up deep merge
TheIronDev Apr 29, 2022
dfcdebe
Implement data generation for Alerts
TheIronDev Apr 29, 2022
5726338
Fix Types for AppDistributionEvent, BillingEvent, and CrashlyticsEvent
TheIronDev Apr 30, 2022
503aa65
Split the cloudevent partial definitions to different files
TheIronDev May 2, 2022
afbeac8
Implement mock MessagePublishedData for pubsub
TheIronDev May 2, 2022
510a880
Update EventArc sample CloudEvent
TheIronDev May 2, 2022
c259fdf
Updated Unit tests for PubSub data.message generation
TheIronDev May 2, 2022
c6ad354
Update returned type for `Alert.OnAlertPublished` partial
TheIronDev May 2, 2022
614139b
Remove `param` from default CloudEvent generation
TheIronDev May 2, 2022
b2eeddd
Fix all the imports (from /lib/v2/providers -> /v2)
TheIronDev May 3, 2022
3b92144
Fix redundant typing
TheIronDev May 3, 2022
87cd8cb
DRY cleanup
TheIronDev May 3, 2022
c7e7845
Patch Minor lint issues
TheIronDev May 3, 2022
a530aac
Removed hardcoded json from pubsub partial generator
TheIronDev May 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,410 changes: 8,370 additions & 40 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebase-functions-test",
"version": "0.3.3",
"version": "1.0.0",
"description": "A testing companion to firebase-functions.",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -39,14 +39,15 @@
"homepage": "https://github.com/firebase/firebase-functions-test#readme",
"dependencies": {
"@types/lodash": "^4.14.104",
"lodash": "^4.17.5"
"lodash": "^4.17.5",
"ts-deepmerge": "^2.0.1"
},
"devDependencies": {
"@types/chai": "~4.2.4",
"@types/mocha": "^5.2.7",
"chai": "^4.2.0",
"firebase-admin": "~8.9.0",
"firebase-functions": "^3.3.0",
"firebase-functions": "^3.20.1",
"firebase-tools": "^8.9.2",
"mocha": "^6.2.2",
"prettier": "^1.19.1",
Expand All @@ -55,8 +56,8 @@
"typescript": "^3.6.4"
},
"peerDependencies": {
"firebase-functions": ">=2.0.0",
"firebase-admin": ">=6.0.0"
"firebase-admin": ">=6.0.0",
"firebase-functions": ">=3.20.1"
},
"engines": {
"node": ">=8.0.0"
Expand Down
60 changes: 60 additions & 0 deletions spec/cloudevent/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import {expect} from 'chai';

import {alerts, storage} from 'firebase-functions/v2';
import {generateMockCloudEvent} from '../../src/cloudevent/generate';

describe('generate (CloudEvent)', () => {
describe('#generateMockCloudEvent', () => {
describe('alerts.billing.onPlanAutomatedUpdatePublished()', () => {
it('should create CloudEvent with appropriate fields', () => {
const cloudFn = alerts.billing.onPlanAutomatedUpdatePublished(() => {
});
const cloudEvent =
generateMockCloudEvent(cloudFn);

expect(cloudEvent.type).equal(
'google.firebase.firebasealerts.alerts.v1.published');
expect(cloudEvent.source).equal(
'//firebasealerts.googleapis.com/projects/42');
expect(cloudEvent.subject).equal(undefined);
});
Copy link
Member

Choose a reason for hiding this comment

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

and eventually tests on data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack (will follow up!)

});
describe('storage.onObjectArchived', () => {
it('should create CloudEvent with appropriate fields', () => {
const bucketName = 'bucket_name';
const cloudFn = storage.onObjectArchived(bucketName, () => {
});
const cloudEvent =
generateMockCloudEvent(cloudFn);

expect(cloudEvent.type).equal(
'google.cloud.storage.object.v1.archived');
expect(cloudEvent.source).equal(
`//storage.googleapis.com/projects/_/buckets/${bucketName}`);
expect(cloudEvent.subject).equal('objects/file_name');
});
Copy link
Member

Choose a reason for hiding this comment

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

and another test for when bucketName is not specified

});
});
});
2 changes: 2 additions & 0 deletions spec/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ describe('index', () => {

import './lifecycle.spec';
import './main.spec';
import './v2.spec';
import './cloudevent/generate';
import './app.spec';
import './providers/https.spec';
import './providers/firestore.spec';
Expand Down
13 changes: 13 additions & 0 deletions spec/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
} from '../src/main';
import { features } from '../src/features';
import { FirebaseFunctionsTest } from '../src/lifecycle';
import {alerts} from 'firebase-functions/v2';
import {wrapV2} from '../src/v2';

describe('main', () => {
describe('#wrap', () => {
Expand Down Expand Up @@ -226,6 +228,17 @@ describe('main', () => {
});
});

describe('v2 functions', () => {
it('should invoke wrapV2 wrapper', () => {
const handler = (cloudEvent) => ({cloudEvent});
const cloudFn = alerts.billing.onPlanAutomatedUpdatePublished(handler);
const cloudFnWrap = wrapV2(cloudFn);

const expectedType = 'google.firebase.firebasealerts.alerts.v1.published';
expect(cloudFnWrap().cloudEvent).to.include({type: expectedType});
});
});

describe('callable functions', () => {
let wrappedCF;

Expand Down
Loading