@@ -211,7 +211,8 @@ describe('164. soda1.js', () => {
211211 await conn . close ( ) ;
212212 } ) ; // 164.9
213213
214- it ( '164.10 the "examples/soda1.js" case' , async ( ) => {
214+ it ( '164.10 the "examples/soda1.js" case with autoCommit = true' , async ( ) => {
215+ oracledb . autoCommit = true ;
215216 const conn = await oracledb . getConnection ( dbConfig ) ;
216217 // Create the parent object for SODA
217218 const soda = conn . getSodaDatabase ( ) ;
@@ -274,7 +275,7 @@ describe('164. soda1.js', () => {
274275 // Count all documents
275276 const res1 = await collection . find ( ) . count ( ) ;
276277 assert . strictEqual ( res1 . count , 4 ) ;
277-
278+ oracledb . autoCommit = false ;
278279 // Remove documents with cities containing 'o'
279280 const res2 = await collection . find ( ) . filter ( { "address.city" : { "$regex" : ".*o.*" } } ) . remove ( ) ;
280281 assert . strictEqual ( res2 . count , 2 ) ;
@@ -293,7 +294,89 @@ describe('164. soda1.js', () => {
293294 await conn . close ( ) ;
294295 } ) ; // 164.10
295296
296- it ( '164.11 Negative: create collection with invalid metaData value' , async ( ) => {
297+ it ( '164.11 the "examples/soda1.js" case with no autocommit set up' , async ( ) => {
298+ const conn = await oracledb . getConnection ( dbConfig ) ;
299+ // Create the parent object for SODA
300+ const soda = conn . getSodaDatabase ( ) ;
301+
302+ // Create a new SODA collection and index
303+ const collection = await soda . createCollection ( "soda_test_164_11" ) ;
304+ const indexSpec = {
305+ "name" : "CITY_IDX" ,
306+ "fields" : [
307+ {
308+ "path" : "address.city" ,
309+ "datatype" : "string" ,
310+ "order" : "asc"
311+ }
312+ ]
313+ } ;
314+ await collection . createIndex ( indexSpec ) ;
315+
316+ // Insert a document
317+ // A system generated key is created by default
318+ const content1 = { name : "Matilda" , address : { city : "Melbourne" } } ;
319+ const doc1 = await collection . insertOneAndGet ( content1 ) ;
320+ const myKey = doc1 . key ;
321+ assert ( myKey ) ;
322+ assert . strictEqual ( typeof ( myKey ) , "string" ) ;
323+
324+ // Fetch the document back
325+ const doc2 = await collection . find ( ) . key ( myKey ) . getOne ( ) ;
326+ const content2 = doc2 . getContent ( ) ; // A JavaScript object
327+ testsUtil . removeID ( content1 ) ;
328+ testsUtil . removeID ( content2 ) ;
329+ assert . deepStrictEqual ( content2 , content1 ) ;
330+
331+ const content3 = testsUtil . removeID ( doc2 . getContentAsString ( ) ) ; // A JSON string
332+
333+ assert . strictEqual ( JSON . stringify ( content2 ) , content3 ) ;
334+
335+ // Replace document contents
336+ const content4 = { name : "Matilda" , address : { city : "Sydney" } } ;
337+ await collection . find ( ) . key ( myKey ) . replaceOne ( content4 ) ;
338+
339+ // Insert some more documents without caring about their keys
340+ const content5 = { name : "Venkat" , address : { city : "Bengaluru" } } ;
341+ await collection . insertOne ( content5 ) ;
342+ const content6 = { name : "May" , address : { city : "London" } } ;
343+ await collection . insertOne ( content6 ) ;
344+ const content7 = { name : "Sally-Ann" , address : { city : "San Francisco" } } ;
345+ await collection . insertOne ( content7 ) ;
346+
347+ // Find all documents with city names starting with 'S'
348+ const documents = await collection . find ( )
349+ . filter ( { "address.city" : { "$like" : "S%" } } )
350+ . getDocuments ( ) ;
351+
352+ for ( let i = 0 ; i < documents . length ; i ++ ) {
353+ const content = documents [ i ] . getContent ( ) ;
354+ ( [ 'Sydney' , 'San Francisco' ] ) . includes ( content . address . city ) ;
355+ }
356+
357+ // Count all documents
358+ const res1 = await collection . find ( ) . count ( ) ;
359+ assert . strictEqual ( res1 . count , 4 ) ;
360+
361+ // Remove documents with cities containing 'o'
362+ const res2 = await collection . find ( ) . filter ( { "address.city" : { "$regex" : ".*o.*" } } ) . remove ( ) ;
363+ assert . strictEqual ( res2 . count , 2 ) ;
364+
365+ // Count all documents
366+ const res3 = await collection . find ( ) . count ( ) ;
367+ assert . strictEqual ( res3 . count , 2 ) ;
368+
369+ await collection . dropIndex ( "CITY_IDX" ) ;
370+
371+ // Commit changes
372+ await conn . commit ( ) ;
373+
374+ const res = await collection . drop ( ) ;
375+ assert . strictEqual ( res . dropped , true ) ;
376+ await conn . close ( ) ;
377+ } ) ; // 164.11
378+
379+ it ( '164.12 Negative: create collection with invalid metaData value' , async ( ) => {
297380 const conn = await oracledb . getConnection ( dbConfig ) ;
298381 const sd = conn . getSodaDatabase ( ) ;
299382
@@ -306,6 +389,6 @@ describe('164. soda1.js', () => {
306389 ) ;
307390
308391 await conn . close ( ) ;
309- } ) ; // 164.11
392+ } ) ; // 164.12
310393
311394} ) ;
0 commit comments