2020// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121// SOFTWARE.
2222
23- import { expect } from 'chai' ;
23+ import { expect } from 'chai' ;
2424
25- import {
26- wrapV2 ,
27- } from '../src/v2' ;
25+ import { wrapV2 } from '../src/v2' ;
2826
2927import {
30- CloudFunction , CloudEvent , alerts , pubsub , storage , eventarc
28+ CloudFunction ,
29+ alerts ,
30+ pubsub ,
31+ storage ,
32+ eventarc ,
33+ https ,
3134} from 'firebase-functions/v2' ;
3235
3336describe ( 'v2' , ( ) => {
3437 describe ( '#wrapV2' , ( ) => {
35- const handler = ( cloudEvent ) => ( { cloudEvent} ) ;
38+ const handler = ( cloudEvent ) => ( { cloudEvent } ) ;
3639
3740 describe ( 'alerts' , ( ) => {
3841 describe ( 'alerts.onAlertPublished()' , ( ) => {
@@ -58,21 +61,27 @@ describe('v2', () => {
5861 } ) ;
5962 describe ( 'alerts.crashlytics.onNewNonfatalIssuePublished()' , ( ) => {
6063 it ( 'should update CloudEvent appropriately' , ( ) => {
61- const cloudFn = alerts . crashlytics . onNewNonfatalIssuePublished ( handler ) ;
64+ const cloudFn = alerts . crashlytics . onNewNonfatalIssuePublished (
65+ handler
66+ ) ;
6267 const cloudFnWrap = wrapV2 ( cloudFn ) ;
6368 expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { } ) ;
6469 } ) ;
6570 } ) ;
6671 describe ( 'alerts.crashlytics.onRegressionAlertPublished()' , ( ) => {
6772 it ( 'should update CloudEvent appropriately' , ( ) => {
68- const cloudFn = alerts . crashlytics . onRegressionAlertPublished ( handler ) ;
73+ const cloudFn = alerts . crashlytics . onRegressionAlertPublished (
74+ handler
75+ ) ;
6976 const cloudFnWrap = wrapV2 ( cloudFn ) ;
7077 expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { } ) ;
7178 } ) ;
7279 } ) ;
7380 describe ( 'alerts.crashlytics.onStabilityDigestPublished()' , ( ) => {
7481 it ( 'should update CloudEvent appropriately' , ( ) => {
75- const cloudFn = alerts . crashlytics . onStabilityDigestPublished ( handler ) ;
82+ const cloudFn = alerts . crashlytics . onStabilityDigestPublished (
83+ handler
84+ ) ;
7685 const cloudFnWrap = wrapV2 ( cloudFn ) ;
7786 expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { } ) ;
7887 } ) ;
@@ -86,14 +95,18 @@ describe('v2', () => {
8695 } ) ;
8796 describe ( 'alerts.appDistribution.onNewTesterIosDevicePublished()' , ( ) => {
8897 it ( 'should update CloudEvent appropriately' , ( ) => {
89- const cloudFn = alerts . appDistribution . onNewTesterIosDevicePublished ( handler ) ;
98+ const cloudFn = alerts . appDistribution . onNewTesterIosDevicePublished (
99+ handler
100+ ) ;
90101 const cloudFnWrap = wrapV2 ( cloudFn ) ;
91102 expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { } ) ;
92103 } ) ;
93104 } ) ;
94105 describe ( 'alerts.billing.onPlanAutomatedUpdatePublished()' , ( ) => {
95106 it ( 'should update CloudEvent appropriately' , ( ) => {
96- const cloudFn = alerts . billing . onPlanAutomatedUpdatePublished ( handler ) ;
107+ const cloudFn = alerts . billing . onPlanAutomatedUpdatePublished (
108+ handler
109+ ) ;
97110 const cloudFnWrap = wrapV2 ( cloudFn ) ;
98111 expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { } ) ;
99112 } ) ;
@@ -113,7 +126,7 @@ describe('v2', () => {
113126 const eventType = 'EVENT_TYPE' ;
114127 const cloudFn = eventarc . onCustomEventPublished ( eventType , handler ) ;
115128 const cloudFnWrap = wrapV2 ( cloudFn ) ;
116- expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { type : eventType } ) ;
129+ expect ( cloudFnWrap ( ) . cloudEvent ) . to . include ( { type : eventType } ) ;
117130 } ) ;
118131 } ) ;
119132 } ) ;
@@ -162,44 +175,50 @@ describe('v2', () => {
162175 it ( 'should update CloudEvent with json data override' , ( ) => {
163176 const data = {
164177 message : {
165- json : { firebase : 'test' }
178+ json : { firebase : 'test' } ,
166179 } ,
167- subscription : 'subscription'
180+ subscription : 'subscription' ,
168181 } ;
169182 const cloudFn = pubsub . onMessagePublished ( 'topic' , handler ) ;
170183 const cloudFnWrap = wrapV2 ( cloudFn ) ;
171- const cloudEventPartial = { data} ;
184+ const cloudEventPartial = { data } ;
172185
173- expect ( cloudFnWrap ( cloudEventPartial ) . cloudEvent . data . message ) . to . include ( {
186+ expect (
187+ cloudFnWrap ( cloudEventPartial ) . cloudEvent . data . message
188+ ) . to . include ( {
174189 data : 'eyJoZWxsbyI6IndvcmxkIn0=' , // Note: This is a mismatch from the json
175190 } ) ;
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' } ) ;
177194 } ) ;
178195 it ( 'should update CloudEvent with json and data string overrides' , ( ) => {
179196 const data = {
180197 message : {
181198 data : 'eyJmaXJlYmFzZSI6Im5vbl9qc29uX3Rlc3QifQ==' ,
182- json : { firebase : 'non_json_test' } ,
199+ json : { firebase : 'non_json_test' } ,
183200 } ,
184- subscription : 'subscription'
201+ subscription : 'subscription' ,
185202 } ;
186203 const cloudFn = pubsub . onMessagePublished ( 'topic' , handler ) ;
187204 const cloudFnWrap = wrapV2 ( cloudFn ) ;
188- const cloudEventPartial = { data} ;
205+ const cloudEventPartial = { data } ;
189206
190- expect ( cloudFnWrap ( cloudEventPartial ) . cloudEvent . data . message ) . to . include ( {
207+ expect (
208+ cloudFnWrap ( cloudEventPartial ) . cloudEvent . data . message
209+ ) . to . include ( {
191210 data : 'eyJmaXJlYmFzZSI6Im5vbl9qc29uX3Rlc3QifQ==' ,
192211 } ) ;
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' } ) ;
195215 } ) ;
196216 } ) ;
197217 } ) ;
198218
199219 describe ( 'callable functions' , ( ) => {
200220 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 ) ;
203222 cloudFunction . __endpoint = {
204223 platform : 'gcfv2' ,
205224 labels : { } ,
@@ -210,11 +229,12 @@ describe('v2', () => {
210229 } ;
211230
212231 try {
213- const wrappedCF = wrapV2 ( cloudFunction as CloudFunction < any > ) ;
232+ const wrappedCF = wrapV2 ( cloudFunction as any ) ;
214233 wrappedCF ( ) ;
215234 } catch ( e ) {
216235 expect ( e . message ) . to . equal (
217- 'Wrap function is not available for callableTriggers functions.' ) ;
236+ 'Wrap function is not available for callableTriggers functions.'
237+ ) ;
218238 }
219239 } ) ;
220240 } ) ;
@@ -223,17 +243,18 @@ describe('v2', () => {
223243 it ( 'should create CloudEvent with appropriate fields for pubsub.onMessagePublished()' , ( ) => {
224244 const data = {
225245 message : {
226- json : '{"hello_firebase": "world_firebase"}'
246+ json : '{"hello_firebase": "world_firebase"}' ,
227247 } ,
228- subscription : 'subscription'
248+ subscription : 'subscription' ,
229249 } ;
230250 const cloudFn = pubsub . onMessagePublished ( 'topic' , handler ) ;
231- const cloudEvent = wrapV2 ( cloudFn ) ( { data} ) . cloudEvent ;
251+ const cloudEvent = wrapV2 ( cloudFn ) ( { data } ) . cloudEvent ;
232252
233253 expect ( cloudEvent . type ) . equal (
234- 'google.cloud.pubsub.topic.v1.messagePublished' ) ;
254+ 'google.cloud.pubsub.topic.v1.messagePublished'
255+ ) ;
235256 expect ( cloudEvent . data . message ) . to . include ( {
236- json : '{"hello_firebase": "world_firebase"}'
257+ json : '{"hello_firebase": "world_firebase"}' ,
237258 } ) ;
238259 } ) ;
239260 it ( 'should generate source from original CloudFunction' , ( ) => {
@@ -283,15 +304,17 @@ describe('v2', () => {
283304 const cloudEventOverride = {
284305 data : {
285306 contentType : 'application/octet-stream' ,
286- }
307+ } ,
287308 } ;
288309
289310 const bucketName = 'bucket_name' ;
290311 const cloudFn = storage . onObjectArchived ( bucketName , handler ) ;
291312
292313 const mergedCloudEvent = wrapV2 ( cloudFn ) ( cloudEventOverride ) . cloudEvent ;
293314 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+ ) ;
295318 } ) ;
296319 } ) ;
297320 } ) ;
0 commit comments