@@ -38,10 +38,17 @@ describe('makeCloudFunction', () => {
3838 service : 'service' ,
3939 triggerResource : ( ) => 'resource' ,
4040 handler : ( ) => null ,
41+ legacyEventType : 'providers/provider/eventTypes/event' ,
4142 } ;
4243
4344 it ( 'should put a __trigger on the returned CloudFunction' , ( ) => {
44- let cf = makeCloudFunction ( cloudFunctionArgs ) ;
45+ let cf = makeCloudFunction ( {
46+ provider : 'mock.provider' ,
47+ eventType : 'mock.event' ,
48+ service : 'service' ,
49+ triggerResource : ( ) => 'resource' ,
50+ handler : ( ) => null ,
51+ } ) ;
4552 expect ( cf . __trigger ) . to . deep . equal ( {
4653 eventTrigger : {
4754 eventType : 'mock.provider.mock.event' ,
@@ -51,6 +58,17 @@ describe('makeCloudFunction', () => {
5158 } ) ;
5259 } ) ;
5360
61+ it ( 'should have legacy event type in __trigger if provided' , ( ) => {
62+ let cf = makeCloudFunction ( cloudFunctionArgs ) ;
63+ expect ( cf . __trigger ) . to . deep . equal ( {
64+ eventTrigger : {
65+ eventType : 'providers/provider/eventTypes/event' ,
66+ resource : 'resource' ,
67+ service : 'service' ,
68+ } ,
69+ } ) ;
70+ } ) ;
71+
5472 it ( 'should construct the right context for legacy event format' , ( ) => {
5573 let args : any = _ . assign ( { } , cloudFunctionArgs , {
5674 handler : ( data : any , context : EventContext ) => context ,
@@ -105,6 +123,39 @@ describe('makeCloudFunction', () => {
105123 params : { } ,
106124 } ) ;
107125 } ) ;
126+
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+ let cf = makeCloudFunction ( args ) ;
134+ let testContext = {
135+ eventId : '00000' ,
136+ timestamp : '2016-11-04T21:29:03.496Z' ,
137+ eventType : 'provider.event' ,
138+ resource : {
139+ service : 'provider' ,
140+ name : 'resource' ,
141+ } ,
142+ } ;
143+ let testData = 'data' ;
144+
145+ return expect ( cf ( testData , testContext ) ) . to . eventually . deep . equal ( {
146+ data : 'data' ,
147+ context : {
148+ eventId : '00000' ,
149+ timestamp : '2016-11-04T21:29:03.496Z' ,
150+ eventType : 'provider.event' ,
151+ resource : {
152+ service : 'provider' ,
153+ name : 'resource' ,
154+ } ,
155+ params : { } ,
156+ } ,
157+ } ) ;
158+ } ) ;
108159} ) ;
109160
110161describe ( 'makeParams' , ( ) => {
@@ -114,13 +165,14 @@ describe('makeParams', () => {
114165 service : 'service' ,
115166 triggerResource : ( ) => 'projects/_/instances/pid/ref/{foo}/nested/{bar}' ,
116167 handler : ( data , context ) => context . params ,
168+ legacyEventType : 'legacyEvent' ,
117169 } ;
118170 const cf = makeCloudFunction ( args ) ;
119171
120172 it ( 'should construct params from the event resource of legacy events' , ( ) => {
121173 const testEvent : LegacyEvent = {
122174 resource : 'projects/_/instances/pid/ref/a/nested/b' ,
123- eventType : 'event ' ,
175+ eventType : 'legacyEvent ' ,
124176 data : 'data' ,
125177 } ;
126178
@@ -160,14 +212,14 @@ describe('makeAuth and makeAuthType', () => {
160212 handler : ( data , context ) => {
161213 return {
162214 auth : context . auth ,
163- authMode : context . authType ,
215+ authType : context . authType ,
164216 } ;
165217 } ,
166218 } ;
167219 let cf = makeCloudFunction ( args ) ;
168220
169221 it ( 'should construct correct auth and authType for admin user' , ( ) => {
170- const testEvent : LegacyEvent = {
222+ const testEvent = {
171223 data : 'data' ,
172224 auth : {
173225 admin : true ,
@@ -176,12 +228,12 @@ describe('makeAuth and makeAuthType', () => {
176228
177229 return expect ( cf ( testEvent ) ) . to . eventually . deep . equal ( {
178230 auth : undefined ,
179- authMode : 'ADMIN' ,
231+ authType : 'ADMIN' ,
180232 } ) ;
181233 } ) ;
182234
183235 it ( 'should construct correct auth and authType for unauthenticated user' , ( ) => {
184- const testEvent : LegacyEvent = {
236+ const testEvent = {
185237 data : 'data' ,
186238 auth : {
187239 admin : false ,
@@ -190,7 +242,7 @@ describe('makeAuth and makeAuthType', () => {
190242
191243 return expect ( cf ( testEvent ) ) . to . eventually . deep . equal ( {
192244 auth : null ,
193- authMode : 'UNAUTHENTICATED' ,
245+ authType : 'UNAUTHENTICATED' ,
194246 } ) ;
195247 } ) ;
196248
@@ -216,7 +268,7 @@ describe('makeAuth and makeAuthType', () => {
216268 sub : 'user' ,
217269 } ,
218270 } ,
219- authMode : 'USER' ,
271+ authType : 'USER' ,
220272 } ) ;
221273 } ) ;
222274} ) ;
0 commit comments