11import * as admin from "firebase-admin" ;
2+ import { setupTestData } from "./test-setup" ;
23
34process . env . FIRESTORE_EMULATOR_HOST = "localhost:8080" ;
45process . env . FIREBASE_FIRESTORE_EMULATOR_ADDRESS = "localhost:8080" ;
@@ -12,8 +13,14 @@ if (admin.apps.length === 0) {
1213 admin . initializeApp ( { projectId : "demo-experimental" } ) ;
1314}
1415
16+ // Setup test data before all tests
17+ beforeAll ( async ( ) => {
18+ await setupTestData ( ) ;
19+ } ) ;
20+
1521const extractObjectfromBuffer = ( $ ) => {
16- const splitBuffers = $ . toString ( ) . replace ( / [ \d ] + [ { ] + / g, ",{" ) ;
22+ const buffer = Buffer . from ( $ ) ;
23+ const splitBuffers = buffer . toString ( ) . replace ( / [ \d ] + [ { ] + / g, ",{" ) ;
1724 const formatted = splitBuffers . toString ( ) . substring ( 1 ) ;
1825 return JSON . parse ( `[${ formatted . toString ( ) } ]` ) ;
1926} ;
@@ -29,7 +36,11 @@ describe("functions", () => {
2936 it ( "successfully returns a bundle with queries, documents and params combined" , async ( ) => {
3037 const bundleName = "documents-queries-params" ;
3138 const url = extUrl ( bundleName ) ;
32- const response = await fetch ( url ) ;
39+ const response = await fetch ( url , {
40+ headers : {
41+ "Accept-Encoding" : "identity" ,
42+ } ,
43+ } ) ;
3344 const bundle = await response . arrayBuffer ( ) ;
3445
3546 const [ metadata , documentMetadata , document ] =
@@ -49,7 +60,11 @@ describe("functions", () => {
4960 it ( "successfully returns a bundle using a query with a collection" , async ( ) => {
5061 const bundleName = "query-with-a-collection" ;
5162 const url = extUrl ( bundleName ) ;
52- const response = await fetch ( url ) ;
63+ const response = await fetch ( url , {
64+ headers : {
65+ "Accept-Encoding" : "identity" ,
66+ } ,
67+ } ) ;
5368 const bundle = await response . arrayBuffer ( ) ;
5469
5570 const [ metadata , documentMetadata , document ] =
@@ -69,7 +84,11 @@ describe("functions", () => {
6984 it ( "successfully returns a bundle using a query with a collection and condition" , async ( ) => {
7085 const bundleName = "query-with-a-collection-and-condition" ;
7186 const url = extUrl ( bundleName ) ;
72- const response = await fetch ( url ) ;
87+ const response = await fetch ( url , {
88+ headers : {
89+ "Accept-Encoding" : "identity" ,
90+ } ,
91+ } ) ;
7392 const bundle = await response . arrayBuffer ( ) ;
7493
7594 const [ metadata , documentMetadata , document ] =
@@ -89,7 +108,11 @@ describe("functions", () => {
89108 it ( "successfully returns a bundle using a query with a collection and where clause" , async ( ) => {
90109 const bundleName = "query-with-a-collection-and-condition" ;
91110 const url = extUrl ( bundleName ) ;
92- const response = await fetch ( url ) ;
111+ const response = await fetch ( url , {
112+ headers : {
113+ "Accept-Encoding" : "identity" ,
114+ } ,
115+ } ) ;
93116 const bundle = await response . arrayBuffer ( ) ;
94117
95118 const [ metadata , documentMetadata , document ] =
@@ -106,10 +129,14 @@ describe("functions", () => {
106129 expect ( document . documentMetadata . queries [ 0 ] ) . toEqual ( "example" ) ;
107130 } ) ;
108131
109- xit ( "successfully returns a bundle using a query with a collection and multiple where clauses" , async ( ) => {
132+ it ( "successfully returns a bundle using a query with a collection and multiple where clauses" , async ( ) => {
110133 const bundleName = "query-with-a-collection-and-multiple-where-conditions" ;
111134 const url = extUrl ( bundleName ) ;
112- const response = await fetch ( url ) ;
135+ const response = await fetch ( url , {
136+ headers : {
137+ "Accept-Encoding" : "identity" ,
138+ } ,
139+ } ) ;
113140 const bundle = await response . arrayBuffer ( ) ;
114141
115142 const [ metadata , documentMetadata , document ] =
@@ -129,7 +156,11 @@ describe("functions", () => {
129156 it ( "successfully returns a bundle using a document" , async ( ) => {
130157 const bundleName = "single-document" ;
131158 const url = extUrl ( bundleName ) ;
132- const response = await fetch ( url ) ;
159+ const response = await fetch ( url , {
160+ headers : {
161+ "Accept-Encoding" : "identity" ,
162+ } ,
163+ } ) ;
133164 const bundle = await response . arrayBuffer ( ) ;
134165
135166 const [ metadata , documentMetadata , document ] =
@@ -153,7 +184,11 @@ describe("functions", () => {
153184 it ( "successfully returns a bundle using multiple documents" , async ( ) => {
154185 const bundleName = "multiple-documents" ;
155186 const url = extUrl ( bundleName ) ;
156- const response = await fetch ( url ) ;
187+ const response = await fetch ( url , {
188+ headers : {
189+ "Accept-Encoding" : "identity" ,
190+ } ,
191+ } ) ;
157192 const bundle = await response . arrayBuffer ( ) ;
158193
159194 const [ metadata , documentMetadata , document ] =
@@ -178,7 +213,11 @@ describe("functions", () => {
178213 it ( "successfully returns a bundle using params" , async ( ) => {
179214 const bundleName = "query-with-param" ;
180215 const url = extUrl ( bundleName ) + "?name=document2" ;
181- const response = await fetch ( url ) ;
216+ const response = await fetch ( url , {
217+ headers : {
218+ "Accept-Encoding" : "identity" ,
219+ } ,
220+ } ) ;
182221 const bundle = await response . arrayBuffer ( ) ;
183222
184223 const [ metadata , documentMetadata , document ] =
@@ -198,7 +237,11 @@ describe("functions", () => {
198237 it ( "successfully returns a bundle using clientCache" , async ( ) => {
199238 const bundleName = "with-client-cache" ;
200239 const url = extUrl ( bundleName ) ;
201- const response = await fetch ( url ) ;
240+ const response = await fetch ( url , {
241+ headers : {
242+ "Accept-Encoding" : "identity" ,
243+ } ,
244+ } ) ;
202245 const bundle = await response . arrayBuffer ( ) ;
203246
204247 const [ metadata , documentMetadata , document ] =
@@ -209,10 +252,14 @@ describe("functions", () => {
209252 expect ( metadata . metadata . totalDocuments ) . toEqual ( 0 ) ;
210253 } ) ;
211254
212- xit ( "successfully returns a bundle using serverCache" , async ( ) => {
255+ it ( "successfully returns a bundle using serverCache" , async ( ) => {
213256 const bundleName = "with-server-cache" ;
214257 const url = extUrl ( bundleName ) ;
215- const response = await fetch ( url ) ;
258+ const response = await fetch ( url , {
259+ headers : {
260+ "Accept-Encoding" : "identity" ,
261+ } ,
262+ } ) ;
216263 const bundle = await response . arrayBuffer ( ) ;
217264
218265 const [ metadata , documentMetadata , document ] =
@@ -223,10 +270,14 @@ describe("functions", () => {
223270 expect ( metadata . metadata . totalDocuments ) . toEqual ( 0 ) ;
224271 } ) ;
225272
226- xit ( "successfully returns a bundle using fileCache" , async ( ) => {
273+ it ( "successfully returns a bundle using fileCache" , async ( ) => {
227274 const bundleName = "with-file-cache" ;
228275 const url = extUrl ( bundleName ) ;
229- const response = await fetch ( url ) ;
276+ const response = await fetch ( url , {
277+ headers : {
278+ "Accept-Encoding" : "identity" ,
279+ } ,
280+ } ) ;
230281 const bundle = await response . arrayBuffer ( ) ;
231282
232283 const [ metadata , documentMetadata , document ] =
@@ -240,7 +291,11 @@ describe("functions", () => {
240291 xit ( "successfully returns a request through a webiste hosted by Firebase" , async ( ) => {
241292 const bundleName = "documents-queries-params" ;
242293 const url = extHostedUrl ( bundleName ) ;
243- const response = await fetch ( url ) ;
294+ const response = await fetch ( url , {
295+ headers : {
296+ "Accept-Encoding" : "identity" ,
297+ } ,
298+ } ) ;
244299 const bundle = await response . arrayBuffer ( ) ;
245300
246301 const [ metadata , documentMetadata , document ] =
@@ -259,9 +314,13 @@ describe("functions", () => {
259314
260315 it ( "returns a 404 response if an unknown bundle is provided" , async ( ) => {
261316 const bundleName = "unknown-bundle" ;
262- const url = extHostedUrl ( bundleName ) ;
317+ const url = extUrl ( bundleName ) ;
263318
264- const response = await fetch ( url ) ;
319+ const response = await fetch ( url , {
320+ headers : {
321+ "Accept-Encoding" : "identity" ,
322+ } ,
323+ } ) ;
265324 expect ( response . status ) . toEqual ( 404 ) ;
266325 } ) ;
267326} ) ;
0 commit comments