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' ;
24
- import { UserRecord } from '../../../src/common/providers/identity' ;
25
- import * as functions from '../../../src/v1' ;
26
- import {
27
- CloudFunction ,
28
- Event ,
29
- EventContext ,
30
- } from '../../../src/v1/cloud-functions' ;
31
- import * as auth from '../../../src/v1/providers/auth' ;
23
+ import { expect } from "chai" ;
24
+ import { UserRecord } from "../../../src/common/providers/identity" ;
25
+ import * as functions from "../../../src/v1" ;
26
+ import { CloudFunction , Event , EventContext } from "../../../src/v1/cloud-functions" ;
27
+ import * as auth from "../../../src/v1/providers/auth" ;
32
28
33
- describe ( ' Auth Functions' , ( ) => {
29
+ describe ( " Auth Functions" , ( ) => {
34
30
const event : Event = {
35
31
data : {
36
32
metadata : {
37
- creationTime : ' 2016-12-15T19:37:37.059Z' ,
38
- lastSignInTime : ' 2017-01-01T00:00:00.000Z' ,
33
+ creationTime : " 2016-12-15T19:37:37.059Z" ,
34
+ lastSignInTime : " 2017-01-01T00:00:00.000Z" ,
39
35
} ,
40
36
} ,
41
37
context : {
42
- eventId : ' 70172329041928' ,
43
- timestamp : ' 2018-04-09T07:56:12.975Z' ,
44
- eventType : ' providers/firebase.auth/eventTypes/user.delete' ,
38
+ eventId : " 70172329041928" ,
39
+ timestamp : " 2018-04-09T07:56:12.975Z" ,
40
+ eventType : " providers/firebase.auth/eventTypes/user.delete" ,
45
41
resource : {
46
- service : ' firebaseauth.googleapis.com' ,
47
- name : ' projects/project1' ,
42
+ service : " firebaseauth.googleapis.com" ,
43
+ name : " projects/project1" ,
48
44
} ,
49
45
} ,
50
46
} ;
51
47
52
- describe ( ' AuthBuilder' , ( ) => {
48
+ describe ( " AuthBuilder" , ( ) => {
53
49
function expectedEndpoint ( project : string , eventType : string ) {
54
50
return {
55
- platform : ' gcfv1' ,
51
+ platform : " gcfv1" ,
56
52
eventTrigger : {
57
53
eventFilters : {
58
54
resource : `projects/${ project } ` ,
@@ -68,7 +64,7 @@ describe('Auth Functions', () => {
68
64
return Promise . resolve ( ) ;
69
65
} ;
70
66
71
- const project = ' project1' ;
67
+ const project = " project1" ;
72
68
73
69
before ( ( ) => {
74
70
process . env . GCLOUD_PROJECT = project ;
@@ -78,54 +74,50 @@ describe('Auth Functions', () => {
78
74
delete process . env . GCLOUD_PROJECT ;
79
75
} ) ;
80
76
81
- it ( ' should allow both region and runtime options to be set' , ( ) => {
77
+ it ( " should allow both region and runtime options to be set" , ( ) => {
82
78
const fn = functions
83
- . region ( ' us-east1' )
79
+ . region ( " us-east1" )
84
80
. runWith ( {
85
81
timeoutSeconds : 90 ,
86
- memory : ' 256MB' ,
82
+ memory : " 256MB" ,
87
83
} )
88
84
. auth . user ( )
89
85
. onCreate ( ( ) => null ) ;
90
86
91
- expect ( fn . __endpoint . region ) . to . deep . equal ( [ ' us-east1' ] ) ;
87
+ expect ( fn . __endpoint . region ) . to . deep . equal ( [ " us-east1" ] ) ;
92
88
expect ( fn . __endpoint . availableMemoryMb ) . to . deep . equal ( 256 ) ;
93
89
expect ( fn . __endpoint . timeoutSeconds ) . to . deep . equal ( 90 ) ;
94
90
95
- expect ( fn . __endpoint . region ) . to . deep . equal ( [ ' us-east1' ] ) ;
91
+ expect ( fn . __endpoint . region ) . to . deep . equal ( [ " us-east1" ] ) ;
96
92
expect ( fn . __endpoint . availableMemoryMb ) . to . deep . equal ( 256 ) ;
97
93
expect ( fn . __endpoint . timeoutSeconds ) . to . deep . equal ( 90 ) ;
98
94
} ) ;
99
95
100
- describe ( ' #onCreate' , ( ) => {
101
- it ( ' should return a trigger/endpoint with appropriate values' , ( ) => {
96
+ describe ( " #onCreate" , ( ) => {
97
+ it ( " should return a trigger/endpoint with appropriate values" , ( ) => {
102
98
const cloudFunction = auth . user ( ) . onCreate ( ( ) => null ) ;
103
99
104
- expect ( cloudFunction . __endpoint ) . to . deep . equal (
105
- expectedEndpoint ( project , 'user.create' )
106
- ) ;
100
+ expect ( cloudFunction . __endpoint ) . to . deep . equal ( expectedEndpoint ( project , "user.create" ) ) ;
107
101
} ) ;
108
102
} ) ;
109
103
110
- describe ( ' #onDelete' , ( ) => {
111
- it ( ' should return a trigger/endpoint with appropriate values' , ( ) => {
104
+ describe ( " #onDelete" , ( ) => {
105
+ it ( " should return a trigger/endpoint with appropriate values" , ( ) => {
112
106
const cloudFunction = auth . user ( ) . onDelete ( handler ) ;
113
107
114
- expect ( cloudFunction . __endpoint ) . to . deep . equal (
115
- expectedEndpoint ( project , 'user.delete' )
116
- ) ;
108
+ expect ( cloudFunction . __endpoint ) . to . deep . equal ( expectedEndpoint ( project , "user.delete" ) ) ;
117
109
} ) ;
118
110
} ) ;
119
111
120
- describe ( ' beforeCreate' , ( ) => {
121
- it ( ' should create the function without options' , ( ) => {
112
+ describe ( " beforeCreate" , ( ) => {
113
+ it ( " should create the function without options" , ( ) => {
122
114
const fn = auth . user ( ) . beforeCreate ( ( u , c ) => Promise . resolve ( ) ) ;
123
115
124
116
expect ( fn . __endpoint ) . to . deep . equal ( {
125
- platform : ' gcfv1' ,
117
+ platform : " gcfv1" ,
126
118
labels : { } ,
127
119
blockingTrigger : {
128
- eventType : ' providers/cloud.auth/eventTypes/user.beforeCreate' ,
120
+ eventType : " providers/cloud.auth/eventTypes/user.beforeCreate" ,
129
121
options : {
130
122
accessToken : false ,
131
123
idToken : false ,
@@ -135,18 +127,18 @@ describe('Auth Functions', () => {
135
127
} ) ;
136
128
expect ( fn . __requiredAPIs ) . to . deep . equal ( [
137
129
{
138
- api : ' identitytoolkit.googleapis.com' ,
139
- reason : ' Needed for auth blocking functions' ,
130
+ api : " identitytoolkit.googleapis.com" ,
131
+ reason : " Needed for auth blocking functions" ,
140
132
} ,
141
133
] ) ;
142
134
} ) ;
143
135
144
- it ( ' should create the function with options' , ( ) => {
136
+ it ( " should create the function with options" , ( ) => {
145
137
const fn = functions
146
- . region ( ' us-east1' )
138
+ . region ( " us-east1" )
147
139
. runWith ( {
148
140
timeoutSeconds : 90 ,
149
- memory : ' 256MB' ,
141
+ memory : " 256MB" ,
150
142
} )
151
143
. auth . user ( {
152
144
blockingOptions : {
@@ -157,13 +149,13 @@ describe('Auth Functions', () => {
157
149
. beforeCreate ( ( u , c ) => Promise . resolve ( ) ) ;
158
150
159
151
expect ( fn . __endpoint ) . to . deep . equal ( {
160
- platform : ' gcfv1' ,
152
+ platform : " gcfv1" ,
161
153
labels : { } ,
162
- region : [ ' us-east1' ] ,
154
+ region : [ " us-east1" ] ,
163
155
availableMemoryMb : 256 ,
164
156
timeoutSeconds : 90 ,
165
157
blockingTrigger : {
166
- eventType : ' providers/cloud.auth/eventTypes/user.beforeCreate' ,
158
+ eventType : " providers/cloud.auth/eventTypes/user.beforeCreate" ,
167
159
options : {
168
160
accessToken : true ,
169
161
idToken : false ,
@@ -173,22 +165,22 @@ describe('Auth Functions', () => {
173
165
} ) ;
174
166
expect ( fn . __requiredAPIs ) . to . deep . equal ( [
175
167
{
176
- api : ' identitytoolkit.googleapis.com' ,
177
- reason : ' Needed for auth blocking functions' ,
168
+ api : " identitytoolkit.googleapis.com" ,
169
+ reason : " Needed for auth blocking functions" ,
178
170
} ,
179
171
] ) ;
180
172
} ) ;
181
173
} ) ;
182
174
183
- describe ( ' beforeSignIn' , ( ) => {
184
- it ( ' should create the function without options' , ( ) => {
175
+ describe ( " beforeSignIn" , ( ) => {
176
+ it ( " should create the function without options" , ( ) => {
185
177
const fn = auth . user ( ) . beforeSignIn ( ( u , c ) => Promise . resolve ( ) ) ;
186
178
187
179
expect ( fn . __endpoint ) . to . deep . equal ( {
188
- platform : ' gcfv1' ,
180
+ platform : " gcfv1" ,
189
181
labels : { } ,
190
182
blockingTrigger : {
191
- eventType : ' providers/cloud.auth/eventTypes/user.beforeSignIn' ,
183
+ eventType : " providers/cloud.auth/eventTypes/user.beforeSignIn" ,
192
184
options : {
193
185
accessToken : false ,
194
186
idToken : false ,
@@ -198,18 +190,18 @@ describe('Auth Functions', () => {
198
190
} ) ;
199
191
expect ( fn . __requiredAPIs ) . to . deep . equal ( [
200
192
{
201
- api : ' identitytoolkit.googleapis.com' ,
202
- reason : ' Needed for auth blocking functions' ,
193
+ api : " identitytoolkit.googleapis.com" ,
194
+ reason : " Needed for auth blocking functions" ,
203
195
} ,
204
196
] ) ;
205
197
} ) ;
206
198
207
- it ( ' should create the function with options' , ( ) => {
199
+ it ( " should create the function with options" , ( ) => {
208
200
const fn = functions
209
- . region ( ' us-east1' )
201
+ . region ( " us-east1" )
210
202
. runWith ( {
211
203
timeoutSeconds : 90 ,
212
- memory : ' 256MB' ,
204
+ memory : " 256MB" ,
213
205
} )
214
206
. auth . user ( {
215
207
blockingOptions : {
@@ -220,13 +212,13 @@ describe('Auth Functions', () => {
220
212
. beforeSignIn ( ( u , c ) => Promise . resolve ( ) ) ;
221
213
222
214
expect ( fn . __endpoint ) . to . deep . equal ( {
223
- platform : ' gcfv1' ,
215
+ platform : " gcfv1" ,
224
216
labels : { } ,
225
- region : [ ' us-east1' ] ,
217
+ region : [ " us-east1" ] ,
226
218
availableMemoryMb : 256 ,
227
219
timeoutSeconds : 90 ,
228
220
blockingTrigger : {
229
- eventType : ' providers/cloud.auth/eventTypes/user.beforeSignIn' ,
221
+ eventType : " providers/cloud.auth/eventTypes/user.beforeSignIn" ,
230
222
options : {
231
223
accessToken : true ,
232
224
idToken : false ,
@@ -236,14 +228,14 @@ describe('Auth Functions', () => {
236
228
} ) ;
237
229
expect ( fn . __requiredAPIs ) . to . deep . equal ( [
238
230
{
239
- api : ' identitytoolkit.googleapis.com' ,
240
- reason : ' Needed for auth blocking functions' ,
231
+ api : " identitytoolkit.googleapis.com" ,
232
+ reason : " Needed for auth blocking functions" ,
241
233
} ,
242
234
] ) ;
243
235
} ) ;
244
236
} ) ;
245
237
246
- describe ( ' #_dataConstructor' , ( ) => {
238
+ describe ( " #_dataConstructor" , ( ) => {
247
239
let cloudFunctionDelete : CloudFunction < UserRecord > ;
248
240
249
241
before ( ( ) => {
@@ -252,63 +244,25 @@ describe('Auth Functions', () => {
252
244
. onDelete ( ( data : UserRecord , context : EventContext ) => data ) ;
253
245
} ) ;
254
246
255
- it ( 'should handle wire format as of v5.0.0 of firebase-admin' , ( ) => {
256
- return cloudFunctionDelete ( event . data , event . context ) . then (
257
- ( data : any ) => {
258
- expect ( data . metadata . creationTime ) . to . equal (
259
- '2016-12-15T19:37:37.059Z'
260
- ) ;
261
- expect ( data . metadata . lastSignInTime ) . to . equal (
262
- '2017-01-01T00:00:00.000Z'
263
- ) ;
264
- }
265
- ) ;
266
- } ) ;
267
- } ) ;
268
- } ) ;
269
-
270
- describe ( 'handler namespace' , ( ) => {
271
- describe ( '#onCreate' , ( ) => {
272
- it ( 'should return an empty endpoint' , ( ) => {
273
- const cloudFunction = functions . handler . auth . user . onCreate ( ( ) => null ) ;
274
- expect ( cloudFunction . __endpoint ) . to . be . undefined ;
275
- } ) ;
276
- } ) ;
277
-
278
- describe ( '#onDelete' , ( ) => {
279
- const cloudFunctionDelete : CloudFunction < UserRecord > =
280
- functions . handler . auth . user . onDelete ( ( data : UserRecord ) => data ) ;
281
-
282
- it ( 'should return an empty endpoint' , ( ) => {
283
- const cloudFunction = functions . handler . auth . user . onDelete ( ( ) => null ) ;
284
- expect ( cloudFunction . __endpoint ) . to . be . undefined ;
285
- } ) ;
286
-
287
- it ( 'should handle wire format as of v5.0.0 of firebase-admin' , ( ) => {
288
- return cloudFunctionDelete ( event . data , event . context ) . then (
289
- ( data : any ) => {
290
- expect ( data . metadata . creationTime ) . to . equal (
291
- '2016-12-15T19:37:37.059Z'
292
- ) ;
293
- expect ( data . metadata . lastSignInTime ) . to . equal (
294
- '2017-01-01T00:00:00.000Z'
295
- ) ;
296
- }
297
- ) ;
247
+ it ( "should handle wire format as of v5.0.0 of firebase-admin" , ( ) => {
248
+ return cloudFunctionDelete ( event . data , event . context ) . then ( ( data : any ) => {
249
+ expect ( data . metadata . creationTime ) . to . equal ( "2016-12-15T19:37:37.059Z" ) ;
250
+ expect ( data . metadata . lastSignInTime ) . to . equal ( "2017-01-01T00:00:00.000Z" ) ;
251
+ } ) ;
298
252
} ) ;
299
253
} ) ;
300
254
} ) ;
301
255
302
- describe ( ' process.env.GCLOUD_PROJECT not set' , ( ) => {
303
- it ( ' should not throw if __endpoint is not accessed' , ( ) => {
256
+ describe ( " process.env.GCLOUD_PROJECT not set" , ( ) => {
257
+ it ( " should not throw if __endpoint is not accessed" , ( ) => {
304
258
expect ( ( ) => auth . user ( ) . onCreate ( ( ) => null ) ) . to . not . throw ( Error ) ;
305
259
} ) ;
306
260
307
- it ( ' should throw when endpoint is accessed' , ( ) => {
261
+ it ( " should throw when endpoint is accessed" , ( ) => {
308
262
expect ( ( ) => auth . user ( ) . onCreate ( ( ) => null ) . __endpoint ) . to . throw ( Error ) ;
309
263
} ) ;
310
264
311
- it ( ' should not throw when #run is called' , ( ) => {
265
+ it ( " should not throw when #run is called" , ( ) => {
312
266
const cf = auth . user ( ) . onCreate ( ( ) => null ) ;
313
267
expect ( cf . run ) . to . not . throw ( Error ) ;
314
268
} ) ;
0 commit comments