1
1
import { PubSub } from "@google-cloud/pubsub" ;
2
- import { GoogleAuth } from "google-auth-library" ;
3
2
import { Request , Response } from "express" ;
4
3
import * as admin from "firebase-admin" ;
5
- import * as functions from "firebase-functions" ;
4
+ import * as functions from "firebase-functions/v1 " ;
6
5
import * as fs from "fs" ;
7
6
import fetch from "node-fetch" ;
8
7
@@ -20,55 +19,17 @@ import * as testLab from "./v1/testLab-utils";
20
19
const firebaseConfig = JSON . parse ( process . env . FIREBASE_CONFIG ) ;
21
20
admin . initializeApp ( ) ;
22
21
23
- // Re-enable no-unused-var check once callable functions are testable again.
24
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
25
22
async function callHttpsTrigger ( name : string , data : any ) {
26
23
const url = `https://${ REGION } -${ firebaseConfig . projectId } .cloudfunctions.net/${ name } ` ;
27
- const client = await new GoogleAuth ( ) . getIdTokenClient ( "32555940559.apps.googleusercontent.com" ) ;
28
- const resp = await client . request ( {
29
- url,
24
+ const resp = await fetch ( url , {
30
25
method : "POST" ,
31
26
headers : {
32
27
"Content-Type" : "application/json" ,
33
28
} ,
34
29
body : JSON . stringify ( { data } ) ,
35
30
} ) ;
36
- if ( resp . status > 200 ) {
37
- throw Error ( resp . statusText ) ;
38
- }
39
- }
40
-
41
- // Re-enable no-unused-var check once callable functions are testable again.
42
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
43
- async function callV2HttpsTrigger ( name : string , data : any , accessToken : string ) {
44
- const getFnResp = await fetch (
45
- `https://cloudfunctions.googleapis.com/v2beta/projects/${ firebaseConfig . projectId } /locations/${ REGION } /functions/${ name } ` ,
46
- {
47
- headers : {
48
- Authorization : `Bearer ${ accessToken } ` ,
49
- } ,
50
- }
51
- ) ;
52
- if ( ! getFnResp . ok ) {
53
- throw new Error ( getFnResp . statusText ) ;
54
- }
55
- const fn = await getFnResp . json ( ) ;
56
- const uri = fn . serviceConfig ?. uri ;
57
- if ( ! uri ) {
58
- throw new Error ( `Cannot call v2 https trigger ${ name } - no uri found` ) ;
59
- }
60
-
61
- const client = await new GoogleAuth ( ) . getIdTokenClient ( "32555940559.apps.googleusercontent.com" ) ;
62
- const invokeFnREsp = await client . request ( {
63
- url : uri ,
64
- method : "POST" ,
65
- headers : {
66
- "Content-Type" : "application/json" ,
67
- } ,
68
- body : JSON . stringify ( { data } ) ,
69
- } ) ;
70
- if ( invokeFnREsp . status > 200 ) {
71
- throw Error ( invokeFnREsp . statusText ) ;
31
+ if ( ! resp . ok ) {
32
+ throw new Error ( `Failed request with status ${ resp . status } !` ) ;
72
33
}
73
34
}
74
35
@@ -150,8 +111,7 @@ function v1Tests(testId: string, accessToken: string): Array<Promise<unknown>> {
150
111
// A firestore write to trigger the Cloud Firestore tests.
151
112
admin . firestore ( ) . collection ( "tests" ) . doc ( testId ) . set ( { test : testId } ) ,
152
113
// Invoke a callable HTTPS trigger.
153
- // TODO: Temporarily disable - doesn't work unless running on projects w/ permission to create public functions.
154
- // callHttpsTrigger("v1-callableTests", { foo: "bar", testId }),
114
+ callHttpsTrigger ( "v1-callableTests" , { foo : "bar" , testId } ) ,
155
115
// A Remote Config update to trigger the Remote Config tests.
156
116
updateRemoteConfig ( testId , accessToken ) ,
157
117
// A storage upload to trigger the Storage tests
@@ -169,8 +129,7 @@ function v1Tests(testId: string, accessToken: string): Array<Promise<unknown>> {
169
129
function v2Tests ( testId : string , accessToken : string ) : Array < Promise < void > > {
170
130
return [
171
131
// Invoke a callable HTTPS trigger.
172
- // TODO: Temporarily disable - doesn't work unless running on projects w/ permission to create public functions.
173
- // callV2HttpsTrigger("v2-callabletests", { foo: "bar", testId }, accessToken),
132
+ callHttpsTrigger ( "v2-callabletests" , { foo : "bar" , testId } ) ,
174
133
// Invoke a scheduled trigger.
175
134
callV2ScheduleTrigger ( "v2-schedule" , "us-central1" , accessToken ) ,
176
135
] ;
0 commit comments