@@ -12,7 +12,7 @@ const payloadSize = 1024 * 1024 * 10;
1212const concurrencyLimit = 5 ;
1313
1414describe ( "DatabaseImporter" , ( ) => {
15- const DATA = { a : 100 , b : [ true , "bar" , { f : { g : 0 , h : 1 } , i : "baz" } ] } ;
15+ const DATA = { a : 100 , b : [ true , "bar" , { f : { g : 0 , h : 1 } , i : "baz" } ] , c : { d : false } } ;
1616 let DATA_STREAM : stream . Readable ;
1717
1818 beforeEach ( ( ) => {
@@ -39,31 +39,38 @@ describe("DatabaseImporter", () => {
3939 it ( "batches data from different top-level objects" , async ( ) => {
4040 nock ( "https://test-db.firebaseio.com" ) . get ( "/foo.json?shallow=true" ) . reply ( 200 ) ;
4141 nock ( "https://test-db.firebaseio.com" )
42- . patch ( "/.json" , JSON . stringify ( { "/foo/a" : 100 , "/foo/ b/0" : true , "/foo/ b/1" : "bar" } ) )
42+ . patch ( "/foo .json" , JSON . stringify ( { a : 100 , "b/0" : true , "b/1" : "bar" } ) )
4343 . reply ( 200 ) ;
4444 nock ( "https://test-db.firebaseio.com" )
45- . patch ( "/.json" , JSON . stringify ( { "/foo/b/2/f" : { g : 0 , h : 1 } , "/foo/b/2/i" : "baz" } ) )
45+ . patch ( "/foo/b/2.json" , JSON . stringify ( { f : { g : 0 , h : 1 } , i : "baz" } ) )
46+ . reply ( 200 ) ;
47+ nock ( "https://test-db.firebaseio.com" )
48+ . patch ( "/foo/c.json" , JSON . stringify ( { d : false } ) )
4649 . reply ( 200 ) ;
4750 const importer = new DatabaseImporter (
4851 dbUrl ,
4952 DATA_STREAM ,
5053 /* importPath= */ "/" ,
51- /* payloadSize= */ 20 ,
54+ /* payloadSize= */ 40 ,
5255 concurrencyLimit
5356 ) ;
5457
5558 const responses = await importer . execute ( ) ;
5659
57- expect ( responses ) . to . have . length ( 2 ) ;
60+ expect ( responses ) . to . have . length ( 3 ) ;
5861 expect ( nock . isDone ( ) ) . to . be . true ;
5962 } ) ;
6063
6164 it ( "writes data as a single batch for large enough payload size" , async ( ) => {
6265 nock ( "https://test-db.firebaseio.com" ) . get ( "/foo.json?shallow=true" ) . reply ( 200 ) ;
6366 nock ( "https://test-db.firebaseio.com" )
6467 . patch (
65- "/.json" ,
66- JSON . stringify ( { "/foo/a" : 100 , "/foo/b" : [ true , "bar" , { f : { g : 0 , h : 1 } , i : "baz" } ] } )
68+ "/foo.json" ,
69+ JSON . stringify ( {
70+ a : 100 ,
71+ b : [ true , "bar" , { f : { g : 0 , h : 1 } , i : "baz" } ] ,
72+ c : { d : false } ,
73+ } )
6774 )
6875 . reply ( 200 ) ;
6976 const importer = new DatabaseImporter (
@@ -83,7 +90,48 @@ describe("DatabaseImporter", () => {
8390 it ( "imports from data path" , async ( ) => {
8491 nock ( "https://test-db.firebaseio.com" ) . get ( "/foo.json?shallow=true" ) . reply ( 200 ) ;
8592 nock ( "https://test-db.firebaseio.com" )
86- . patch ( "/.json" , JSON . stringify ( { "/foo/b" : [ true , "bar" , { f : { g : 0 , h : 1 } , i : "baz" } ] } ) )
93+ . patch ( "/foo/c.json" , JSON . stringify ( { d : false } ) )
94+ . reply ( 200 ) ;
95+ const importer = new DatabaseImporter (
96+ dbUrl ,
97+ DATA_STREAM ,
98+ /* importPath= */ "/c" ,
99+ payloadSize ,
100+ concurrencyLimit
101+ ) ;
102+
103+ const responses = await importer . execute ( ) ;
104+
105+ expect ( responses ) . to . have . length ( 1 ) ;
106+ expect ( nock . isDone ( ) ) . to . be . true ;
107+ } ) ;
108+
109+ it ( "writes primitive as object" , async ( ) => {
110+ nock ( "https://test-db.firebaseio.com" ) . get ( "/foo.json?shallow=true" ) . reply ( 200 ) ;
111+ nock ( "https://test-db.firebaseio.com" )
112+ . patch ( "/foo.json" , JSON . stringify ( { a : 100 } ) )
113+ . reply ( 200 ) ;
114+ const importer = new DatabaseImporter (
115+ dbUrl ,
116+ DATA_STREAM ,
117+ /* importPath= */ "/a" ,
118+ payloadSize ,
119+ concurrencyLimit
120+ ) ;
121+
122+ const responses = await importer . execute ( ) ;
123+
124+ expect ( responses ) . to . have . length ( 1 ) ;
125+ expect ( nock . isDone ( ) ) . to . be . true ;
126+ } ) ;
127+
128+ it ( "writes array as object" , async ( ) => {
129+ nock ( "https://test-db.firebaseio.com" ) . get ( "/foo.json?shallow=true" ) . reply ( 200 ) ;
130+ nock ( "https://test-db.firebaseio.com" )
131+ . patch (
132+ "/foo/b.json" ,
133+ JSON . stringify ( { "0" : true , "1" : "bar" , "2" : { f : { g : 0 , h : 1 } , i : "baz" } } )
134+ )
87135 . reply ( 200 ) ;
88136 const importer = new DatabaseImporter (
89137 dbUrl ,
@@ -122,15 +170,23 @@ describe("DatabaseImporter", () => {
122170 nock ( "https://test-db.firebaseio.com" ) . get ( "/foo.json?shallow=true" ) . reply ( 200 ) ;
123171 nock ( "https://test-db.firebaseio.com" )
124172 . patch (
125- "/.json" ,
126- JSON . stringify ( { "/foo/a" : 100 , "/foo/b" : [ true , "bar" , { f : { g : 0 , h : 1 } , i : "baz" } ] } )
173+ "/foo.json" ,
174+ JSON . stringify ( {
175+ a : 100 ,
176+ b : [ true , "bar" , { f : { g : 0 , h : 1 } , i : "baz" } ] ,
177+ c : { d : false } ,
178+ } )
127179 )
128180 . once ( )
129181 . replyWithError ( timeoutErr ) ;
130182 nock ( "https://test-db.firebaseio.com" )
131183 . patch (
132- "/.json" ,
133- JSON . stringify ( { "/foo/a" : 100 , "/foo/b" : [ true , "bar" , { f : { g : 0 , h : 1 } , i : "baz" } ] } )
184+ "/foo.json" ,
185+ JSON . stringify ( {
186+ a : 100 ,
187+ b : [ true , "bar" , { f : { g : 0 , h : 1 } , i : "baz" } ] ,
188+ c : { d : false } ,
189+ } )
134190 )
135191 . once ( )
136192 . reply ( 200 ) ;
0 commit comments