From bb492ebd67b4f8c63060454409eaa180839a6b0b Mon Sep 17 00:00:00 2001 From: roll Date: Tue, 3 Jul 2018 15:08:58 +0300 Subject: [PATCH] Added Current (Flat CSV) tests --- .eslintrc | 2 +- census/controllers/api.js | 10 +++++----- tests/api.js | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.eslintrc b/.eslintrc index aad92a0a..a752cd56 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,7 +12,7 @@ parserOptions: rules: max-len: - error - - code: 90 + - code: 100 ignoreStrings: true strict: - error diff --git a/census/controllers/api.js b/census/controllers/api.js index a9f70e60..fcf86030 100644 --- a/census/controllers/api.js +++ b/census/controllers/api.js @@ -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 diff --git a/tests/api.js b/tests/api.js index 0f6c1b19..eda72b5c 100644 --- a/tests/api.js +++ b/tests/api.js @@ -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, () => { @@ -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];