20
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
// SOFTWARE.
22
22
23
- import { expect } from 'chai' ;
23
+ import { expect } from 'chai' ;
24
24
25
- import {
26
- wrapV2 ,
27
- } from '../src/v2' ;
25
+ import { wrapV2 } from '../src/v2' ;
28
26
29
27
import {
30
- CloudFunction , CloudEvent , alerts , pubsub , storage , eventarc
28
+ CloudFunction ,
29
+ alerts ,
30
+ pubsub ,
31
+ storage ,
32
+ eventarc ,
33
+ https ,
31
34
} from 'firebase-functions/v2' ;
32
35
33
36
describe ( 'v2' , ( ) => {
34
37
describe ( '#wrapV2' , ( ) => {
35
- const handler = ( cloudEvent ) => ( { cloudEvent} ) ;
38
+ const handler = ( cloudEvent ) => ( { cloudEvent } ) ;
36
39
37
40
describe ( 'alerts' , ( ) => {
38
41
describe ( 'alerts.onAlertPublished()' , ( ) => {
@@ -58,21 +61,27 @@ describe('v2', () => {
58
61
} ) ;
59
62
describe ( 'alerts.crashlytics.onNewNonfatalIssuePublished()' , ( ) => {
60
63
it ( 'should update CloudEvent appropriately' , ( ) => {
61
- const cloudFn = alerts . crashlytics . onNewNonfatalIssuePublished ( handler ) ;
64
+ const cloudFn = alerts . crashlytics . onNewNonfatalIssuePublished (
65
+ handler
66
+ ) ;
62
67
const cloudFnWrap = wrapV2 ( cloudFn ) ;
63
68
expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { } ) ;
64
69
} ) ;
65
70
} ) ;
66
71
describe ( 'alerts.crashlytics.onRegressionAlertPublished()' , ( ) => {
67
72
it ( 'should update CloudEvent appropriately' , ( ) => {
68
- const cloudFn = alerts . crashlytics . onRegressionAlertPublished ( handler ) ;
73
+ const cloudFn = alerts . crashlytics . onRegressionAlertPublished (
74
+ handler
75
+ ) ;
69
76
const cloudFnWrap = wrapV2 ( cloudFn ) ;
70
77
expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { } ) ;
71
78
} ) ;
72
79
} ) ;
73
80
describe ( 'alerts.crashlytics.onStabilityDigestPublished()' , ( ) => {
74
81
it ( 'should update CloudEvent appropriately' , ( ) => {
75
- const cloudFn = alerts . crashlytics . onStabilityDigestPublished ( handler ) ;
82
+ const cloudFn = alerts . crashlytics . onStabilityDigestPublished (
83
+ handler
84
+ ) ;
76
85
const cloudFnWrap = wrapV2 ( cloudFn ) ;
77
86
expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { } ) ;
78
87
} ) ;
@@ -86,14 +95,18 @@ describe('v2', () => {
86
95
} ) ;
87
96
describe ( 'alerts.appDistribution.onNewTesterIosDevicePublished()' , ( ) => {
88
97
it ( 'should update CloudEvent appropriately' , ( ) => {
89
- const cloudFn = alerts . appDistribution . onNewTesterIosDevicePublished ( handler ) ;
98
+ const cloudFn = alerts . appDistribution . onNewTesterIosDevicePublished (
99
+ handler
100
+ ) ;
90
101
const cloudFnWrap = wrapV2 ( cloudFn ) ;
91
102
expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { } ) ;
92
103
} ) ;
93
104
} ) ;
94
105
describe ( 'alerts.billing.onPlanAutomatedUpdatePublished()' , ( ) => {
95
106
it ( 'should update CloudEvent appropriately' , ( ) => {
96
- const cloudFn = alerts . billing . onPlanAutomatedUpdatePublished ( handler ) ;
107
+ const cloudFn = alerts . billing . onPlanAutomatedUpdatePublished (
108
+ handler
109
+ ) ;
97
110
const cloudFnWrap = wrapV2 ( cloudFn ) ;
98
111
expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { } ) ;
99
112
} ) ;
@@ -113,7 +126,7 @@ describe('v2', () => {
113
126
const eventType = 'EVENT_TYPE' ;
114
127
const cloudFn = eventarc . onCustomEventPublished ( eventType , handler ) ;
115
128
const cloudFnWrap = wrapV2 ( cloudFn ) ;
116
- expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { type : eventType } ) ;
129
+ expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { type : eventType } ) ;
117
130
} ) ;
118
131
} ) ;
119
132
} ) ;
@@ -162,44 +175,50 @@ describe('v2', () => {
162
175
it ( 'should update CloudEvent with json data override' , ( ) => {
163
176
const data = {
164
177
message : {
165
- json : { firebase : 'test' }
178
+ json : { firebase : 'test' } ,
166
179
} ,
167
- subscription : 'subscription'
180
+ subscription : 'subscription' ,
168
181
} ;
169
182
const cloudFn = pubsub . onMessagePublished ( 'topic' , handler ) ;
170
183
const cloudFnWrap = wrapV2 ( cloudFn ) ;
171
- const cloudEventPartial = { data} ;
184
+ const cloudEventPartial = { data } ;
172
185
173
- expect ( cloudFnWrap ( cloudEventPartial ) . cloudEvent . data . message ) . to . include ( {
186
+ expect (
187
+ cloudFnWrap ( cloudEventPartial ) . cloudEvent . data . message
188
+ ) . to . include ( {
174
189
data : 'eyJoZWxsbyI6IndvcmxkIn0=' , // Note: This is a mismatch from the json
175
190
} ) ;
176
- expect ( cloudFnWrap ( cloudEventPartial ) . cloudEvent . data . message . json ) . to . include ( { firebase : 'test' } ) ;
191
+ expect (
192
+ cloudFnWrap ( cloudEventPartial ) . cloudEvent . data . message . json
193
+ ) . to . include ( { firebase : 'test' } ) ;
177
194
} ) ;
178
195
it ( 'should update CloudEvent with json and data string overrides' , ( ) => {
179
196
const data = {
180
197
message : {
181
198
data : 'eyJmaXJlYmFzZSI6Im5vbl9qc29uX3Rlc3QifQ==' ,
182
- json : { firebase : 'non_json_test' } ,
199
+ json : { firebase : 'non_json_test' } ,
183
200
} ,
184
- subscription : 'subscription'
201
+ subscription : 'subscription' ,
185
202
} ;
186
203
const cloudFn = pubsub . onMessagePublished ( 'topic' , handler ) ;
187
204
const cloudFnWrap = wrapV2 ( cloudFn ) ;
188
- const cloudEventPartial = { data} ;
205
+ const cloudEventPartial = { data } ;
189
206
190
- expect ( cloudFnWrap ( cloudEventPartial ) . cloudEvent . data . message ) . to . include ( {
207
+ expect (
208
+ cloudFnWrap ( cloudEventPartial ) . cloudEvent . data . message
209
+ ) . to . include ( {
191
210
data : 'eyJmaXJlYmFzZSI6Im5vbl9qc29uX3Rlc3QifQ==' ,
192
211
} ) ;
193
- expect ( cloudFnWrap ( cloudEventPartial ) . cloudEvent . data . message . json )
194
- . to . include ( { firebase : 'non_json_test' } ) ;
212
+ expect (
213
+ cloudFnWrap ( cloudEventPartial ) . cloudEvent . data . message . json
214
+ ) . to . include ( { firebase : 'non_json_test' } ) ;
195
215
} ) ;
196
216
} ) ;
197
217
} ) ;
198
218
199
219
describe ( 'callable functions' , ( ) => {
200
220
it ( 'return an error because they are not supported' , ( ) => {
201
- const cloudFunction = ( input ) => input ;
202
- cloudFunction . run = ( cloudEvent : CloudEvent ) => ( { cloudEvent} ) ;
221
+ const cloudFunction = https . onCall ( ( data ) => data ) ;
203
222
cloudFunction . __endpoint = {
204
223
platform : 'gcfv2' ,
205
224
labels : { } ,
@@ -210,11 +229,12 @@ describe('v2', () => {
210
229
} ;
211
230
212
231
try {
213
- const wrappedCF = wrapV2 ( cloudFunction as CloudFunction < any > ) ;
232
+ const wrappedCF = wrapV2 ( cloudFunction as any ) ;
214
233
wrappedCF ( ) ;
215
234
} catch ( e ) {
216
235
expect ( e . message ) . to . equal (
217
- 'Wrap function is not available for callableTriggers functions.' ) ;
236
+ 'Wrap function is not available for callableTriggers functions.'
237
+ ) ;
218
238
}
219
239
} ) ;
220
240
} ) ;
@@ -223,17 +243,18 @@ describe('v2', () => {
223
243
it ( 'should create CloudEvent with appropriate fields for pubsub.onMessagePublished()' , ( ) => {
224
244
const data = {
225
245
message : {
226
- json : '{"hello_firebase": "world_firebase"}'
246
+ json : '{"hello_firebase": "world_firebase"}' ,
227
247
} ,
228
- subscription : 'subscription'
248
+ subscription : 'subscription' ,
229
249
} ;
230
250
const cloudFn = pubsub . onMessagePublished ( 'topic' , handler ) ;
231
- const cloudEvent = wrapV2 ( cloudFn ) ( { data} ) . cloudEvent ;
251
+ const cloudEvent = wrapV2 ( cloudFn ) ( { data } ) . cloudEvent ;
232
252
233
253
expect ( cloudEvent . type ) . equal (
234
- 'google.cloud.pubsub.topic.v1.messagePublished' ) ;
254
+ 'google.cloud.pubsub.topic.v1.messagePublished'
255
+ ) ;
235
256
expect ( cloudEvent . data . message ) . to . include ( {
236
- json : '{"hello_firebase": "world_firebase"}'
257
+ json : '{"hello_firebase": "world_firebase"}' ,
237
258
} ) ;
238
259
} ) ;
239
260
it ( 'should generate source from original CloudFunction' , ( ) => {
@@ -283,15 +304,17 @@ describe('v2', () => {
283
304
const cloudEventOverride = {
284
305
data : {
285
306
contentType : 'application/octet-stream' ,
286
- }
307
+ } ,
287
308
} ;
288
309
289
310
const bucketName = 'bucket_name' ;
290
311
const cloudFn = storage . onObjectArchived ( bucketName , handler ) ;
291
312
292
313
const mergedCloudEvent = wrapV2 ( cloudFn ) ( cloudEventOverride ) . cloudEvent ;
293
314
expect ( mergedCloudEvent . data ?. size ) . equal ( 42 ) ;
294
- expect ( mergedCloudEvent . data ?. contentType ) . equal ( 'application/octet-stream' ) ;
315
+ expect ( mergedCloudEvent . data ?. contentType ) . equal (
316
+ 'application/octet-stream'
317
+ ) ;
295
318
} ) ;
296
319
} ) ;
297
320
} ) ;
0 commit comments