@@ -91,6 +91,40 @@ describe('run-queries', () => {
9191 } ) ;
9292 } ) ;
9393
94+ it ( 'should export csv results with characters that need to be escaped' , async ( ) => {
95+ const csvLocation = path . join ( tmpDir . name , 'test.csv' ) ;
96+ const qs = createMockQueryServerClient (
97+ createMockCliServer ( {
98+ bqrsInfo : [ { 'result-sets' : [ { name : SELECT_QUERY_NAME } , { name : 'hucairz' } ] } ] ,
99+ bqrsDecode : [ {
100+ columns : [ { kind : 'NotString' } , { kind : 'String' } ] ,
101+ // We only escape string columns. In practice, we will only see quotes in strings, but
102+ // it is a good test anyway.
103+ tuples : [
104+ [ '"a"' , '"b"' ] ,
105+ [ 'c,xxx' , 'd,yyy' ] ,
106+ [ 'aaa " bbb' , 'ccc " ddd' ] ,
107+ [ true , false ] ,
108+ [ 123 , 456 ] ,
109+ [ 123.98 , 456.99 ] ,
110+ ] ,
111+ } ]
112+ } )
113+ ) ;
114+ const info = createMockQueryInfo ( ) ;
115+ const promise = info . exportCsvResults ( qs , csvLocation ) ;
116+
117+ const result = await promise ;
118+ expect ( result ) . to . eq ( true ) ;
119+
120+ const csv = fs . readFileSync ( csvLocation , 'utf8' ) ;
121+ expect ( csv ) . to . eq ( '"a","""b"""\nc,xxx,"d,yyy"\naaa " bbb,"ccc "" ddd"\ntrue,"false"\n123,"456"\n123.98,"456.99"\n' ) ;
122+
123+ // now verify that we are using the expected result set
124+ expect ( ( qs . cliServer . bqrsDecode as sinon . SinonStub ) . callCount ) . to . eq ( 1 ) ;
125+ expect ( ( qs . cliServer . bqrsDecode as sinon . SinonStub ) . getCall ( 0 ) . args [ 1 ] ) . to . eq ( SELECT_QUERY_NAME ) ;
126+ } ) ;
127+
94128 it ( 'should handle csv exports for a query with no result sets' , async ( ) => {
95129 const csvLocation = path . join ( tmpDir . name , 'test.csv' ) ;
96130 const qs = createMockQueryServerClient (
0 commit comments