@@ -12,6 +12,7 @@ import {
1212 LONG_TIMEOUT ,
1313 getTestingConfig ,
1414 getChinookConfig ,
15+ getChinookApiKeyUrl ,
1516 getChinookTlsConnection ,
1617 sendCommandsAsync ,
1718 // clearTestingDatabasesAsync,
@@ -74,6 +75,32 @@ describe('connection-tls', () => {
7475 LONG_TIMEOUT
7576 )
7677
78+ it (
79+ 'should connect using api key' ,
80+ done => {
81+ try {
82+ // eg: sqlitecloud://mIiLARzKm9XBVllbAzkB1wqrgijJ3Gx0X5z1Agm3xBo@host .sqlite.cloud:8860/chinook.sqlite
83+ const connectionUrl = getChinookApiKeyUrl ( )
84+ const connection = new SQLiteCloudTlsConnection ( connectionUrl , error => {
85+ expect ( error ) . toBeNull ( )
86+ expect ( connection . connected ) . toBe ( true )
87+
88+ connection . sendCommands ( 'TEST STRING' , ( error , results ) => {
89+ connection . close ( )
90+ expect ( connection . connected ) . toBe ( false )
91+ done ( )
92+ } )
93+ } )
94+ expect ( connection ) . toBeDefined ( )
95+ } catch ( error ) {
96+ console . error ( `An error occurred while connecting using api key: ${ error } ` )
97+ debugger
98+ throw error
99+ }
100+ } ,
101+ LONG_TIMEOUT
102+ )
103+
77104 it ( 'should connect with connection string' , done => {
78105 // if (CHINOOK_DATABASE_URL.indexOf('localhost') > 0) {
79106 // // skip this test when running locally since it requires a self-signed certificate
@@ -128,7 +155,7 @@ describe('connection-tls', () => {
128155 expect ( error ) . toBeDefined ( )
129156 expect ( error ) . toBeInstanceOf ( SQLiteCloudError )
130157 const sqliteCloudError = error as SQLiteCloudError
131- expect ( sqliteCloudError . message ) . toBe ( 'The user, password and host arguments must be specified.' )
158+ expect ( sqliteCloudError . message ) . toBe ( 'The user, password and host arguments or the ?apiKey= must be specified.' )
132159 expect ( sqliteCloudError . errorCode ) . toBe ( 'ERR_MISSING_ARGS' )
133160 expect ( sqliteCloudError . externalErrorCode ) . toBeUndefined ( )
134161 expect ( sqliteCloudError . offsetCode ) . toBeUndefined ( )
@@ -524,7 +551,7 @@ describe('connection-tls', () => {
524551 chinook . sendCommands ( 'LIST METADATA;' , ( error , results ) => {
525552 expect ( error ) . toBeNull ( )
526553 expect ( results . numberOfColumns ) . toBe ( 8 )
527- expect ( results . numberOfRows ) . toBe ( 64 )
554+ expect ( results . numberOfRows ) . toBeGreaterThanOrEqual ( 32 )
528555
529556 done ( )
530557 chinook . close ( )
@@ -594,7 +621,7 @@ describe('connection-tls', () => {
594621 chinook . sendCommands ( 'SELECT * FROM tracks;' , ( error , results ) => {
595622 expect ( error ) . toBeNull ( )
596623 expect ( results . numberOfColumns ) . toBe ( 9 )
597- expect ( results . numberOfRows ) . toBe ( 3503 )
624+ expect ( results . numberOfRows ) . toBeGreaterThan ( 3000 ) // 3503 tracks but we sometimes test deleting rows
598625
599626 done ( )
600627 chinook . close ( )
0 commit comments