@@ -51,12 +51,38 @@ describe('Auth Functions', () => {
51
51
} ;
52
52
53
53
describe ( 'AuthBuilder' , ( ) => {
54
+ function expectedTrigger ( project : string , eventType : string ) {
55
+ return {
56
+ eventTrigger : {
57
+ resource : `projects/${ project } ` ,
58
+ eventType : `providers/firebase.auth/eventTypes/${ eventType } ` ,
59
+ service : 'firebaseauth.googleapis.com' ,
60
+ } ,
61
+ } ;
62
+ }
63
+
64
+ function expectedEndpoint ( project : string , eventType : string ) {
65
+ return {
66
+ platform : 'gcfv1' ,
67
+ eventTrigger : {
68
+ eventFilters : {
69
+ resource : `projects/${ project } ` ,
70
+ } ,
71
+ eventType : `providers/firebase.auth/eventTypes/${ eventType } ` ,
72
+ retry : false ,
73
+ } ,
74
+ labels : { } ,
75
+ } ;
76
+ }
77
+
54
78
const handler = ( user : firebase . auth . UserRecord ) => {
55
79
return Promise . resolve ( ) ;
56
80
} ;
57
81
82
+ const project = 'project1' ;
83
+
58
84
before ( ( ) => {
59
- process . env . GCLOUD_PROJECT = 'project1' ;
85
+ process . env . GCLOUD_PROJECT = project ;
60
86
} ) ;
61
87
62
88
after ( ( ) => {
@@ -76,31 +102,37 @@ describe('Auth Functions', () => {
76
102
expect ( fn . __trigger . regions ) . to . deep . equal ( [ 'us-east1' ] ) ;
77
103
expect ( fn . __trigger . availableMemoryMb ) . to . deep . equal ( 256 ) ;
78
104
expect ( fn . __trigger . timeout ) . to . deep . equal ( '90s' ) ;
105
+
106
+ expect ( fn . __endpoint . region ) . to . deep . equal ( [ 'us-east1' ] ) ;
107
+ expect ( fn . __endpoint . availableMemoryMb ) . to . deep . equal ( 256 ) ;
108
+ expect ( fn . __endpoint . timeoutSeconds ) . to . deep . equal ( 90 ) ;
79
109
} ) ;
80
110
81
111
describe ( '#onCreate' , ( ) => {
82
- it ( 'should return a TriggerDefinition with appropriate values' , ( ) => {
112
+ it ( 'should return a trigger/endpoint with appropriate values' , ( ) => {
83
113
const cloudFunction = auth . user ( ) . onCreate ( ( ) => null ) ;
84
- expect ( cloudFunction . __trigger ) . to . deep . equal ( {
85
- eventTrigger : {
86
- eventType : 'providers/firebase.auth/eventTypes/user.create' ,
87
- resource : 'projects/project1' ,
88
- service : 'firebaseauth.googleapis.com' ,
89
- } ,
90
- } ) ;
114
+
115
+ expect ( cloudFunction . __trigger ) . to . deep . equal (
116
+ expectedTrigger ( project , 'user.create' )
117
+ ) ;
118
+
119
+ expect ( cloudFunction . __endpoint ) . to . deep . equal (
120
+ expectedEndpoint ( project , 'user.create' )
121
+ ) ;
91
122
} ) ;
92
123
} ) ;
93
124
94
125
describe ( '#onDelete' , ( ) => {
95
- it ( 'should return a TriggerDefinition with appropriate values' , ( ) => {
126
+ it ( 'should return a trigger/endpoint with appropriate values' , ( ) => {
96
127
const cloudFunction = auth . user ( ) . onDelete ( handler ) ;
97
- expect ( cloudFunction . __trigger ) . to . deep . equal ( {
98
- eventTrigger : {
99
- eventType : 'providers/firebase.auth/eventTypes/user.delete' ,
100
- resource : 'projects/project1' ,
101
- service : 'firebaseauth.googleapis.com' ,
102
- } ,
103
- } ) ;
128
+
129
+ expect ( cloudFunction . __trigger ) . to . deep . equal (
130
+ expectedTrigger ( project , 'user.delete' )
131
+ ) ;
132
+
133
+ expect ( cloudFunction . __endpoint ) . to . deep . equal (
134
+ expectedEndpoint ( project , 'user.delete' )
135
+ ) ;
104
136
} ) ;
105
137
} ) ;
106
138
@@ -198,6 +230,11 @@ describe('Auth Functions', () => {
198
230
const cloudFunction = functions . handler . auth . user . onCreate ( ( ) => null ) ;
199
231
expect ( cloudFunction . __trigger ) . to . deep . equal ( { } ) ;
200
232
} ) ;
233
+
234
+ it ( 'should return an empty endpoint' , ( ) => {
235
+ const cloudFunction = functions . handler . auth . user . onCreate ( ( ) => null ) ;
236
+ expect ( cloudFunction . __endpoint ) . to . be . undefined ;
237
+ } ) ;
201
238
} ) ;
202
239
203
240
describe ( '#onDelete' , ( ) => {
@@ -206,13 +243,15 @@ describe('Auth Functions', () => {
206
243
) ;
207
244
208
245
it ( 'should return an empty trigger' , ( ) => {
209
- const handler = ( user : firebase . auth . UserRecord ) => {
210
- return Promise . resolve ( ) ;
211
- } ;
212
- const cloudFunction = functions . handler . auth . user . onDelete ( handler ) ;
246
+ const cloudFunction = functions . handler . auth . user . onDelete ( ( ) => null ) ;
213
247
expect ( cloudFunction . __trigger ) . to . deep . equal ( { } ) ;
214
248
} ) ;
215
249
250
+ it ( 'should return an empty endpoint' , ( ) => {
251
+ const cloudFunction = functions . handler . auth . user . onDelete ( ( ) => null ) ;
252
+ expect ( cloudFunction . __endpoint ) . to . be . undefined ;
253
+ } ) ;
254
+
216
255
it ( 'should handle wire format as of v5.0.0 of firebase-admin' , ( ) => {
217
256
return cloudFunctionDelete ( event . data , event . context ) . then (
218
257
( data : any ) => {
@@ -237,6 +276,10 @@ describe('Auth Functions', () => {
237
276
expect ( ( ) => auth . user ( ) . onCreate ( ( ) => null ) . __trigger ) . to . throw ( Error ) ;
238
277
} ) ;
239
278
279
+ it ( 'should throw when endpoint is accessed' , ( ) => {
280
+ expect ( ( ) => auth . user ( ) . onCreate ( ( ) => null ) . __endpoint ) . to . throw ( Error ) ;
281
+ } ) ;
282
+
240
283
it ( 'should not throw when #run is called' , ( ) => {
241
284
const cf = auth . user ( ) . onCreate ( ( ) => null ) ;
242
285
expect ( cf . run ) . to . not . throw ( Error ) ;
0 commit comments