-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
24 lines (18 loc) · 858 Bytes
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const test = require('ava')
const sinon = require('sinon')
const { UsersCollection } = require('./lib/db')
const userRepository = require('./lib/user-repository')
const emailService = require('./lib/email-service')
const newsletter = require('.')
test.beforeEach(async () => {
await UsersCollection.remove({})
})
test('sends a newsletter to users that did not yet receive it', async t => {
await UsersCollection.insert({ name: 'test', email: '[email protected]', lastEmailSentAt: null })
sinon.spy(userRepository, 'findNotYetReceivedNewsletter')
sinon.stub(emailService, 'sendTo')
await newsletter.run(userRepository, emailService)
t.is(userRepository.findNotYetReceivedNewsletter.callCount, 1)
t.is(emailService.sendTo.callCount, 1)
// implement your assertions about arguments, like "recipient", "subject", "content" of the email etc.
})