@@ -25,7 +25,6 @@ import { expect } from 'chai';
25
25
import {
26
26
Event ,
27
27
EventContext ,
28
- LegacyEvent ,
29
28
makeCloudFunction ,
30
29
MakeCloudFunctionArgs ,
31
30
Change ,
@@ -69,32 +68,7 @@ describe('makeCloudFunction', () => {
69
68
} ) ;
70
69
} ) ;
71
70
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' , ( ) => {
98
72
let args : any = _ . assign ( { } , cloudFunctionArgs , {
99
73
handler : ( data : any , context : EventContext ) => context ,
100
74
} ) ;
@@ -112,7 +86,7 @@ describe('makeCloudFunction', () => {
112
86
data : 'data' ,
113
87
} ;
114
88
115
- return expect ( cf ( test ) ) . to . eventually . deep . equal ( {
89
+ return expect ( cf ( test . data , test . context ) ) . to . eventually . deep . equal ( {
116
90
eventId : '00000' ,
117
91
timestamp : '2016-11-04T21:29:03.496Z' ,
118
92
eventType : 'provider.event' ,
@@ -124,41 +98,6 @@ describe('makeCloudFunction', () => {
124
98
} ) ;
125
99
} ) ;
126
100
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
-
162
101
it ( 'should throw error when context.params accessed in handler environment' , ( ) => {
163
102
let args : any = _ . assign ( { } , cloudFunctionArgs , {
164
103
handler : ( data : any , context : EventContext ) => context ,
@@ -178,7 +117,7 @@ describe('makeCloudFunction', () => {
178
117
data : 'test data' ,
179
118
} ;
180
119
181
- return cf ( test ) . then ( result => {
120
+ return cf ( test . data , test . context ) . then ( result => {
182
121
expect ( result ) . to . deep . equal ( {
183
122
eventId : '00000' ,
184
123
timestamp : '2016-11-04T21:29:03.496Z' ,
@@ -204,20 +143,7 @@ describe('makeParams', () => {
204
143
} ;
205
144
const cf = makeCloudFunction ( args ) ;
206
145
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' , ( ) => {
221
147
const testEvent : Event = {
222
148
context : {
223
149
eventId : '111' ,
@@ -231,7 +157,9 @@ describe('makeParams', () => {
231
157
data : 'data' ,
232
158
} ;
233
159
234
- return expect ( cf ( testEvent ) ) . to . eventually . deep . equal ( {
160
+ return expect (
161
+ cf ( testEvent . data , testEvent . context )
162
+ ) . to . eventually . deep . equal ( {
235
163
foo : 'a' ,
236
164
bar : 'b' ,
237
165
} ) ;
@@ -256,12 +184,16 @@ describe('makeAuth and makeAuthType', () => {
256
184
it ( 'should construct correct auth and authType for admin user' , ( ) => {
257
185
const testEvent = {
258
186
data : 'data' ,
259
- auth : {
260
- admin : true ,
187
+ context : {
188
+ auth : {
189
+ admin : true ,
190
+ } ,
261
191
} ,
262
192
} ;
263
193
264
- return expect ( cf ( testEvent ) ) . to . eventually . deep . equal ( {
194
+ return expect (
195
+ cf ( testEvent . data , testEvent . context )
196
+ ) . to . eventually . deep . equal ( {
265
197
auth : undefined ,
266
198
authType : 'ADMIN' ,
267
199
} ) ;
@@ -270,33 +202,41 @@ describe('makeAuth and makeAuthType', () => {
270
202
it ( 'should construct correct auth and authType for unauthenticated user' , ( ) => {
271
203
const testEvent = {
272
204
data : 'data' ,
273
- auth : {
274
- admin : false ,
205
+ context : {
206
+ auth : {
207
+ admin : false ,
208
+ } ,
275
209
} ,
276
210
} ;
277
211
278
- return expect ( cf ( testEvent ) ) . to . eventually . deep . equal ( {
212
+ return expect (
213
+ cf ( testEvent . data , testEvent . context )
214
+ ) . to . eventually . deep . equal ( {
279
215
auth : null ,
280
216
authType : 'UNAUTHENTICATED' ,
281
217
} ) ;
282
218
} ) ;
283
219
284
220
it ( 'should construct correct auth and authType for a user' , ( ) => {
285
- const testEvent : LegacyEvent = {
221
+ const testEvent = {
286
222
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
+ } ,
294
232
} ,
295
233
} ,
296
234
} ,
297
235
} ;
298
236
299
- return expect ( cf ( testEvent ) ) . to . eventually . deep . equal ( {
237
+ return expect (
238
+ cf ( testEvent . data , testEvent . context )
239
+ ) . to . eventually . deep . equal ( {
300
240
auth : {
301
241
uid : 'user' ,
302
242
token : {
0 commit comments