Skip to content

Commit 5ff3b6c

Browse files
authored
Fix integration test. (#250)
1 parent 3f70cc2 commit 5ff3b6c

File tree

10 files changed

+19
-21
lines changed

10 files changed

+19
-21
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
node_js:
3-
- '6.11.5'
3+
- '6.14.0'
4+
- '8'
45
- stable
56
sudo: false

integration_test/functions/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"@google-cloud/pubsub": "^0.6.0",
99
"@types/lodash": "^4.14.41",
1010
"firebase": "^4.9.1",
11-
"firebase-admin": "~5.12.0",
11+
"firebase-admin": "~5.12.1",
1212
"firebase-functions": "./firebase-functions.tgz",
1313
"lodash": "^4.17.2"
1414
},
1515
"main": "lib/index.js",
1616
"devDependencies": {
17-
"typescript": "^2.0.10"
17+
"typescript": "^2.8.3"
1818
},
1919
"private": true
2020
}

integration_test/functions/src/auth-tests.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ export const createUserTests: any = functions.auth.user().onCreate((u, c) => {
99

1010
return new TestSuite<UserMetadata>('auth user onCreate')
1111
.it('should have a project as resource', (user, context) => expectEq(
12-
context.resource, `projects/${process.env.GCLOUD_PROJECT}`))
12+
context.resource.name, `projects/${process.env.GCLOUD_PROJECT}`))
1313

1414
.it('should not have a path', (user, context) => expectEq((context as any).path, undefined))
1515

1616
.it('should have the correct eventType', (user, context) => expectEq(
17-
context.eventType, 'providers/firebase.auth/eventTypes/user.create'))
17+
context.eventType, 'google.firebase.auth.user.create'))
1818

1919
.it('should have an eventId', (user, context)=> context.eventId)
2020

@@ -33,12 +33,12 @@ export const deleteUserTests: any = functions.auth.user().onDelete((u, c) => {
3333

3434
return new TestSuite<UserMetadata>('auth user onDelete')
3535
.it('should have a project as resource', (user, context) => expectEq(
36-
context.resource, `projects/${process.env.GCLOUD_PROJECT}`))
36+
context.resource.name, `projects/${process.env.GCLOUD_PROJECT}`))
3737

3838
.it('should not have a path', (user, context) => expectEq((context as any).path, undefined))
3939

4040
.it('should have the correct eventType', (user, context) => expectEq(
41-
context.eventType, 'providers/firebase.auth/eventTypes/user.delete'))
41+
context.eventType, 'google.firebase.auth.user.delete'))
4242

4343
.it('should have an eventId', (user, context) => context.eventId)
4444

integration_test/functions/src/database-tests.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as functions from 'firebase-functions';
22
import { TestSuite, expectEq, expectMatches } from './testing';
33
import * as admin from 'firebase-admin';
44
import DataSnapshot = admin.database.DataSnapshot;
5-
import { Change } from '../../../src/cloud-functions';
65

76
const testIdFieldName = 'testId';
87

@@ -14,7 +13,7 @@ export const databaseTests: any = functions.database.ref('dbTests/{testId}/start
1413
return;
1514
}
1615

17-
return new TestSuite<Change<DataSnapshot>>('database ref onWrite')
16+
return new TestSuite<functions.Change<DataSnapshot>>('database ref onWrite')
1817

1918
.it('should not have event.app', (change, context) => !(context as any).app)
2019

integration_test/functions/src/firestore-tests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const firestoreTests: any = functions.firestore.document('tests/{document
1919
)
2020

2121
.it('should have the right eventType', (snap, context) => expectEq(
22-
context.eventType, 'providers/cloud.firestore/eventTypes/document.create'))
22+
context.eventType, 'google.firestore.document.create'))
2323

2424
.it('should have eventId', (snap, context) => context.eventId)
2525

integration_test/functions/src/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ export * from './firestore-tests';
1111
export * from './https-tests';
1212
const numTests = Object.keys(exports).length; // Assumption: every exported function is its own test.
1313

14-
// Client SDK doesn't support auto initialization:
15-
firebase.initializeApp(JSON.parse(process.env.FIREBASE_CONFIG));
14+
import 'firebase-functions'; // temporary shim until process.env.FIREBASE_CONFIG available natively in GCF(BUG 63586213)
15+
const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);
16+
firebase.initializeApp(firebaseConfig);
1617
console.log('initializing admin');
1718
admin.initializeApp();
1819

@@ -21,7 +22,7 @@ function callHttpsTrigger(name: string, data: any) {
2122
return new Promise((resolve, reject) => {
2223
const request = https.request({
2324
method: 'POST',
24-
host: 'us-central1-' + functions.config().firebase.projectId + '.cloudfunctions.net',
25+
host: 'us-central1-' + firebaseConfig.projectId + '.cloudfunctions.net',
2526
path: '/' + name,
2627
headers: {
2728
'Content-Type': 'application/json',

integration_test/functions/src/pubsub-tests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const pubsubTests: any = functions.pubsub.topic('pubsubTests').onPublish(
1919
.it('should not have a path', (message, context) => expectEq((context as any).path, undefined))
2020

2121
.it('should have the correct eventType', (message, context) => expectEq(
22-
context.eventType, 'providers/cloud.pubsub/eventTypes/topic.publish'))
22+
context.eventType, 'google.pubsub.topic.publish'))
2323

2424
.it('should have an eventId', (message, context) => context.eventId)
2525

integration_test/functions/src/testing.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as firebase from 'firebase-admin';
22
import * as _ from 'lodash';
33
import { EventContext } from 'firebase-functions';
44

5-
export type TestCase<T> = (data: T, context: EventContext) => any
5+
export type TestCase<T> = (data: T, context?: EventContext) => any
66
export type TestCaseMap<T> = { [key: string]: TestCase<T> };
77

88
export class TestSuite<T> {
@@ -19,7 +19,7 @@ export class TestSuite<T> {
1919
return this;
2020
}
2121

22-
run(testId: string, data: T, context: EventContext): Promise<void> {
22+
run(testId: string, data: T, context?: EventContext): Promise<void> {
2323
let running: Array<Promise<any>> = [];
2424
for (let testName in this.tests) {
2525
if (!this.tests.hasOwnProperty(testName)) { continue; }

integration_test/functions/tsconfig.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"compilerOptions": {
3-
"lib": [
4-
"es6",
5-
"es2015.promise"
6-
],
3+
"lib": ["es6"],
74
"module": "commonjs",
85
"target": "es6",
96
"noImplicitAny": false,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"nock": "^9.0.0",
4747
"sinon": "^1.17.4",
4848
"tslint": "^3.15.1",
49-
"typescript": "^2.0.3"
49+
"typescript": "^2.8.3"
5050
},
5151
"peerDependencies": {
5252
"firebase-admin": "~5.12.1"

0 commit comments

Comments
 (0)