@@ -13,7 +13,7 @@ const {
1313 IMMUDB_PWD = 'immudb' ,
1414} = process . env ;
1515
16- tap . test ( 'database management ' , async t => {
16+ tap . test ( '[DATABASE MANAGEMENT] ' , async t => {
1717 const config : Config = {
1818 host : IMMUDB_HOST ,
1919 port : IMMUDB_PORT ,
@@ -57,8 +57,8 @@ tap.test('database management', async t => {
5757 const fourthResponse = await immudbClient . set ( fourthRequestData ) ;
5858
5959 if ( fourthResponse ) {
60- t . equal ( fourthResponse . bltxid , 0 ) ;
61- t . equal ( fourthResponse . id , 1 ) ;
60+ t . equal ( fourthResponse . bltxid , 1 ) ;
61+ t . equal ( fourthResponse . id , 2 ) ;
6262 } else {
6363 t . fail ( 'Failed to set' ) ;
6464 }
@@ -88,7 +88,7 @@ tap.test('database management', async t => {
8888 }
8989} ) ;
9090
91- tap . test ( 'user management ' , async t => {
91+ tap . test ( '[USER MANAGEMENT] ' , async t => {
9292 const config : Config = {
9393 host : IMMUDB_HOST ,
9494 port : IMMUDB_PORT ,
@@ -158,7 +158,7 @@ tap.test('user management', async t => {
158158 }
159159} ) ;
160160
161- tap . test ( 'operations ' , async t => {
161+ tap . test ( '[OPERATIONS]: Regular ' , async t => {
162162 const config : Config = {
163163 host : IMMUDB_HOST ,
164164 port : IMMUDB_PORT ,
@@ -234,7 +234,7 @@ tap.test('operations', async t => {
234234 await immudbClient . verifiedSetReference ( verifiedSetReferenceRequest )
235235
236236 // test: safely set a reference to an inserted key
237- const verifiedSetReferenceAtRequest = { key : referenceKey , referencedKey : key , attx : 1 }
237+ const verifiedSetReferenceAtRequest = { key : referenceKey , referencedKey : key , attx : 0 }
238238 await immudbClient . verifiedSetReferenceAt ( verifiedSetReferenceAtRequest )
239239
240240 // // test: count keys having the specified value
@@ -311,9 +311,8 @@ tap.test('operations', async t => {
311311 key : `${ key } ${ key } ` ,
312312 value : `${ value } ${ value } ` ,
313313 } ;
314- let verifiedSetResponse
315314 try {
316- verifiedSetResponse = await immudbClient . verifiedSet ( verifiedSetRequest ) ;
315+ await immudbClient . verifiedSet ( verifiedSetRequest ) ;
317316 } catch ( err ) {
318317 t . fail ( err )
319318 }
@@ -328,7 +327,7 @@ tap.test('operations', async t => {
328327 value : `${ value } 1` ,
329328 } ;
330329 try {
331- verifiedSetResponse = await immudbClient . verifiedSet ( verifiedSetRequest ) ;
330+ await immudbClient . verifiedSet ( verifiedSetRequest ) ;
332331 } catch ( err ) {
333332 t . fail ( err )
334333 }
@@ -340,7 +339,7 @@ tap.test('operations', async t => {
340339 value : `${ value } 2` ,
341340 } ;
342341 try {
343- verifiedSetResponse = await immudbClient . verifiedSet ( verifiedSetRequest ) ;
342+ await immudbClient . verifiedSet ( verifiedSetRequest ) ;
344343 } catch ( err ) {
345344 t . fail ( err )
346345 }
@@ -390,7 +389,7 @@ tap.test('operations', async t => {
390389 await immudbClient . zAdd ( verifiedZAddRequest )
391390
392391 // test: safely set a secondary index on a key at a specific transaction
393- const verifiedZAddAtRequest = { set : 'test' , score : 32 , key, attx : 1 }
392+ const verifiedZAddAtRequest = { set : 'test' , score : 32 , key, attx : 0 }
394393 await immudbClient . zAddAt ( verifiedZAddAtRequest )
395394
396395 t . end ( ) ;
@@ -399,7 +398,86 @@ tap.test('operations', async t => {
399398 }
400399} ) ;
401400
402- tap . test ( 'batches' , async t => {
401+ tap . test ( '[OPERATIONS]: SQL' , async t => {
402+ const config : Config = {
403+ host : IMMUDB_HOST ,
404+ port : IMMUDB_PORT ,
405+ autoLogin : false ,
406+ } ;
407+ const immudbClient = await ImmudbClient . getInstance ( config ) ;
408+ try {
409+ const rand = 1 ;
410+ const testDB = 'testdb' ;
411+
412+ // test: login using the specified username and password
413+ const loginRequest : Parameters . Login = {
414+ user : IMMUDB_USER ,
415+ password : IMMUDB_PWD ,
416+ } ;
417+ await immudbClient . login (
418+ loginRequest
419+ ) ;
420+
421+ const listDatabasesResponse = await immudbClient . listDatabases ( )
422+ if ( listDatabasesResponse ) {
423+ const { databasesList } = listDatabasesResponse
424+
425+ // let dbExists = false
426+ const dbExists = databasesList . some ( ( { databasename } ) => databasename === testDB )
427+
428+ if ( ! dbExists ) {
429+ // test: create database
430+ const createDatabaseRequest : Parameters . CreateDatabase = { databasename : testDB } ;
431+
432+ await immudbClient . createDatabase ( createDatabaseRequest ) ;
433+ }
434+ }
435+
436+ // test: use database just created
437+ const useDatabaseRequest : Parameters . UseDatabase = { databasename : testDB } ;
438+ await immudbClient . useDatabase ( useDatabaseRequest ) ;
439+
440+ const tableName = `table${ Math . floor ( Math . random ( ) * 101 ) } `
441+
442+ await immudbClient . SQLExec ( {
443+ sql : `create table ${ tableName } (id integer, name varchar, primary key id);` ,
444+ } )
445+
446+ await immudbClient . SQLListTables ( )
447+
448+ const sqlExecParams = [
449+ {
450+ id : 1 ,
451+ name : 'Joe'
452+ } ,
453+ {
454+ id : 2 ,
455+ name : 'Joe'
456+ } ,
457+ {
458+ id : 3 ,
459+ name : 'Adam'
460+ } ,
461+ ]
462+ for ( const params of sqlExecParams ) {
463+ await immudbClient . SQLExec ( {
464+ sql : `insert into ${ tableName } (id, name) values (@id, @name);` ,
465+ params
466+ } )
467+ }
468+
469+ await immudbClient . SQLQuery ( {
470+ sql : `select id,name from ${ tableName } where name=@name;` ,
471+ params : { name : 'Joe' }
472+ } )
473+
474+ t . end ( ) ;
475+ } catch ( err ) {
476+ t . error ( err ) ;
477+ }
478+ } ) ;
479+
480+ tap . test ( '[BATCHES]' , async t => {
403481 const config : Config = {
404482 host : IMMUDB_HOST ,
405483 port : IMMUDB_PORT ,
0 commit comments