diff --git a/test/integration/app-test.js b/test/integration/app-test.js index 63bd9ad..908e81e 100644 --- a/test/integration/app-test.js +++ b/test/integration/app-test.js @@ -3,6 +3,7 @@ const request = require('supertest'); const Mongo = require('../../src/dao/mongo'); const nodemailer = require('nodemailer'); +const templates = require('../../src/email/templates'); const config = require('config'); const fs = require('fs'); const log = require('winston'); @@ -31,14 +32,17 @@ describe('Koa App (HTTP Server) Integration Tests', function() { mongo = new Mongo(); await mongo.init(config.mongo); - sendEmailStub = sandbox.stub().returns(Promise.resolve({response: '250'})); - sendEmailStub.withArgs(sinon.match(recipient => recipient.to.address === primaryEmail), sinon.match(params => { + const paramMatcher = sinon.match(params => { emailParams = params; 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({ - templateSender: () => sendEmailStub, - use() {} + sendMail: sendEmailStub }); const init = require('../../src/app'); diff --git a/test/integration/public-key-test.js b/test/integration/public-key-test.js index cd2c32f..3daf4a5 100644 --- a/test/integration/public-key-test.js +++ b/test/integration/public-key-test.js @@ -7,6 +7,7 @@ const Email = require('../../src/email/email'); const Mongo = require('../../src/dao/mongo'); const PGP = require('../../src/service/pgp'); const PublicKey = require('../../src/service/public-key'); +const templates = require('../../src/email/templates'); describe('Public Key Integration Tests', function() { this.timeout(20000); @@ -37,19 +38,24 @@ describe('Public Key Integration Tests', function() { sandbox = sinon.sandbox.create(); await mongo.clear(DB_TYPE); + mailsSent = []; - sendEmailStub = sinon.stub().returns(Promise.resolve({response: '250'})); - sendEmailStub.withArgs(sinon.match(recipient => { - mailsSent[mailsSent.length] = {to: recipient.to.address}; - return true; - }), sinon.match(params => { - mailsSent[mailsSent.length - 1].params = params; + const paramMatcher = sinon.match(params => { + mailsSent[mailsSent.length] = {params}; expect(params.nonce).to.exist; expect(params.keyId).to.exist; 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({ - templateSender: () => sendEmailStub + sendMail: sendEmailStub }); email = new Email(nodemailer); email.init({