@@ -13,6 +13,9 @@ query MyQuery {
1313}
1414`
1515
16+ // const HEADER = `[float_column, int_column, text_column, time_column]`
17+ const HEADER = [ 'int_column' , 'float_column' , 'time_column' , 'text_column' ]
18+
1619describe ( 'data-api-download' , function ( ) {
1720 it ( 'should return JSON when no format parameter is passed' , function ( done ) {
1821 request ( app )
@@ -88,6 +91,12 @@ describe('data-api-download', function () {
8891 )
8992 assert ( res . header [ 'content-type' ] == 'text/csv; charset=utf-8' )
9093 // check that is a CSV
94+ const pipeSeparated = res . text
95+ . split ( '\n' )
96+ . filter ( ( line ) => line . length > 0 )
97+ . every ( ( line ) => line . includes ( ',' ) )
98+ // console.log('pipe Separated = ', pipeSeparated)
99+ assert ( pipeSeparated )
91100 done ( )
92101 } )
93102 } )
@@ -110,6 +119,52 @@ describe('data-api-download', function () {
110119 )
111120 assert ( res . header [ 'content-type' ] == 'text/csv; charset=utf-8' )
112121 // check that is a pipe-separated-CSV
122+ const pipeSeparated = res . text
123+ . split ( '\n' )
124+ . filter ( ( line ) => line . length > 0 )
125+ . every ( ( line ) => line . includes ( '|' ) )
126+ // console.log('pipe Separated = ', pipeSeparated)
127+ assert ( pipeSeparated )
128+
129+ done ( )
130+ } )
131+ } )
132+
133+ it ( 'should return columns in specified ORDER when adding headers to the call' , function ( done ) {
134+ request ( app )
135+ . post ( '/v1/download?format=csv' )
136+ . send ( {
137+ query : QUERY ,
138+ header : HEADER ,
139+ } )
140+ . expect ( 200 )
141+ . end ( function ( err , res ) {
142+ console . log ( 'ERROR = ' , err )
143+ // console.log('response TEXT: ', res.text)
144+ // console.log('response BODY: ', res.body)
145+ console . log ( res . header )
146+ assert (
147+ res . header [ 'content-disposition' ] ==
148+ 'attachment; filename="download.csv";'
149+ )
150+ assert ( res . header [ 'content-type' ] == 'text/csv; charset=utf-8' )
151+ // check that the header is ordered
152+ const headerLine = res . text . split ( '\n' ) [ 0 ] . split ( ',' )
153+ // console.log('header line = ', headerLine, HEADER)
154+ assert ( headerLine . length === HEADER . length )
155+ const matchingHeader = headerLine
156+ . map ( function ( e , i ) {
157+ // console.log(
158+ // 'matching header',
159+ // e.trim() == HEADER[i].trim(),
160+ // e,
161+ // HEADER[i]
162+ // )
163+ return e . trim ( ) == HEADER [ i ] . trim ( )
164+ } )
165+ . every ( ( e ) => e == true )
166+
167+ assert ( matchingHeader )
113168
114169 done ( )
115170 } )
0 commit comments