22 * @license
33 * Copyright 2024 Google Inc.
44 *
5- * Licensed under the Apache License, Version 2.0 (the " License" );
5+ * Licensed under the Apache License, Version 2.0 (the ' License' );
66 * you may not use this file except in compliance with the License.
77 * You may obtain a copy of the License at
88 *
99 * http://www.apache.org/licenses/LICENSE-2.0
1010 *
1111 * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an " AS IS" BASIS,
12+ * distributed under the License is distributed on an ' AS IS' BASIS,
1313 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414 * See the License for the specific language governing permissions and
1515 * limitations under the License.
@@ -260,15 +260,21 @@ describe('DataConnectApiClient CRUD helpers', () => {
260260 describe ( 'insert()' , ( ) => {
261261 it ( 'should call executeGraphql with the correct mutation for simple data' , async ( ) => {
262262 const simpleData = { name : 'test' , value : 123 } ;
263- const expectedMutation = `mutation { ${ testTableName } _insert(data: { name: " test" , value: 123 }) }` ;
263+ const expectedMutation = `mutation { ${ testTableName } _insert(data: { name: ' test' , value: 123 }) }` ;
264264 await apiClient . insert ( testTableName , simpleData ) ;
265265 expect ( executeGraphqlStub ) . to . have . been . calledOnceWithExactly ( expectedMutation ) ;
266266 } ) ;
267267
268268 it ( 'should call executeGraphql with the correct mutation for complex data' , async ( ) => {
269- const complexData = { id : 'abc' , active : true , scores : [ 10 , 20 ] , info : { nested : "yes/no \"quote\" \\slash\\" } } ;
270- // Note: Need to match the specific escaping from objectToString: / -> \\, " -> \"
271- const expectedMutation = `mutation { ${ testTableName } _insert(data: { id: "abc", active: true, scores: [10, 20], info: { nested: "yes/no \\"quote\\" \\\\slash\\\\" } }) }` ;
269+ const complexData = { id : 'abc' , active : true , scores : [ 10 , 20 ] , info : { nested : 'yes/no "quote" \\slash\\' } } ;
270+ // Note: Need to match the specific escaping from objectToString: / -> \\, ' -> \'
271+ const expectedMutation = `
272+ mutation {
273+ ${ testTableName } _insert(data: {
274+ id: 'abc', active: true, scores: [10, 20],
275+ info: { nested: 'yes/no \\'quote\\' \\\\slash\\\\' }
276+ })
277+ }` ;
272278 await apiClient . insert ( testTableName , complexData ) ;
273279 expect ( executeGraphqlStub ) . to . have . been . calledOnceWithExactly ( expectedMutation ) ;
274280 } ) ;
@@ -296,18 +302,24 @@ describe('DataConnectApiClient CRUD helpers', () => {
296302 describe ( 'insertMany()' , ( ) => {
297303 it ( 'should call executeGraphql with the correct mutation for simple data array' , async ( ) => {
298304 const simpleDataArray = [ { name : 'test1' } , { name : 'test2' , value : 456 } ] ;
299- const expectedMutation = `mutation { ${ testTableName } _insertMany(data: [{ name: "test1" }, { name: "test2", value: 456 }]) }` ;
305+ const expectedMutation = `
306+ mutation {
307+ ${ testTableName } _insertMany(data: [{ name: 'test1' }, { name: 'test2', value: 456 }]) }` ;
300308 await apiClient . insertMany ( testTableName , simpleDataArray ) ;
301309 expect ( executeGraphqlStub ) . to . have . been . calledOnceWithExactly ( expectedMutation ) ;
302310 } ) ;
303311
304312 it ( 'should call executeGraphql with the correct mutation for complex data array' , async ( ) => {
305313 const complexDataArray = [
306314 { id : 'a' , active : true , info : { nested : 'n1' } } ,
307- { id : 'b' , scores : [ 1 , 2 ] , info : { nested : " n2/\\" } }
315+ { id : 'b' , scores : [ 1 , 2 ] , info : { nested : ' n2/\\' } }
308316 ] ;
309- // Note: Matching specific escaping: / -> \\, " -> \"
310- const expectedMutation = `mutation { ${ testTableName } _insertMany(data: [{ id: "a", active: true, info: { nested: "n1" } }, { id: "b", scores: [1, 2], info: { nested: "n2/\\\\" } }]) }` ;
317+ // Note: Matching specific escaping: / -> \\, ' -> \'
318+ const expectedMutation = `
319+ mutation {
320+ ${ testTableName } _insertMany(data:
321+ [{ id: 'a', active: true, info: { nested: 'n1' } }, { id: 'b', scores: [1, 2],
322+ info: { nested: 'n2/\\\\' } }]) }` ;
311323 await apiClient . insertMany ( testTableName , complexDataArray ) ;
312324 expect ( executeGraphqlStub ) . to . have . been . calledOnceWithExactly ( expectedMutation ) ;
313325 } ) ;
@@ -330,7 +342,7 @@ describe('DataConnectApiClient CRUD helpers', () => {
330342 . with . property ( 'code' , 'data-connect/invalid-argument' ) ;
331343 } ) ;
332344
333- it ( 'should throw FirebaseDataConnectError for non-array data' , ( ) => {
345+ it ( 'should throw FirebaseDataConnectError for non-array data' , ( ) => {
334346 expect ( ( ) => apiClient . insertMany ( testTableName , { data : 1 } as any ) )
335347 . to . throw ( FirebaseDataConnectError , / ` d a t a ` m u s t b e a n o n - e m p t y a r r a y f o r i n s e r t M a n y ./ )
336348 . with . property ( 'code' , 'data-connect/invalid-argument' ) ;
@@ -341,15 +353,17 @@ describe('DataConnectApiClient CRUD helpers', () => {
341353 describe ( 'upsert()' , ( ) => {
342354 it ( 'should call executeGraphql with the correct mutation for simple data' , async ( ) => {
343355 const simpleData = { id : 'key1' , value : 'updated' } ;
344- const expectedMutation = `mutation { ${ testTableName } _upsert(data: { id: " key1" , value: " updated" }) }` ;
356+ const expectedMutation = `mutation { ${ testTableName } _upsert(data: { id: ' key1' , value: ' updated' }) }` ;
345357 await apiClient . upsert ( testTableName , simpleData ) ;
346358 expect ( executeGraphqlStub ) . to . have . been . calledOnceWithExactly ( expectedMutation ) ;
347359 } ) ;
348360
349361 it ( 'should call executeGraphql with the correct mutation for complex data' , async ( ) => {
350- const complexData = { id : 'key2' , active : false , items : [ 1 , null ] , detail : { status : "done/\\" } } ;
351- // Note: Matching specific escaping: / -> \\, " -> \"
352- const expectedMutation = `mutation { ${ testTableName } _upsert(data: { id: "key2", active: false, items: [1, null], detail: { status: "done/\\\\" } }) }` ;
362+ const complexData = { id : 'key2' , active : false , items : [ 1 , null ] , detail : { status : 'done/\\' } } ;
363+ // Note: Matching specific escaping: / -> \\, ' -> \'
364+ const expectedMutation = `
365+ mutation { ${ testTableName } _upsert(data:
366+ { id: 'key2', active: false, items: [1, null], detail: { status: 'done/\\\\' } }) }` ;
353367 await apiClient . upsert ( testTableName , complexData ) ;
354368 expect ( executeGraphqlStub ) . to . have . been . calledOnceWithExactly ( expectedMutation ) ;
355369 } ) ;
@@ -377,7 +391,8 @@ describe('DataConnectApiClient CRUD helpers', () => {
377391 describe ( 'upsertMany()' , ( ) => {
378392 it ( 'should call executeGraphql with the correct mutation for simple data array' , async ( ) => {
379393 const simpleDataArray = [ { id : 'k1' } , { id : 'k2' , value : 99 } ] ;
380- const expectedMutation = `mutation { ${ testTableName } _upsertMany(data: [{ id: "k1" }, { id: "k2", value: 99 }]) }` ;
394+ const expectedMutation = `
395+ mutation { ${ testTableName } _upsertMany(data: [{ id: 'k1' }, { id: 'k2', value: 99 }]) }` ;
381396 await apiClient . upsertMany ( testTableName , simpleDataArray ) ;
382397 expect ( executeGraphqlStub ) . to . have . been . calledOnceWithExactly ( expectedMutation ) ;
383398 } ) ;
@@ -387,8 +402,10 @@ describe('DataConnectApiClient CRUD helpers', () => {
387402 { id : 'x' , active : true , info : { nested : 'n1/\\"x' } } ,
388403 { id : 'y' , scores : [ null , 2 ] }
389404 ] ;
390- // Note: Matching specific escaping: / -> \\, " -> \"
391- const expectedMutation = `mutation { ${ testTableName } _upsertMany(data: [{ id: "x", active: true, info: { nested: "n1/\\\\\\"x" } }, { id: "y", scores: [null, 2] }]) }` ;
405+ // Note: Matching specific escaping: / -> \\, ' -> \'
406+ const expectedMutation = `
407+ mutation { ${ testTableName } _upsertMany(data:
408+ [{ id: 'x', active: true, info: { nested: 'n1/\\\\\\'x' } }, { id: 'y', scores: [null, 2] }]) }` ;
392409 await apiClient . upsertMany ( testTableName , complexDataArray ) ;
393410 expect ( executeGraphqlStub ) . to . have . been . calledOnceWithExactly ( expectedMutation ) ;
394411 } ) ;
0 commit comments