|
167 | 167 | end
|
168 | 168 | end
|
169 | 169 | end
|
| 170 | + |
| 171 | + describe 'csv' do |
| 172 | + it 'should return CSV with correct headers and data' do |
| 173 | + params = { |
| 174 | + fields: { 'Tree' => 'id,name,owner', 'owner' => 'name'}, |
| 175 | + page: { 'number' => '1', 'size' => '10' }, |
| 176 | + searchExtended: '0', |
| 177 | + sort: '-id', |
| 178 | + timezone: 'Europe/Paris', |
| 179 | + header: 'id,name,owner', |
| 180 | + } |
| 181 | + get '/forest/Tree.csv', params: params, headers: headers |
| 182 | + |
| 183 | + expect(response.status).to eq(200) |
| 184 | + expect(response.headers['Content-Type']).to include('text/csv') |
| 185 | + expect(response.headers['Content-Disposition']).to include('attachment') |
| 186 | + |
| 187 | + csv_content = response.body |
| 188 | + csv_lines = csv_content.split("\n") |
| 189 | + |
| 190 | + expect(csv_lines.first).to eq(params[:header]) |
| 191 | + expect(csv_lines[1]).to eq('1,Lemon Tree,Michel') |
| 192 | + end |
| 193 | + |
| 194 | + it 'returns CSV with only requested fields and ignores optional relation' do |
| 195 | + params = { |
| 196 | + fields: { 'Tree' => 'id,name', 'owner' => 'name'}, |
| 197 | + page: { 'number' => '1', 'size' => '10' }, |
| 198 | + searchExtended: '0', |
| 199 | + sort: '-id', |
| 200 | + timezone: 'Europe/Paris', |
| 201 | + header: 'id,name', |
| 202 | + } |
| 203 | + get '/forest/Tree.csv', params: params, headers: headers |
| 204 | + |
| 205 | + expect(response.status).to eq(200) |
| 206 | + expect(response.headers['Content-Type']).to include('text/csv') |
| 207 | + expect(response.headers['Content-Disposition']).to include('attachment') |
| 208 | + |
| 209 | + csv_content = response.body |
| 210 | + csv_lines = csv_content.split("\n") |
| 211 | + |
| 212 | + expect(csv_lines.first).to eq(params[:header]) |
| 213 | + expect(csv_lines[1]).to eq('1,Lemon Tree') |
| 214 | + end |
| 215 | + end |
170 | 216 | end
|
171 | 217 |
|
172 | 218 | describe 'Requesting User resources', :type => :request do
|
|
0 commit comments