improved tests
This commit is contained in:
parent
c61b8f4448
commit
f7a682612a
@ -351,19 +351,17 @@
|
||||
|
||||
emailPlugin.createVerificationSecretAndSendEmail = function(email, callback) {
|
||||
emailPlugin.createVerificationSecret(email, function(err, secret) {
|
||||
if (err) {
|
||||
if (err || !secret) {
|
||||
logger.error('error saving verification secret', email, secret, err);
|
||||
return callback(emailPlugin.errors.INTERNAL_ERROR);
|
||||
}
|
||||
if (secret) {
|
||||
emailPlugin.sendVerificationEmail(email, secret, function (err, res) {
|
||||
if (err) {
|
||||
logger.error('error sending verification email', email, secret, err);
|
||||
return callback(emailPlugin.errors.ERROR_SENDING_EMAIL);
|
||||
}
|
||||
return callback();
|
||||
});
|
||||
}
|
||||
emailPlugin.sendVerificationEmail(email, secret, function (err, res) {
|
||||
if (err) {
|
||||
logger.error('error sending verification email', email, secret, err);
|
||||
return callback(emailPlugin.errors.ERROR_SENDING_EMAIL);
|
||||
}
|
||||
return callback();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ describe('emailstore test', function() {
|
||||
leveldb_stub.get = sinon.stub();
|
||||
leveldb_stub.del = sinon.stub();
|
||||
var email_stub = sinon.stub();
|
||||
email_stub.sendMail = sinon.stub();
|
||||
email_stub.sendMail = sinon.stub().callsArg(1);
|
||||
|
||||
var cryptoMock = {
|
||||
randomBytes: sinon.stub()
|
||||
@ -199,7 +199,6 @@ describe('emailstore test', function() {
|
||||
});
|
||||
|
||||
describe('creating verification secret', function() {
|
||||
var sendVerificationEmail = sinon.stub(plugin, 'sendVerificationEmail');
|
||||
var fakeEmail = 'fake@email.com';
|
||||
var fakeRandom = 'fakerandom';
|
||||
var randomBytes = {
|
||||
@ -211,8 +210,8 @@ describe('emailstore test', function() {
|
||||
beforeEach(function() {
|
||||
leveldb_stub.get.reset();
|
||||
leveldb_stub.put.reset();
|
||||
plugin.email.sendMail.reset();
|
||||
|
||||
sendVerificationEmail.reset();
|
||||
cryptoMock.randomBytes = sinon.stub();
|
||||
cryptoMock.randomBytes.onFirstCall().returns(randomBytes);
|
||||
});
|
||||
@ -235,11 +234,11 @@ describe('emailstore test', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('calls the function to verify the email', function(done) {
|
||||
it('sends verification email', function(done) {
|
||||
setupLevelDb();
|
||||
|
||||
plugin.createVerificationSecretAndSendEmail(fakeEmail, function(err) {
|
||||
sendVerificationEmail.calledOnce;
|
||||
plugin.email.sendMail.calledOnce.should.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -260,10 +259,6 @@ describe('emailstore test', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
after(function() {
|
||||
plugin.sendVerificationEmail.restore();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user