Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

Commit

Permalink
Added Current (Flat CSV) tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Jul 3, 2018
1 parent 15905a1 commit bb492eb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Expand Up @@ -12,7 +12,7 @@ parserOptions:
rules:
max-len:
- error
- code: 90
- code: 100
ignoreStrings: true
strict:
- error
Expand Down
10 changes: 5 additions & 5 deletions census/controllers/api.js
Expand Up @@ -299,16 +299,16 @@ let _outputFlatEntryResults = function(results, questions, format, res) {
let maxLocations = 0
for (const item of results) {
let answers = item.getSimpleAnswersForQuestions(questions);
let getAnswerById = id => answers.find(answer => answer.id === id)
maxFormats = Math.max(maxFormats, getAnswerById('format').value.length)
maxCharacts = Math.max(maxCharacts, getAnswerById('characteristics').value.length)
maxLocations = Math.max(maxLocations, getAnswerById('location').value.length)
let getAnswerById = id => answers.find(answer => answer.id === id) || {}
maxFormats = Math.max(maxFormats, (getAnswerById('format').value || []).length)
maxCharacts = Math.max(maxCharacts, (getAnswerById('characteristics').value || []).length)
maxLocations = Math.max(maxLocations, (getAnswerById('location').value || []).length)
}

// Mapper
let mapper = function(item) {
let answers = item.getSimpleAnswersForQuestions(questions);
let getAnswerById = id => answers.find(answer => answer.id === id)
let getAnswerById = id => answers.find(answer => answer.id === id) || {}
let result = {}

// General
Expand Down
23 changes: 23 additions & 0 deletions tests/api.js
Expand Up @@ -81,6 +81,14 @@ describe('API', function() {
});
});

it('Current cascaded flat', done => {
let browser = testUtils.browser;
browser.visit('/api/entries.cascade.flat.' + format, () => {
checkResponse(browser, 4);
done();
});
});

it('All current, year: ' + year, done => {
let browser = testUtils.browser;
browser.visit('/api/entries/' + year + '.' + format, () => {
Expand Down Expand Up @@ -137,6 +145,21 @@ describe('API', function() {
});
});

describe('Flat entries (data)', function() {
it('Cascade current', done => {
let browser = testUtils.browser;
browser.visit('/api/entries.cascade.flat.json', () => {
browser.assert.success();
const data = JSON.parse(browser.text());
const item = data.results[0];
assert.deepEqual(item['Format 1'], 'AsciiDoc')
assert.deepEqual(item['Format 2'], 'CSV')
assert.deepEqual(item['Format 3'], 'HTML')
done();
});
});
});

describe('Places', function() {
_.forEach(_.keys(responseFormats), format => {
let checkResponse = responseFormats[format];
Expand Down

0 comments on commit bb492eb

Please sign in to comment.