Fix integration tests for verification email matching

This commit is contained in:
Tankred Hase 2017-08-19 17:52:15 +08:00 committed by Martin Hauck
parent 0852822055
commit 92df122435
No known key found for this signature in database
GPG Key ID: 16A77ADCADE027B1
2 changed files with 22 additions and 12 deletions

View File

@ -3,6 +3,7 @@
const request = require('supertest'); const request = require('supertest');
const Mongo = require('../../src/dao/mongo'); const Mongo = require('../../src/dao/mongo');
const nodemailer = require('nodemailer'); const nodemailer = require('nodemailer');
const templates = require('../../src/email/templates');
const config = require('config'); const config = require('config');
const fs = require('fs'); const fs = require('fs');
const log = require('winston'); const log = require('winston');
@ -31,14 +32,17 @@ describe('Koa App (HTTP Server) Integration Tests', function() {
mongo = new Mongo(); mongo = new Mongo();
await mongo.init(config.mongo); await mongo.init(config.mongo);
sendEmailStub = sandbox.stub().returns(Promise.resolve({response: '250'})); const paramMatcher = sinon.match(params => {
sendEmailStub.withArgs(sinon.match(recipient => recipient.to.address === primaryEmail), sinon.match(params => {
emailParams = params; emailParams = params;
return Boolean(params.nonce); return Boolean(params.nonce);
})); });
sandbox.spy(templates, 'verifyKey').withArgs(paramMatcher);
sandbox.spy(templates, 'verifyRemove').withArgs(paramMatcher);
sendEmailStub = sandbox.stub().returns(Promise.resolve({response: '250'}));
sendEmailStub.withArgs(sinon.match(sendOptions => sendOptions.to.address === primaryEmail));
sandbox.stub(nodemailer, 'createTransport').returns({ sandbox.stub(nodemailer, 'createTransport').returns({
templateSender: () => sendEmailStub, sendMail: sendEmailStub
use() {}
}); });
const init = require('../../src/app'); const init = require('../../src/app');

View File

@ -7,6 +7,7 @@ const Email = require('../../src/email/email');
const Mongo = require('../../src/dao/mongo'); const Mongo = require('../../src/dao/mongo');
const PGP = require('../../src/service/pgp'); const PGP = require('../../src/service/pgp');
const PublicKey = require('../../src/service/public-key'); const PublicKey = require('../../src/service/public-key');
const templates = require('../../src/email/templates');
describe('Public Key Integration Tests', function() { describe('Public Key Integration Tests', function() {
this.timeout(20000); this.timeout(20000);
@ -37,19 +38,24 @@ describe('Public Key Integration Tests', function() {
sandbox = sinon.sandbox.create(); sandbox = sinon.sandbox.create();
await mongo.clear(DB_TYPE); await mongo.clear(DB_TYPE);
mailsSent = []; mailsSent = [];
sendEmailStub = sinon.stub().returns(Promise.resolve({response: '250'})); const paramMatcher = sinon.match(params => {
sendEmailStub.withArgs(sinon.match(recipient => { mailsSent[mailsSent.length] = {params};
mailsSent[mailsSent.length] = {to: recipient.to.address};
return true;
}), sinon.match(params => {
mailsSent[mailsSent.length - 1].params = params;
expect(params.nonce).to.exist; expect(params.nonce).to.exist;
expect(params.keyId).to.exist; expect(params.keyId).to.exist;
return true; return true;
});
sandbox.spy(templates, 'verifyKey').withArgs(paramMatcher);
sandbox.spy(templates, 'verifyRemove').withArgs(paramMatcher);
sendEmailStub = sinon.stub().returns(Promise.resolve({response: '250'}));
sendEmailStub.withArgs(sinon.match(sendOptions => {
mailsSent[mailsSent.length - 1].to = sendOptions.to.address;
return true;
})); }));
sandbox.stub(nodemailer, 'createTransport').returns({ sandbox.stub(nodemailer, 'createTransport').returns({
templateSender: () => sendEmailStub sendMail: sendEmailStub
}); });
email = new Email(nodemailer); email = new Email(nodemailer);
email.init({ email.init({