Skip to content

Commit e6bd9a1

Browse files
authored
Remove LegacyEvent, change all tests to use new Event format (#460)
* remove LegacyEvent flows * fix context in v1beta1 as it looks different - this fixes integration tests also * remove LegacyEvent since it's no longer supported * fixes from review comments, removing unused tests * adding changelog entry
1 parent c4ff972 commit e6bd9a1

12 files changed

+553
-436
lines changed

changelog.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
- important - [breaking change] The Firebase Functions SDK no longer supports Node 6. Developers must use Node 8.13.0 or higher.
2-
- important - [breaking change] The Firebase Functions SDK no longer supports Firebase Tools SDK below version 6.8.0.
3-
- important - [breaking change] FIREBASE_PROJECT environment variable is no longer supported and has been supplanted by FIREBASE_CONFIG.
1+
important - [breaking change] The Firebase Functions SDK no longer supports Node 6. Developers must use Node 8.13.0 or higher.
2+
important - [breaking change] The Firebase Functions SDK no longer supports Firebase Tools SDK below version 6.8.0.
3+
important - [breaking change] FIREBASE_PROJECT environment variable is no longer supported and has been supplanted by FIREBASE_CONFIG.
4+
fixed - Fixed bug in Node 10 where events from Node 10 were not parsed properly resulting in undefined.

spec/cloud-functions.spec.ts

Lines changed: 34 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { expect } from 'chai';
2525
import {
2626
Event,
2727
EventContext,
28-
LegacyEvent,
2928
makeCloudFunction,
3029
MakeCloudFunctionArgs,
3130
Change,
@@ -69,32 +68,7 @@ describe('makeCloudFunction', () => {
6968
});
7069
});
7170

72-
it('should construct the right context for legacy event format', () => {
73-
let args: any = _.assign({}, cloudFunctionArgs, {
74-
handler: (data: any, context: EventContext) => context,
75-
});
76-
let cf = makeCloudFunction(args);
77-
let test: LegacyEvent = {
78-
eventId: '00000',
79-
timestamp: '2016-11-04T21:29:03.496Z',
80-
eventType: 'providers/provider/eventTypes/event',
81-
resource: 'resource',
82-
data: 'data',
83-
};
84-
85-
return expect(cf(test)).to.eventually.deep.equal({
86-
eventId: '00000',
87-
timestamp: '2016-11-04T21:29:03.496Z',
88-
eventType: 'mock.provider.mock.event',
89-
resource: {
90-
service: 'service',
91-
name: 'resource',
92-
},
93-
params: {},
94-
});
95-
});
96-
97-
it('should construct the right context for new event format', () => {
71+
it('should construct the right context for event', () => {
9872
let args: any = _.assign({}, cloudFunctionArgs, {
9973
handler: (data: any, context: EventContext) => context,
10074
});
@@ -112,7 +86,7 @@ describe('makeCloudFunction', () => {
11286
data: 'data',
11387
};
11488

115-
return expect(cf(test)).to.eventually.deep.equal({
89+
return expect(cf(test.data, test.context)).to.eventually.deep.equal({
11690
eventId: '00000',
11791
timestamp: '2016-11-04T21:29:03.496Z',
11892
eventType: 'provider.event',
@@ -124,41 +98,6 @@ describe('makeCloudFunction', () => {
12498
});
12599
});
126100

127-
it('should handle Node 8 function signature', () => {
128-
let args: any = _.assign({}, cloudFunctionArgs, {
129-
handler: (data: any, context: EventContext) => {
130-
return { data, context };
131-
},
132-
});
133-
process.env.X_GOOGLE_NEW_FUNCTION_SIGNATURE = 'true';
134-
let cf = makeCloudFunction(args);
135-
delete process.env.X_GOOGLE_NEW_FUNCTION_SIGNATURE;
136-
let testContext = {
137-
eventId: '00000',
138-
timestamp: '2016-11-04T21:29:03.496Z',
139-
eventType: 'provider.event',
140-
resource: {
141-
service: 'provider',
142-
name: 'resource',
143-
},
144-
};
145-
let testData = 'data';
146-
147-
return expect(cf(testData, testContext)).to.eventually.deep.equal({
148-
data: 'data',
149-
context: {
150-
eventId: '00000',
151-
timestamp: '2016-11-04T21:29:03.496Z',
152-
eventType: 'provider.event',
153-
resource: {
154-
service: 'provider',
155-
name: 'resource',
156-
},
157-
params: {},
158-
},
159-
});
160-
});
161-
162101
it('should throw error when context.params accessed in handler environment', () => {
163102
let args: any = _.assign({}, cloudFunctionArgs, {
164103
handler: (data: any, context: EventContext) => context,
@@ -178,7 +117,7 @@ describe('makeCloudFunction', () => {
178117
data: 'test data',
179118
};
180119

181-
return cf(test).then(result => {
120+
return cf(test.data, test.context).then(result => {
182121
expect(result).to.deep.equal({
183122
eventId: '00000',
184123
timestamp: '2016-11-04T21:29:03.496Z',
@@ -204,20 +143,7 @@ describe('makeParams', () => {
204143
};
205144
const cf = makeCloudFunction(args);
206145

207-
it('should construct params from the event resource of legacy events', () => {
208-
const testEvent: LegacyEvent = {
209-
resource: 'projects/_/instances/pid/ref/a/nested/b',
210-
eventType: 'legacyEvent',
211-
data: 'data',
212-
};
213-
214-
return expect(cf(testEvent)).to.eventually.deep.equal({
215-
foo: 'a',
216-
bar: 'b',
217-
});
218-
});
219-
220-
it('should construct params from the event resource of new format events', () => {
146+
it('should construct params from the event resource of events', () => {
221147
const testEvent: Event = {
222148
context: {
223149
eventId: '111',
@@ -231,7 +157,9 @@ describe('makeParams', () => {
231157
data: 'data',
232158
};
233159

234-
return expect(cf(testEvent)).to.eventually.deep.equal({
160+
return expect(
161+
cf(testEvent.data, testEvent.context)
162+
).to.eventually.deep.equal({
235163
foo: 'a',
236164
bar: 'b',
237165
});
@@ -256,12 +184,16 @@ describe('makeAuth and makeAuthType', () => {
256184
it('should construct correct auth and authType for admin user', () => {
257185
const testEvent = {
258186
data: 'data',
259-
auth: {
260-
admin: true,
187+
context: {
188+
auth: {
189+
admin: true,
190+
},
261191
},
262192
};
263193

264-
return expect(cf(testEvent)).to.eventually.deep.equal({
194+
return expect(
195+
cf(testEvent.data, testEvent.context)
196+
).to.eventually.deep.equal({
265197
auth: undefined,
266198
authType: 'ADMIN',
267199
});
@@ -270,33 +202,41 @@ describe('makeAuth and makeAuthType', () => {
270202
it('should construct correct auth and authType for unauthenticated user', () => {
271203
const testEvent = {
272204
data: 'data',
273-
auth: {
274-
admin: false,
205+
context: {
206+
auth: {
207+
admin: false,
208+
},
275209
},
276210
};
277211

278-
return expect(cf(testEvent)).to.eventually.deep.equal({
212+
return expect(
213+
cf(testEvent.data, testEvent.context)
214+
).to.eventually.deep.equal({
279215
auth: null,
280216
authType: 'UNAUTHENTICATED',
281217
});
282218
});
283219

284220
it('should construct correct auth and authType for a user', () => {
285-
const testEvent: LegacyEvent = {
221+
const testEvent = {
286222
data: 'data',
287-
auth: {
288-
admin: false,
289-
variable: {
290-
uid: 'user',
291-
provider: 'google',
292-
token: {
293-
sub: 'user',
223+
context: {
224+
auth: {
225+
admin: false,
226+
variable: {
227+
uid: 'user',
228+
provider: 'google',
229+
token: {
230+
sub: 'user',
231+
},
294232
},
295233
},
296234
},
297235
};
298236

299-
return expect(cf(testEvent)).to.eventually.deep.equal({
237+
return expect(
238+
cf(testEvent.data, testEvent.context)
239+
).to.eventually.deep.equal({
300240
auth: {
301241
uid: 'user',
302242
token: {

spec/providers/analytics.spec.input.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,15 @@ export const fullPayload = JSON.parse(`{
117117
}
118118
}
119119
},
120-
"eventId": "1486080145623867projects/analytics-integration-fd82a/events/i_made_this_upproviders/google.firebase.analytics/eventTypes/event.sendprojects/f949d1bb9ef782579-tp/topics/cloud-functions-u54ejabpzs4prfjh7433eklhae",
121-
"eventType": "providers/google.firebase.analytics/eventTypes/event.send",
122-
"resource": "projects/analytics-integration-fd82a/events/i_made_this_up",
123-
"timestamp": "2017-03-29T23:59:59.986371388Z"
120+
"context": {
121+
"eventId": "1486080145623867projects/analytics-integration-fd82a/events/i_made_this_upproviders/google.firebase.analytics/eventTypes/event.sendprojects/f949d1bb9ef782579-tp/topics/cloud-functions-u54ejabpzs4prfjh7433eklhae",
122+
"eventType": "providers/google.firebase.analytics/eventTypes/event.send",
123+
"timestamp": "2017-03-29T23:59:59.986371388Z",
124+
"resource": {
125+
"service": "app-measurement.com",
126+
"name": "projects/analytics-integration-fd82a/events/i_made_this_up"
127+
}
128+
}
124129
}`);
125130

126131
// The event data that we expect would be constructed if the payload above were to arrive.

0 commit comments

Comments
 (0)