Skip to content

Commit

Permalink
Tests for CSV export; add timestamp and collector to export
Browse files Browse the repository at this point in the history
  • Loading branch information
hampelm committed Jun 1, 2012
1 parent e50f1c1 commit ec31fc0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ uploaded_files/*
!uploaded_files/README.md !uploaded_files/README.md
setenv*.sh setenv*.sh
herokuconfig*.sh herokuconfig*.sh
nohup.out
6 changes: 4 additions & 2 deletions responses.js
Expand Up @@ -57,7 +57,7 @@ function commasep(row, headers, headerCount) {
len = 1; len = 1;
} else { } else {
// If it's an array of responses, join them with a semicolon // If it's an array of responses, join them with a semicolon
ar.push(row[i].join(";")); arr.push(row[i].join(";"));
} }


} }
Expand Down Expand Up @@ -285,7 +285,7 @@ function setup(app, db, idgen, collectionName) {
cursor.toArray(function(err, items) { cursor.toArray(function(err, items) {


// Start with some basic headers // Start with some basic headers
var headers = ['parcel_id', 'source']; var headers = ['parcel_id', 'collector', 'timestamp', 'source'];


// Record which header is at which index // Record which header is at which index
var headerIndices = {}; var headerIndices = {};
Expand All @@ -305,6 +305,8 @@ function setup(app, db, idgen, collectionName) {
// Add context entries (parcel ID, source type) // Add context entries (parcel ID, source type)
var row = [ var row = [
items[i].parcel_id, items[i].parcel_id,
items[i].source.collector,
items[i].created,
items[i].source.type items[i].source.type
]; ];


Expand Down
8 changes: 6 additions & 2 deletions test/test.export_csv.js
Expand Up @@ -10,16 +10,20 @@ suite('csvExport', function(){
'third': 1 'third': 1
}; };
var complexRow = ['a', [1,2,3], 4]; 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(){ test('commasep should turn a simple list into a csv string', function(){
var csv = commasep(row, headers, headerCount); var csv = commasep(row, headers, headerCount);
var expected = 'a,2,3'; var expected = 'a,2,3';
assert.equal(csv,expected); assert.equal(csv,expected);
}); });



test('arrays should be serialized with semicolons', function() { 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'; var expected = 'a,1;2;3,4';
assert.equal(csv,expected); assert.equal(csv,expected);
}); });
Expand Down

0 comments on commit ec31fc0

Please sign in to comment.