Skip to content

Commit

Permalink
fix(test): testing mail sending to a user when registering
Browse files Browse the repository at this point in the history
  • Loading branch information
serge1peshcoff committed Apr 5, 2020
1 parent 9e3fb59 commit 127146d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions test/api/campaigns-submission.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,31 @@ describe('Campaign submission', () => {
expect(res.body.superadmin).not.toEqual(true);
});

test('should send a mail to user', async () => {
const campaign = await generator.createCampaign({});
const user = generator.generateUser();

const requestsMock = mock.mockAll({
mailer: {
body: (body) => body.to === user.email.toLowerCase()
}
});

const res = await request({
uri: '/signup/' + campaign.url,
method: 'POST',
headers: { 'X-Auth-Token': 'blablabla' },
body: user
});

expect(res.statusCode).toEqual(200);
expect(res.body.success).toEqual(true);
expect(res.body).toHaveProperty('data');
expect(res.body).not.toHaveProperty('errors');

expect(requestsMock.mailer.isDone()).toEqual(true);
});

test('should fail when mailer returns net error', async () => {
mock.mockAll({ mailer: { netError: true } });

Expand Down
2 changes: 1 addition & 1 deletion test/scripts/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports.mockMailer = (options) => {

return nock(`${config.mailer.url}:${config.mailer.port}`)
.persist()
.post('/')
.post('/', options.body)
.reply(200, { success: true });
};

Expand Down

0 comments on commit 127146d

Please sign in to comment.