@@ -51,12 +51,38 @@ describe('Auth Functions', () => {
5151 } ;
5252
5353 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+
5478 const handler = ( user : firebase . auth . UserRecord ) => {
5579 return Promise . resolve ( ) ;
5680 } ;
5781
82+ const project = 'project1' ;
83+
5884 before ( ( ) => {
59- process . env . GCLOUD_PROJECT = 'project1' ;
85+ process . env . GCLOUD_PROJECT = project ;
6086 } ) ;
6187
6288 after ( ( ) => {
@@ -76,31 +102,37 @@ describe('Auth Functions', () => {
76102 expect ( fn . __trigger . regions ) . to . deep . equal ( [ 'us-east1' ] ) ;
77103 expect ( fn . __trigger . availableMemoryMb ) . to . deep . equal ( 256 ) ;
78104 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 ) ;
79109 } ) ;
80110
81111 describe ( '#onCreate' , ( ) => {
82- it ( 'should return a TriggerDefinition with appropriate values' , ( ) => {
112+ it ( 'should return a trigger/endpoint with appropriate values' , ( ) => {
83113 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+ ) ;
91122 } ) ;
92123 } ) ;
93124
94125 describe ( '#onDelete' , ( ) => {
95- it ( 'should return a TriggerDefinition with appropriate values' , ( ) => {
126+ it ( 'should return a trigger/endpoint with appropriate values' , ( ) => {
96127 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+ ) ;
104136 } ) ;
105137 } ) ;
106138
@@ -198,6 +230,11 @@ describe('Auth Functions', () => {
198230 const cloudFunction = functions . handler . auth . user . onCreate ( ( ) => null ) ;
199231 expect ( cloudFunction . __trigger ) . to . deep . equal ( { } ) ;
200232 } ) ;
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+ } ) ;
201238 } ) ;
202239
203240 describe ( '#onDelete' , ( ) => {
@@ -206,13 +243,15 @@ describe('Auth Functions', () => {
206243 ) ;
207244
208245 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 ) ;
213247 expect ( cloudFunction . __trigger ) . to . deep . equal ( { } ) ;
214248 } ) ;
215249
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+
216255 it ( 'should handle wire format as of v5.0.0 of firebase-admin' , ( ) => {
217256 return cloudFunctionDelete ( event . data , event . context ) . then (
218257 ( data : any ) => {
@@ -237,6 +276,10 @@ describe('Auth Functions', () => {
237276 expect ( ( ) => auth . user ( ) . onCreate ( ( ) => null ) . __trigger ) . to . throw ( Error ) ;
238277 } ) ;
239278
279+ it ( 'should throw when endpoint is accessed' , ( ) => {
280+ expect ( ( ) => auth . user ( ) . onCreate ( ( ) => null ) . __endpoint ) . to . throw ( Error ) ;
281+ } ) ;
282+
240283 it ( 'should not throw when #run is called' , ( ) => {
241284 const cf = auth . user ( ) . onCreate ( ( ) => null ) ;
242285 expect ( cf . run ) . to . not . throw ( Error ) ;
0 commit comments