@@ -35,6 +35,7 @@ import {
3535import { runHandler } from "../../helper" ;
3636import { MINIMAL_V1_ENDPOINT } from "../../fixtures" ;
3737import { CALLABLE_AUTH_HEADER , ORIGINAL_AUTH_HEADER } from "../../../src/common/providers/https" ;
38+ import { onInit } from "../../../src/v1" ;
3839
3940describe ( "CloudHttpsBuilder" , ( ) => {
4041 describe ( "#onRequest" , ( ) => {
@@ -70,6 +71,26 @@ describe("CloudHttpsBuilder", () => {
7071 expect ( fn . __endpoint . timeoutSeconds ) . to . deep . equal ( 90 ) ;
7172 expect ( fn . __endpoint . httpsTrigger . invoker ) . to . deep . equal ( [ "private" ] ) ;
7273 } ) ;
74+
75+ it ( "calls init function" , async ( ) => {
76+ let hello ;
77+ onInit ( ( ) => ( hello = "world" ) ) ;
78+ expect ( hello ) . to . be . undefined ;
79+ const fn = functions . https . onRequest ( ( _req , res ) => {
80+ res . send ( 200 ) ;
81+ } ) ;
82+ const req = new MockRequest (
83+ {
84+ data : { foo : "bar" } ,
85+ } ,
86+ {
87+ "content-type" : "application/json" ,
88+ }
89+ ) ;
90+ req . method = "POST" ;
91+ await runHandler ( fn , req as any ) ;
92+ expect ( hello ) . to . equal ( "world" ) ;
93+ } ) ;
7394 } ) ;
7495} ) ;
7596
@@ -114,7 +135,7 @@ describe("#onCall", () => {
114135 expect ( fn . __endpoint . timeoutSeconds ) . to . deep . equal ( 90 ) ;
115136 } ) ;
116137
117- it ( "has a .run method" , ( ) => {
138+ it ( "has a .run method" , async ( ) => {
118139 const cf = https . onCall ( ( d , c ) => {
119140 return { data : d , context : c } ;
120141 } ) ;
@@ -127,7 +148,8 @@ describe("#onCall", () => {
127148 token : "token" ,
128149 } ,
129150 } ;
130- expect ( cf . run ( data , context ) ) . to . deep . equal ( { data, context } ) ;
151+
152+ await expect ( cf . run ( data , context ) ) . to . eventually . deep . equal ( { data, context } ) ;
131153 } ) ;
132154
133155 // Regression test for firebase-functions#947
@@ -152,6 +174,25 @@ describe("#onCall", () => {
152174 expect ( gotData ) . to . deep . equal ( { foo : "bar" } ) ;
153175 } ) ;
154176
177+ it ( "should call initializer" , async ( ) => {
178+ const func = https . onCall ( ( ) => null ) ;
179+ const req = new MockRequest (
180+ {
181+ data : { } ,
182+ } ,
183+ {
184+ "content-type" : "application/json" ,
185+ }
186+ ) ;
187+ req . method = "POST" ;
188+
189+ let hello ;
190+ onInit ( ( ) => ( hello = "world" ) ) ;
191+ expect ( hello ) . to . be . undefined ;
192+ await runHandler ( func , req as any ) ;
193+ expect ( hello ) . to . equal ( "world" ) ;
194+ } ) ;
195+
155196 // Test for firebase-tools#5210
156197 it ( "should create context.auth for v1 emulated functions" , async ( ) => {
157198 sinon . stub ( debug , "isDebugFeatureEnabled" ) . withArgs ( "skipTokenVerification" ) . returns ( true ) ;
0 commit comments