From 36e0a79bb9da4b75f7a965045ca542a5456404ab Mon Sep 17 00:00:00 2001 From: Karl Fleischmann Date: Fri, 4 Aug 2017 18:08:26 +0200 Subject: [PATCH] Add tests for the recently added search functions --- tests/automated-script.sh | 12 ++++++++++++ tests/db-tests.js | 37 +++++++++++++++++++++++++++++++++++++ tests/test.js | 12 +++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/tests/automated-script.sh b/tests/automated-script.sh index 17e3eb53..b95b2ac4 100755 --- a/tests/automated-script.sh +++ b/tests/automated-script.sh @@ -59,6 +59,18 @@ echo 'Report all days' moro report --all echo 'ended' +echo 'Take a note' +moro note "# Testing moro" +echo 'ended' + +echo 'Take a hyphened note' +moro note "-5" +echo 'ended' + +echo 'Searching for a note' +moro search "#" +echo 'ended' + echo 'Let us clear the database if it exists' moro clear --yes echo 'ended' diff --git a/tests/db-tests.js b/tests/db-tests.js index fd725e82..5c77918f 100644 --- a/tests/db-tests.js +++ b/tests/db-tests.js @@ -6,6 +6,7 @@ import { updateDatabase, getDateReport, getFullReport, + getSearchTerm, removeDatabase, calculateWorkHours } from '../lib/db.js' @@ -107,3 +108,39 @@ test.serial('getFullReport outputs ok results', async t => { const results = await getFullReport(knexForTestsInMemory) t.deepEqual(results, okResults) }) + +test('getSearchTerm returns the desired note', async t => { + const record = { + breakDuration: 25, + date: '2017-08-04', + end: '17:35', + id: 1, + notes: [], + start: '09:15' + } + const note1 = { + date: '2017-08-04', + createdat: '17:00', + note: '#Workrelated', + action: 'addNote', + } + const note2 = { + date: '2017-08-04', + createdat: '17:30', + note: 'leisure', + action: 'addNote', + } + + const okResults = [{ + date: '2017-08-04', + createdat: '17:00', + note: '#Workrelated', + }] + + await updateDatabase(record, knexForTestsInMemory) + await updateDatabase(note1, knexForTestsInMemory) + await updateDatabase(note2, knexForTestsInMemory) + + const results = await getSearchTerm('related', knexForTestsInMemory) + t.deepEqual(results, okResults) +}) diff --git a/tests/test.js b/tests/test.js index 7a36abd8..c0fc0b81 100644 --- a/tests/test.js +++ b/tests/test.js @@ -3,7 +3,8 @@ import test from 'ava' import { printSingleDayReport, - printAllDaysReport + printAllDaysReport, + printSearchResults } from '../lib/utils/helpers.js' const moment = require('moment') @@ -40,3 +41,12 @@ test('printAllDaysReport with week change runs without crashing', t => { {date: '2017-03-15', workHours: diff('2017-03-15 09:10', '2017-03-15 17:10')}] t.pass(printAllDaysReport(reprotRecord)) }) + +test('printSearchResults runs without crashing', t => { + const searchResults = [ + { date: '2017-08-04', createdat: '17:00', note: '#Workrelated' }, + { date: '2017-08-04', createdat: '17:30', note: '#Workrelated' }, + { date: '2017-08-04', createdat: '18:00', note: 'Other project #related' } + ] + t.pass(printSearchResults(searchResults)) +})