Skip to content

Commit

Permalink
Add tests for the recently added search functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fleischie committed Aug 4, 2017
1 parent 21af31c commit 36e0a79
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/automated-script.sh
Expand Up @@ -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'
Expand Down
37 changes: 37 additions & 0 deletions tests/db-tests.js
Expand Up @@ -6,6 +6,7 @@ import {
updateDatabase,
getDateReport,
getFullReport,
getSearchTerm,
removeDatabase,
calculateWorkHours
} from '../lib/db.js'
Expand Down Expand Up @@ -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)
})
12 changes: 11 additions & 1 deletion tests/test.js
Expand Up @@ -3,7 +3,8 @@
import test from 'ava'
import {
printSingleDayReport,
printAllDaysReport
printAllDaysReport,
printSearchResults
} from '../lib/utils/helpers.js'

const moment = require('moment')
Expand Down Expand Up @@ -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))
})

0 comments on commit 36e0a79

Please sign in to comment.