From 8c4f35daf4e7fcea71fcbfe9e076588bb664db8d Mon Sep 17 00:00:00 2001 From: shalott Date: Tue, 15 Nov 2016 13:21:46 -0500 Subject: [PATCH] Fixing test failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test seems to occasionally start failing (another coder reported the same thing happening to them in the blacksmiths’ guild) because the order in which the tasks are created can sometimes not match the order in the array. So I have sorted the tasks array after creation by the task name to ensure a consistent ordering, and slightly reordered the expect statements to match. --- .../dataexport/GET-export_history.csv.test.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/api/v3/integration/dataexport/GET-export_history.csv.test.js b/test/api/v3/integration/dataexport/GET-export_history.csv.test.js index fafc55d7cb..13e03fd6b0 100644 --- a/test/api/v3/integration/dataexport/GET-export_history.csv.test.js +++ b/test/api/v3/integration/dataexport/GET-export_history.csv.test.js @@ -10,12 +10,17 @@ describe('GET /export/history.csv', () => { it('should return a valid CSV file with tasks history data', async () => { let user = await generateUser(); let tasks = await user.post('/tasks/user', [ - {type: 'habit', text: 'habit 1'}, {type: 'daily', text: 'daily 1'}, + {type: 'habit', text: 'habit 1'}, {type: 'habit', text: 'habit 2'}, {type: 'todo', text: 'todo 1'}, ]); + // to handle occasional inconsistency in task creation order + tasks.sort(function (a, b) { + return a.text.localeCompare(b.text); + }); + // score all the tasks twice await user.post(`/tasks/${tasks[0]._id}/score/up`); await user.post(`/tasks/${tasks[1]._id}/score/up`); @@ -28,7 +33,7 @@ describe('GET /export/history.csv', () => { await user.post(`/tasks/${tasks[3]._id}/score/up`); // adding an history entry to daily 1 manually because cron didn't run yet - await updateDocument('tasks', tasks[1], { + await updateDocument('tasks', tasks[0], { history: [{value: 3.2, date: Number(new Date())}], }); @@ -41,9 +46,9 @@ describe('GET /export/history.csv', () => { let splitRes = res.split('\n'); expect(splitRes[0]).to.equal('Task Name,Task ID,Task Type,Date,Value'); - expect(splitRes[1]).to.equal(`habit 1,${tasks[0]._id},habit,${moment(tasks[0].history[0].date).format('YYYY-MM-DD HH:mm:ss')},${tasks[0].history[0].value}`); - expect(splitRes[2]).to.equal(`habit 1,${tasks[0]._id},habit,${moment(tasks[0].history[1].date).format('YYYY-MM-DD HH:mm:ss')},${tasks[0].history[1].value}`); - expect(splitRes[3]).to.equal(`daily 1,${tasks[1]._id},daily,${moment(tasks[1].history[0].date).format('YYYY-MM-DD HH:mm:ss')},${tasks[1].history[0].value}`); + expect(splitRes[1]).to.equal(`daily 1,${tasks[0]._id},daily,${moment(tasks[0].history[0].date).format('YYYY-MM-DD HH:mm:ss')},${tasks[0].history[0].value}`); + expect(splitRes[2]).to.equal(`habit 1,${tasks[1]._id},habit,${moment(tasks[1].history[0].date).format('YYYY-MM-DD HH:mm:ss')},${tasks[1].history[0].value}`); + expect(splitRes[3]).to.equal(`habit 1,${tasks[1]._id},habit,${moment(tasks[1].history[1].date).format('YYYY-MM-DD HH:mm:ss')},${tasks[1].history[1].value}`); expect(splitRes[4]).to.equal(`habit 2,${tasks[2]._id},habit,${moment(tasks[2].history[0].date).format('YYYY-MM-DD HH:mm:ss')},${tasks[2].history[0].value}`); expect(splitRes[5]).to.equal(`habit 2,${tasks[2]._id},habit,${moment(tasks[2].history[1].date).format('YYYY-MM-DD HH:mm:ss')},${tasks[2].history[1].value}`); expect(splitRes[6]).to.equal('');