Permalink
Browse files

Tests for CSV export; add timestamp and collector to export

  • Loading branch information...
1 parent e50f1c1 commit ec31fc0cc2cf76e674168093d8f9472080535d42 hampelm committed Jun 1, 2012
Showing with 11 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +4 −2 responses.js
  3. +6 −2 test/test.export_csv.js
View
@@ -3,3 +3,4 @@ uploaded_files/*
!uploaded_files/README.md
setenv*.sh
herokuconfig*.sh
+nohup.out
View
@@ -57,7 +57,7 @@ function commasep(row, headers, headerCount) {
len = 1;
} else {
// If it's an array of responses, join them with a semicolon
- ar.push(row[i].join(";"));
+ arr.push(row[i].join(";"));
}
}
@@ -285,7 +285,7 @@ function setup(app, db, idgen, collectionName) {
cursor.toArray(function(err, items) {
// Start with some basic headers
- var headers = ['parcel_id', 'source'];
+ var headers = ['parcel_id', 'collector', 'timestamp', 'source'];
// Record which header is at which index
var headerIndices = {};
@@ -305,6 +305,8 @@ function setup(app, db, idgen, collectionName) {
// Add context entries (parcel ID, source type)
var row = [
items[i].parcel_id,
+ items[i].source.collector,
+ items[i].created,
items[i].source.type
];
@@ -10,16 +10,20 @@ suite('csvExport', function(){
'third': 1
};
var complexRow = ['a', [1,2,3], 4];
+ var complexHeaderCount = {
+ 'first': 1,
+ 'second': 3,
+ 'third': 1
+ };
test('commasep should turn a simple list into a csv string', function(){
var csv = commasep(row, headers, headerCount);
var expected = 'a,2,3';
assert.equal(csv,expected);
});
-
test('arrays should be serialized with semicolons', function() {
- var csv = commasep(complexRow, headers, headerCount);
+ var csv = commasep(complexRow, headers, complexHeaderCount);
var expected = 'a,1;2;3,4';
assert.equal(csv,expected);
});

0 comments on commit ec31fc0

Please sign in to comment.