Skip to content

Commit

Permalink
ft 164489793 writing test for the user notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Harerimana authored and Frank Harerimana committed Apr 26, 2019
1 parent 19a0760 commit 02bce11
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
5 changes: 2 additions & 3 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import Mailer from '../helpers/mailer';
import helper from '../helpers/helper';
import blacklist from '../helpers/redis';
import { sendAccountVerification as mailingHelper } from '../helpers/mailing';

import ArticleEvents from '../helpers/userEvents';
import UserEvents from '../helpers/userEvents';
/* eslint-disable class-methods-use-this */

const notify = new ArticleEvents();
const notify = new UserEvents();
// register events
notify.on('verified', args => notify.verifyingAccount(args));
const { Op } = Sequelize;
Expand Down
4 changes: 2 additions & 2 deletions helpers/userEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import userNotification from '../controllers/userNotification';
/**
* notification handler
*/
class ArticleEvents extends EventEmitter {
class UserEvents extends EventEmitter {
/**
* @author frank harerimana
* @param {*} userid
Expand All @@ -17,4 +17,4 @@ class ArticleEvents extends EventEmitter {
}
}

export default ArticleEvents;
export default UserEvents;
41 changes: 41 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import chai from 'chai';
import debug from 'debug';
import dotenv from 'dotenv';
import faker from 'faker';
import Mailer from '../helpers/mailer';
import userEvents from '../helpers/userEvents';

dotenv.config();
process.env.NODE_ENV = 'test';
chai.should();

const logError = debug('app:*');

const data = {
email: faker.internet.email(),
subject: faker.random.words(),
message: faker.lorem.paragraphs(),
footer: faker.lorem.sentences()
};
describe('mailer class', () => {
it('should be able to send email', async () => {
try {
const res = await Mailer.messageMaker(data.email, data.subject, data.message, data.footer);
res.should.be.a('boolean');
} catch (error) {
logError(error);
}
});
});

describe('user event handler', () => {
it('should pass data to the controller and return sucess', async () => {
try {
const event = new userEvents();
const res = event.verifyingAccount(faker.random.number());
res.should.be.a('string');
} catch (error) {
logError(error);
}
});
});
Empty file removed test/mailer.js
Empty file.
2 changes: 1 addition & 1 deletion test/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('/ sending mail to client', () => {
it('it should be able to deliver send email', async () => {
const client = faker.internet.email();
const subject = 'testing purpose';
const result = await new Mailer(client, subject).sender();
const result = await new Mailer(client, subject, faker.internet.url()).sender();
result.should.be.a('string');
});
});
Expand Down

0 comments on commit 02bce11

Please sign in to comment.