added tests
This commit is contained in:
parent
946eafc96d
commit
83e6d9bad0
@ -761,7 +761,6 @@
|
|||||||
}, response);
|
}, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
var secret;
|
|
||||||
if (_.isObject(value)) {
|
if (_.isObject(value)) {
|
||||||
if (moment().isAfter(value.expires)) {
|
if (moment().isAfter(value.expires)) {
|
||||||
return emailPlugin.returnError(emailPlugin.errors.REGISTRATION_EXPIRED, response);
|
return emailPlugin.returnError(emailPlugin.errors.REGISTRATION_EXPIRED, response);
|
||||||
|
|||||||
@ -8,6 +8,7 @@ var bitcore = require('bitcore');
|
|||||||
var logger = require('../lib/logger').logger;
|
var logger = require('../lib/logger').logger;
|
||||||
var should = chai.should;
|
var should = chai.should;
|
||||||
var expect = chai.expect;
|
var expect = chai.expect;
|
||||||
|
var moment = require('moment');
|
||||||
|
|
||||||
logger.transports.console.level = 'non';
|
logger.transports.console.level = 'non';
|
||||||
|
|
||||||
@ -225,9 +226,12 @@ describe('emailstore test', function() {
|
|||||||
|
|
||||||
it('saves data under the expected key', function(done) {
|
it('saves data under the expected key', function(done) {
|
||||||
setupLevelDb();
|
setupLevelDb();
|
||||||
|
var clock = sinon.useFakeTimers();
|
||||||
plugin.createVerificationSecretAndSendEmail(fakeEmail, function(err) {
|
plugin.createVerificationSecretAndSendEmail(fakeEmail, function(err) {
|
||||||
leveldb_stub.put.firstCall.args[1].should.equal(fakeRandom);
|
var arg = leveldb_stub.put.firstCall.args[1];
|
||||||
|
arg.secret.should.equal(fakeRandom);
|
||||||
|
arg.expires.isSame(moment().add(7, 'days')).should.be.true;
|
||||||
|
clock.restore();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -363,7 +367,7 @@ describe('emailstore test', function() {
|
|||||||
response.json.returnsThis();
|
response.json.returnsThis();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should validate correctly an email if the secret matches', function() {
|
it('should validate correctly an email if the secret matches (without expiration date)', function() {
|
||||||
leveldb_stub.get.onFirstCall().callsArgWith(1, null, secret);
|
leveldb_stub.get.onFirstCall().callsArgWith(1, null, secret);
|
||||||
leveldb_stub.del = sinon.stub().yields(null);
|
leveldb_stub.del = sinon.stub().yields(null);
|
||||||
response.redirect = sinon.stub();
|
response.redirect = sinon.stub();
|
||||||
@ -373,6 +377,19 @@ describe('emailstore test', function() {
|
|||||||
assert(response.redirect.firstCall.calledWith(plugin.redirectUrl));
|
assert(response.redirect.firstCall.calledWith(plugin.redirectUrl));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should validate correctly an email if the secret matches (using expiration date)', function() {
|
||||||
|
leveldb_stub.get.onFirstCall().callsArgWith(1, null, {
|
||||||
|
secret: secret,
|
||||||
|
expires: moment().add(7, 'days')
|
||||||
|
});
|
||||||
|
leveldb_stub.del = sinon.stub().yields(null);
|
||||||
|
response.redirect = sinon.stub();
|
||||||
|
|
||||||
|
plugin.validate(request, response);
|
||||||
|
|
||||||
|
assert(response.redirect.firstCall.calledWith(plugin.redirectUrl));
|
||||||
|
});
|
||||||
|
|
||||||
it('should fail to validate an email if the secret doesn\'t match', function() {
|
it('should fail to validate an email if the secret doesn\'t match', function() {
|
||||||
var invalid = '3';
|
var invalid = '3';
|
||||||
leveldb_stub.get.onFirstCall().callsArgWith(1, null, invalid);
|
leveldb_stub.get.onFirstCall().callsArgWith(1, null, invalid);
|
||||||
@ -387,6 +404,23 @@ describe('emailstore test', function() {
|
|||||||
}));
|
}));
|
||||||
assert(response.end.calledOnce);
|
assert(response.end.calledOnce);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should fail to validate an email if the secret has expired', function() {
|
||||||
|
leveldb_stub.get.onFirstCall().callsArgWith(1, null, {
|
||||||
|
secret: secret,
|
||||||
|
expires: moment().subtract(2, 'days')
|
||||||
|
});
|
||||||
|
response.status.returnsThis();
|
||||||
|
response.json.returnsThis();
|
||||||
|
|
||||||
|
plugin.validate(request, response);
|
||||||
|
|
||||||
|
assert(response.status.firstCall.calledWith(plugin.errors.REGISTRATION_EXPIRED.code));
|
||||||
|
assert(response.json.firstCall.calledWith({
|
||||||
|
error: 'Registration expired'
|
||||||
|
}));
|
||||||
|
assert(response.end.calledOnce);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('removing items', function() {
|
describe('removing items', function() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user