@@ -7,18 +7,24 @@ const rewire = require('rewire');
77const subject = rewire ( '../../lib/deploy-client' ) ;
88
99describe ( 'DeployClient private methods' , function ( ) {
10- const rewire = require ( 'rewire' ) ;
11- const subject = rewire ( '../../lib/deploy-client' ) ;
12-
1310 const knex = require ( 'knex' ) ( {
1411 client : 'sqlite3' ,
1512 connection : { filename : ':memory:' } ,
1613 useNullAsDefault : true ,
1714 //debug: true
1815 } ) ;
1916
20- beforeEach ( subject . __get__ ( 'createTable' ) . bind ( { knex } , 'test' ) ) ;
21- afterEach ( ( ) => knex . schema . dropTable ( 'test' ) ) ;
17+ beforeEach ( ( ) => {
18+ global . TABLE_NAME = 'test' ;
19+
20+ return knex . migrate . latest ( ) ;
21+ } ) ;
22+
23+ afterEach ( ( ) => {
24+ global . TABLE_NAME = 'test' ;
25+
26+ return knex . migrate . rollback ( ) ;
27+ } ) ;
2228
2329 // Tear down the connection pool after all the tests have completed.
2430 after ( ( ) => knex . destroy ( ) ) ;
@@ -322,8 +328,6 @@ describe('DeployClient public API', function() {
322328 allowOverwrite : false
323329 } ;
324330
325- const createTable = subject . __get__ ( 'createTable' ) ;
326-
327331 let deployClient ;
328332
329333 afterEach ( ( ) => {
@@ -379,7 +383,7 @@ describe('DeployClient public API', function() {
379383 it ( 'returns successfully' , function ( ) {
380384 deployClient = new subject ( baseOptions ) ;
381385
382- return createTable . call ( deployClient , 'foo' )
386+ return deployClient . sanityCheck ( { tableName : 'foo' } )
383387 . then ( ( ) => deployClient . fetchRevisions ( { tableName : 'foo' } ) ) ;
384388 } ) ;
385389 } ) ;
@@ -388,7 +392,7 @@ describe('DeployClient public API', function() {
388392 it ( 'returns the active revision key' , function ( ) {
389393 deployClient = new subject ( baseOptions ) ;
390394
391- return createTable . call ( deployClient , 'foo' )
395+ return deployClient . sanityCheck ( { tableName : 'foo' } )
392396 . then ( ( ) => deployClient . knex ( 'foo' ) . insert ( [
393397 { key : 'first' , value : 'foo' , is_active : false } ,
394398 { key : 'second' , value : 'bar' , is_active : true } ,
@@ -403,7 +407,7 @@ describe('DeployClient public API', function() {
403407 it ( 'returns null if no revision keys are active' , function ( ) {
404408 deployClient = new subject ( baseOptions ) ;
405409
406- return createTable . call ( deployClient , 'foo' )
410+ return deployClient . sanityCheck ( { tableName : 'foo' } )
407411 . then ( ( ) => deployClient . knex ( 'foo' ) . insert ( { key : 'foo' , value : 'bar' } ) )
408412 . then ( ( ) => deployClient . activeRevisionKey ( { tableName : 'foo' } ) )
409413 . then ( key => {
@@ -416,7 +420,7 @@ describe('DeployClient public API', function() {
416420 it ( 'activates a valid revision' , function ( ) {
417421 deployClient = new subject ( baseOptions ) ;
418422
419- return createTable . call ( deployClient , 'foo' )
423+ return deployClient . sanityCheck ( { tableName : 'foo' } )
420424 . then ( ( ) => deployClient . knex ( 'foo' ) . insert ( { key : 'foo' , value : 'bar' } ) )
421425 . then ( ( ) => deployClient . activateRevision ( { tableName : 'foo' , revisionKey : 'foo' } ) )
422426 . then ( ( ) => deployClient . knex ( 'foo' ) . select ( 'key' ) . where ( 'is_active' , true ) )
@@ -434,7 +438,7 @@ describe('DeployClient public API', function() {
434438 it ( 'will not activate an invalid revision' , function ( ) {
435439 deployClient = new subject ( baseOptions ) ;
436440
437- return createTable . call ( deployClient , 'foo' )
441+ return deployClient . sanityCheck ( { tableName : 'foo' } )
438442 . then ( ( ) => {
439443 let promise = deployClient . activateRevision ( { tableName : 'foo' , revisionKey : 'foo' } ) ;
440444
@@ -484,7 +488,7 @@ describe('DeployClient public API', function() {
484488 { key : 'third' , value : 'qux' , created_at : 3 }
485489 ] ;
486490
487- return createTable . call ( deployClient , 'foo' )
491+ return deployClient . sanityCheck ( { tableName : 'foo' } )
488492 . then ( ( ) => deployClient . knex ( 'foo' ) . insert ( revisionList ) )
489493 . then ( ( ) => deployClient . upload ( { tableName : 'foo' , revisionKey : 'fourth' , value : 'wat' } ) )
490494 . then ( ( ) => deployClient . knex ( 'foo' ) . select ( 'key' , 'value' ) . orderBy ( 'created_at' ) )
0 commit comments