@@ -67,6 +67,7 @@ describe('Table', () => {
6767 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6868 let TableCached : any ;
6969 let table ;
70+ let tableWithSchema ;
7071 let transaction : FakeTransaction ;
7172
7273 const DATABASE = {
@@ -75,6 +76,7 @@ describe('Table', () => {
7576 } ;
7677
7778 const NAME = 'table-name' ;
79+ const NAMEWITHSCHEMA = 'schema.' + NAME ;
7880
7981 before ( ( ) => {
8082 Table = proxyquire ( '../src/table.js' , {
@@ -86,6 +88,7 @@ describe('Table', () => {
8688 beforeEach ( ( ) => {
8789 extend ( Table , TableCached ) ;
8890 table = new Table ( DATABASE , NAME ) ;
91+ tableWithSchema = new Table ( DATABASE , NAMEWITHSCHEMA ) ;
8992 transaction = new FakeTransaction ( ) ;
9093 } ) ;
9194
@@ -209,26 +212,124 @@ describe('Table', () => {
209212 } ) ;
210213
211214 describe ( 'delete' , ( ) => {
212- it ( 'should update the schema on the database' , ( ) => {
213- const updateSchemaReturnValue = { } ;
215+ it ( 'should update the schema on the database for GoogleSQL using await' , async ( ) => {
216+ table . database = {
217+ getDatabaseDialect : ( ) => {
218+ return 'GOOGLE_STANDARD_SQL' ;
219+ } ,
220+ updateSchema : schema => {
221+ assert . strictEqual ( schema , 'DROP TABLE `table-name`' ) ;
222+ } ,
223+ } ;
224+
225+ await table . delete ( ) ;
226+ } ) ;
227+
228+ it ( 'should update the schema on the database for GoogleSQL using callbacks' , ( ) => {
229+ function callback ( ) { }
230+ table . database = {
231+ getDatabaseDialect : ( ) => {
232+ return 'GOOGLE_STANDARD_SQL' ;
233+ } ,
234+ updateSchema : ( schema , gaxOptions , callback_ ) => {
235+ assert . strictEqual ( schema , 'DROP TABLE `table-name`' ) ;
236+ assert . strictEqual ( callback_ , callback ) ;
237+ } ,
238+ } ;
239+ table . delete ( callback ) ;
240+ } ) ;
241+
242+ it ( 'should update the schema on the database for GoogleSQL with schema in the table name using await' , async ( ) => {
243+ tableWithSchema . database = {
244+ getDatabaseDialect : ( ) => {
245+ return 'GOOGLE_STANDARD_SQL' ;
246+ } ,
247+ updateSchema : schema => {
248+ assert . strictEqual ( schema , 'DROP TABLE `schema`.`table-name`' ) ;
249+ } ,
250+ } ;
251+
252+ await tableWithSchema . delete ( ) ;
253+ } ) ;
254+
255+ it ( 'should update the schema on the database for GoogleSQL with schema in the table name using callbacks' , ( ) => {
256+ function callback ( ) { }
257+ tableWithSchema . database = {
258+ getDatabaseDialect : ( ) => {
259+ return 'GOOGLE_STANDARD_SQL' ;
260+ } ,
261+ updateSchema : ( schema , gaxOptions , callback_ ) => {
262+ assert . strictEqual ( schema , 'DROP TABLE `schema`.`table-name`' ) ;
263+ assert . strictEqual ( callback_ , callback ) ;
264+ } ,
265+ } ;
266+ tableWithSchema . delete ( callback ) ;
267+ } ) ;
268+
269+ it ( 'should update the schema on the database for PostgresSQL using await' , async ( ) => {
270+ table . database = {
271+ getDatabaseDialect : ( ) => {
272+ return 'POSTGRESQL' ;
273+ } ,
274+ updateSchema : schema => {
275+ assert . strictEqual ( schema , `DROP TABLE "${ table . name } "` ) ;
276+ } ,
277+ } ;
214278
279+ await table . delete ( ) ;
280+ } ) ;
281+
282+ it ( 'should update the schema on the database for PostgresSQL using callbacks' , ( ) => {
215283 function callback ( ) { }
216284
217285 table . database = {
286+ getDatabaseDialect : ( ) => {
287+ return 'POSTGRESQL' ;
288+ } ,
218289 updateSchema : ( schema , gaxOptions , callback_ ) => {
219- assert . strictEqual ( schema , 'DROP TABLE `' + table . name + '` ') ;
290+ assert . strictEqual ( schema , 'DROP TABLE " table- name" ' ) ;
220291 assert . strictEqual ( callback_ , callback ) ;
221- return updateSchemaReturnValue ;
222292 } ,
223293 } ;
224294
225- const returnValue = table . delete ( callback ) ;
226- assert . strictEqual ( returnValue , updateSchemaReturnValue ) ;
295+ table . delete ( callback ) ;
296+ } ) ;
297+
298+ it ( 'should update the schema on the database for PostgresSQL with schema in the table name using await' , async ( ) => {
299+ tableWithSchema . database = {
300+ getDatabaseDialect : ( ) => {
301+ return 'POSTGRESQL' ;
302+ } ,
303+ updateSchema : schema => {
304+ assert . strictEqual ( schema , `DROP TABLE "schema"."${ table . name } "` ) ;
305+ } ,
306+ } ;
307+
308+ await tableWithSchema . delete ( ) ;
309+ } ) ;
310+
311+ it ( 'should update the schema on the database for PostgresSQL with schema in the table name using callbacks' , ( ) => {
312+ function callback ( ) { }
313+ tableWithSchema . database = {
314+ getDatabaseDialect : ( ) => {
315+ return 'POSTGRESQL' ;
316+ } ,
317+ updateSchema : ( schema , gaxOptions , callback_ ) => {
318+ assert . strictEqual ( schema , `DROP TABLE "schema"."${ table . name } "` ) ;
319+ assert . strictEqual ( callback_ , callback ) ;
320+ } ,
321+ } ;
322+
323+ tableWithSchema . delete ( callback ) ;
227324 } ) ;
228325
229326 it ( 'should accept and pass gaxOptions to updateSchema' , done => {
230327 const gaxOptions = { } ;
231328 table . database = {
329+ getDatabaseDialect : gaxOptionsFromTable => {
330+ assert . strictEqual ( gaxOptionsFromTable , gaxOptions ) ;
331+ return 'GOOGLE_STANDARD_SQL' ;
332+ } ,
232333 updateSchema : ( schema , gaxOptionsFromTable ) => {
233334 assert . strictEqual ( gaxOptionsFromTable , gaxOptions ) ;
234335 done ( ) ;
0 commit comments