@@ -861,24 +861,28 @@ describe('PoolPlus', () => {
861
861
const debugPool = new PoolPlus ( Object . assign ( { plusOptions : { debug : true } } , config ) ) ;
862
862
863
863
before ( ( ) => {
864
- sinon . stub ( console , 'log' ) ;
865
- } ) ;
866
-
867
- afterEach ( ( ) => {
868
- console . log . reset ( ) ;
864
+ sinon . stub ( debugPool , 'query' ) . yieldsAsync ( null , [ ] ) ;
869
865
} ) ;
870
866
871
867
after ( done => {
872
- console . log . restore ( ) ;
868
+ debugPool . query . restore ( ) ;
873
869
debugPool . end ( done ) ;
874
870
} ) ;
875
871
876
872
it ( 'should log operations to the console when syncing' , done => {
877
- debugPool . defineTable ( 'pool_plus_test_table_debug' , {
873
+ sinon . stub ( console , 'log' ) ;
874
+ sinon . stub ( Connection . prototype , 'query' ) . yieldsAsync ( ) ;
875
+
876
+ debugPool . defineTable ( 'pool_plus_test_table_debug_a' , {
878
877
columns : {
879
878
id : debugPool . ColTypes . int ( ) . unsigned ( ) . notNull ( ) . primaryKey ( ) ,
880
879
} ,
881
880
} ) ;
881
+ debugPool . defineTable ( 'pool_plus_test_table_debug_b' , {
882
+ columns : {
883
+ id : debugPool . ColTypes . char ( 1 ) ,
884
+ } ,
885
+ } ) ;
882
886
883
887
debugPool . sync ( err => {
884
888
if ( err ) throw err ;
@@ -889,20 +893,35 @@ describe('PoolPlus', () => {
889
893
'' ,
890
894
'type: CREATE_TABLE' ,
891
895
'SQL:' ,
892
- 'CREATE TABLE `pool_plus_test_table_debug ` (' ,
896
+ 'CREATE TABLE `pool_plus_test_table_debug_a ` (' ,
893
897
' `id` int unsigned NOT NULL,' ,
894
898
' PRIMARY KEY (`id`)' ,
895
899
')' ,
896
900
'' ,
901
+ 'type: CREATE_TABLE' ,
902
+ 'SQL:' ,
903
+ 'CREATE TABLE `pool_plus_test_table_debug_b` (' ,
904
+ ' `id` char(1)' ,
905
+ ')' ,
906
+ '' ,
897
907
'===================================================' ,
898
908
'' ,
899
909
] . join ( '\n' ) ) ;
900
910
911
+ console . log . restore ( ) ;
912
+ Connection . prototype . query . restore ( ) ;
901
913
done ( ) ;
902
914
} ) ;
903
915
} ) ;
904
916
905
917
it ( 'should log the operation that failed to the console when syncing' , done => {
918
+ const error = new Error ( 'MOCK ALTER TABLE ERROR' ) ;
919
+
920
+ sinon . stub ( console , 'log' ) ;
921
+ sinon . stub ( Connection . prototype , 'query' ) . callsFake ( ( sql , cb ) => {
922
+ process . nextTick ( cb , sql . startsWith ( 'ALTER' ) ? error : null ) ;
923
+ } ) ;
924
+
906
925
debugPool . defineTable ( 'pool_plus_test_table_debug_error' , {
907
926
columns : {
908
927
id : debugPool . ColTypes . int ( ) . unsigned ( ) . notNull ( ) . primaryKey ( ) ,
@@ -913,25 +932,23 @@ describe('PoolPlus', () => {
913
932
} ) ;
914
933
915
934
debugPool . sync ( err => {
916
- err . should . be . an . Error ( ) . and . match ( {
917
- message : / E R _ C A N N O T _ A D D _ F O R E I G N / ,
918
- code : 'ER_CANNOT_ADD_FOREIGN' ,
919
- errno : 1215 ,
920
- } ) ;
935
+ err . should . equal ( error ) ;
921
936
922
937
console . log . should . have . been . calledWithExactly ( [
923
938
'' ,
924
939
'====== mysql-plus sync errored on operation: ======' ,
925
940
'' ,
926
941
'type: ADD_FOREIGN_KEY' ,
927
942
'SQL:' ,
928
- 'ALTER TABLE `pool_plus_test_table_debug_error` ADD CONSTRAINT `fk_pool_plus_test_table_debug_error_id`' +
929
- ' FOREIGN KEY (`id`) REFERENCES `non_existent_table` (`id`)' ,
943
+ 'ALTER TABLE `pool_plus_test_table_debug_error` ADD CONSTRAINT `fk_pool_plus_test_table_debug_error_id`' ,
944
+ ' FOREIGN KEY (`id`) REFERENCES `non_existent_table` (`id`)' ,
930
945
'' ,
931
946
'===================================================' ,
932
947
'' ,
933
948
] . join ( '\n' ) ) ;
934
949
950
+ console . log . restore ( ) ;
951
+ Connection . prototype . query . restore ( ) ;
935
952
done ( ) ;
936
953
} ) ;
937
954
} ) ;
0 commit comments