@@ -35,6 +35,7 @@ import {
35
35
import { runHandler } from "../../helper" ;
36
36
import { MINIMAL_V1_ENDPOINT } from "../../fixtures" ;
37
37
import { CALLABLE_AUTH_HEADER , ORIGINAL_AUTH_HEADER } from "../../../src/common/providers/https" ;
38
+ import { onInit } from "../../../src/v1" ;
38
39
39
40
describe ( "CloudHttpsBuilder" , ( ) => {
40
41
describe ( "#onRequest" , ( ) => {
@@ -70,6 +71,26 @@ describe("CloudHttpsBuilder", () => {
70
71
expect ( fn . __endpoint . timeoutSeconds ) . to . deep . equal ( 90 ) ;
71
72
expect ( fn . __endpoint . httpsTrigger . invoker ) . to . deep . equal ( [ "private" ] ) ;
72
73
} ) ;
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
+ } ) ;
73
94
} ) ;
74
95
} ) ;
75
96
@@ -114,7 +135,7 @@ describe("#onCall", () => {
114
135
expect ( fn . __endpoint . timeoutSeconds ) . to . deep . equal ( 90 ) ;
115
136
} ) ;
116
137
117
- it ( "has a .run method" , ( ) => {
138
+ it ( "has a .run method" , async ( ) => {
118
139
const cf = https . onCall ( ( d , c ) => {
119
140
return { data : d , context : c } ;
120
141
} ) ;
@@ -127,7 +148,8 @@ describe("#onCall", () => {
127
148
token : "token" ,
128
149
} ,
129
150
} ;
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 } ) ;
131
153
} ) ;
132
154
133
155
// Regression test for firebase-functions#947
@@ -152,6 +174,25 @@ describe("#onCall", () => {
152
174
expect ( gotData ) . to . deep . equal ( { foo : "bar" } ) ;
153
175
} ) ;
154
176
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
+
155
196
// Test for firebase-tools#5210
156
197
it ( "should create context.auth for v1 emulated functions" , async ( ) => {
157
198
sinon . stub ( debug , "isDebugFeatureEnabled" ) . withArgs ( "skipTokenVerification" ) . returns ( true ) ;
0 commit comments