@@ -5,9 +5,12 @@ var options = {
5
5
} ;
6
6
7
7
var os = require ( 'os' ) ;
8
+ var path = require ( 'path' ) ;
8
9
var utils = require ( '../lib/utils' ) ;
9
10
var header = require ( './db/header' ) ;
10
- var helpers = header ( options ) . pgp . helpers ;
11
+ var pgp = header ( options ) . pgp ;
12
+ var helpers = pgp . helpers ;
13
+ var QueryFile = pgp . QueryFile ;
11
14
12
15
var dataSingle = {
13
16
val : 123 ,
@@ -832,3 +835,42 @@ describe("method 'values'", function () {
832
835
} ) ;
833
836
} ) ;
834
837
838
+ describe ( "method 'concat'" , function ( ) {
839
+ describe ( "Negative" , function ( ) {
840
+ it ( "must throw on a non-array input" , function ( ) {
841
+ var error = new TypeError ( "Parameter 'queries' must be an array." ) ;
842
+ expect ( function ( ) {
843
+ helpers . concat ( ) ;
844
+ } ) . toThrow ( error ) ;
845
+ expect ( function ( ) {
846
+ helpers . concat ( 123 ) ;
847
+ } ) . toThrow ( error ) ;
848
+ } ) ;
849
+ it ( "must throw on invalid elements inside array" , function ( ) {
850
+ var error = new Error ( "Invalid query element at index 0." ) ;
851
+ expect ( function ( ) {
852
+ helpers . concat ( [ 1 ] ) ;
853
+ } ) . toThrow ( error ) ;
854
+ expect ( function ( ) {
855
+ helpers . concat ( [ { } ] ) ;
856
+ } ) . toThrow ( error ) ;
857
+ } ) ;
858
+ } ) ;
859
+
860
+ describe ( "Positive" , function ( ) {
861
+ describe ( "with simple strings" , function ( ) {
862
+ it ( "must allow an empty array" , function ( ) {
863
+ expect ( helpers . concat ( [ ] ) ) . toBe ( '' ) ;
864
+ } ) ;
865
+ it ( "must remove symbols correctly" , function ( ) {
866
+ expect ( helpers . concat ( [ 'one' , 'two' ] ) ) . toBe ( 'one;two' ) ; // normal
867
+ expect ( helpers . concat ( [ '\t;;one;\t;' , ' two ;;\t\t' ] ) ) . toBe ( 'one;two' ) ;
868
+ expect ( helpers . concat ( [ '\t;;one;\t;here ' , ' two ;;\t\t' ] ) ) . toBe ( 'one;\t;here;two' ) ;
869
+ } ) ;
870
+ it ( "must support mixed types correctly" , function ( ) {
871
+ var qf = new QueryFile ( path . join ( __dirname , './sql/allUsers.sql' ) , { minify : true } ) ;
872
+ expect ( helpers . concat ( [ 'one' , { query : 'two' } , qf ] ) ) . toBe ( 'one;two;select * from users' ) ;
873
+ } ) ;
874
+ } ) ;
875
+ } ) ;
876
+ } ) ;
0 commit comments