Skip to content

Commit

Permalink
add user-repository tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-fei committed May 22, 2020
1 parent d8bbc7c commit 567c9da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/user-repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const db = require('./db')

module.exports = {
findNotYetReceivedNewsletter: () => {
return db.get('users').find({
lastEmailSentAt: null
})
}
}
15 changes: 15 additions & 0 deletions lib/user-repository.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const test = require('ava')
const db = require('./db')
const userRepository = require('./user-repository')

test.beforeEach(async () => {
await db.get('users').remove({})
})

test('find users that did not yet receive the newsletter', async t => {
await db.get('users').insert({ name: 'test', email: '[email protected]', lastEmailSentAt: null })

const users = await userRepository.findNotYetReceivedNewsletter()
t.true(Array.isArray(users))
t.is(users.length, 1)
})

0 comments on commit 567c9da

Please sign in to comment.