@@ -25,7 +25,6 @@ import { expect } from 'chai';
2525import {
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 : {
0 commit comments