Add space after async in async () =>

This commit is contained in:
Tankred Hase 2017-08-17 17:44:26 +08:00
parent 4081463dfa
commit a52cef2771
7 changed files with 70 additions and 66 deletions

View File

@ -41,7 +41,11 @@
"semi": ["warn", "always"], // require or disallow semicolons instead of ASI "semi": ["warn", "always"], // require or disallow semicolons instead of ASI
"semi-spacing": 1, // enforce consistent spacing before and after semicolons "semi-spacing": 1, // enforce consistent spacing before and after semicolons
"space-before-blocks": 1, // enforce consistent spacing before blocks "space-before-blocks": 1, // enforce consistent spacing before blocks
"space-before-function-paren": ["warn", "never"], // enforce consistent spacing before function definition opening parenthesis "space-before-function-paren": ["warn", {
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
}], // enforce consistent spacing before function definition opening parenthesis
"space-in-parens": ["warn", "never"], // enforce consistent spacing inside parentheses "space-in-parens": ["warn", "never"], // enforce consistent spacing inside parentheses
"space-infix-ops": 1, // require spacing around operators "space-infix-ops": 1, // require spacing around operators
/* ES6 */ /* ES6 */

View File

@ -54,7 +54,7 @@ router.get('/api/v1/key', ctx => rest.query(ctx));
router.del('/api/v1/key', ctx => rest.remove(ctx)); router.del('/api/v1/key', ctx => rest.remove(ctx));
// Redirect all http traffic to https // Redirect all http traffic to https
app.use(async(ctx, next) => { app.use(async (ctx, next) => {
if (util.isTrue(config.server.httpsUpgrade) && util.checkHTTP(ctx)) { if (util.isTrue(config.server.httpsUpgrade) && util.checkHTTP(ctx)) {
ctx.redirect(`https://${ctx.hostname}${ctx.url}`); ctx.redirect(`https://${ctx.hostname}${ctx.url}`);
} else { } else {
@ -63,7 +63,7 @@ app.use(async(ctx, next) => {
}); });
// Set HTTP response headers // Set HTTP response headers
app.use(async(ctx, next) => { app.use(async (ctx, next) => {
// HSTS // HSTS
if (util.isTrue(config.server.httpsUpgrade)) { if (util.isTrue(config.server.httpsUpgrade)) {
ctx.set('Strict-Transport-Security', 'max-age=16070400'); ctx.set('Strict-Transport-Security', 'max-age=16070400');
@ -121,7 +121,7 @@ function injectDependencies() {
// //
if (!global.testing) { // don't automatically start server in tests if (!global.testing) { // don't automatically start server in tests
(async() => { (async () => {
try { try {
const app = await init(); const app = await init();
app.listen(config.server.port); app.listen(config.server.port);

View File

@ -22,7 +22,7 @@ describe('Koa App (HTTP Server) Integration Tests', function() {
const primaryEmail = 'safewithme.testuser@gmail.com'; const primaryEmail = 'safewithme.testuser@gmail.com';
const fingerprint = '4277257930867231CE393FB8DBC0B3D92B1B86E9'; const fingerprint = '4277257930867231CE393FB8DBC0B3D92B1B86E9';
before(async() => { before(async () => {
sandbox = sinon.sandbox.create(); sandbox = sinon.sandbox.create();
publicKeyArmored = fs.readFileSync(`${__dirname}/../key1.asc`, 'utf8'); publicKeyArmored = fs.readFileSync(`${__dirname}/../key1.asc`, 'utf8');
@ -46,13 +46,13 @@ describe('Koa App (HTTP Server) Integration Tests', function() {
app = await init(); app = await init();
}); });
beforeEach(async() => { beforeEach(async () => {
await mongo.clear(DB_TYPE_PUB_KEY); await mongo.clear(DB_TYPE_PUB_KEY);
await mongo.clear(DB_TYPE_USER_ID); await mongo.clear(DB_TYPE_USER_ID);
emailParams = null; emailParams = null;
}); });
after(async() => { after(async () => {
sandbox.restore(); sandbox.restore();
await mongo.clear(DB_TYPE_PUB_KEY); await mongo.clear(DB_TYPE_PUB_KEY);
await mongo.clear(DB_TYPE_USER_ID); await mongo.clear(DB_TYPE_USER_ID);

View File

@ -36,7 +36,7 @@ describe('Email Integration Tests', function() {
}); });
describe("_sendHelper", () => { describe("_sendHelper", () => {
it('should work', async() => { it('should work', async () => {
const mailOptions = { const mailOptions = {
from: email._sender, from: email._sender,
to: recipient, to: recipient,
@ -50,23 +50,23 @@ describe('Email Integration Tests', function() {
}); });
describe("send verifyKey template", () => { describe("send verifyKey template", () => {
it('should send plaintext email', async() => { it('should send plaintext email', async () => {
delete userId.publicKeyArmored; delete userId.publicKeyArmored;
await email.send({template: tpl.verifyKey, userId, keyId, origin}); await email.send({template: tpl.verifyKey, userId, keyId, origin});
}); });
it('should send pgp encrypted email', async() => { it('should send pgp encrypted email', async () => {
await email.send({template: tpl.verifyKey, userId, keyId, origin}); await email.send({template: tpl.verifyKey, userId, keyId, origin});
}); });
}); });
describe("send verifyRemove template", () => { describe("send verifyRemove template", () => {
it('should send plaintext email', async() => { it('should send plaintext email', async () => {
delete userId.publicKeyArmored; delete userId.publicKeyArmored;
await email.send({template: tpl.verifyRemove, userId, keyId, origin}); await email.send({template: tpl.verifyRemove, userId, keyId, origin});
}); });
it('should send pgp encrypted email', async() => { it('should send pgp encrypted email', async () => {
await email.send({template: tpl.verifyRemove, userId, keyId, origin}); await email.send({template: tpl.verifyRemove, userId, keyId, origin});
}); });
}); });

View File

@ -9,27 +9,27 @@ describe('Mongo Integration Tests', function() {
const DB_TYPE = 'apple'; const DB_TYPE = 'apple';
let mongo; let mongo;
before(async() => { before(async () => {
mongo = new Mongo(); mongo = new Mongo();
await mongo.init(config.mongo); await mongo.init(config.mongo);
}); });
beforeEach(async() => { beforeEach(async () => {
await mongo.clear(DB_TYPE); await mongo.clear(DB_TYPE);
}); });
after(async() => { after(async () => {
await mongo.clear(DB_TYPE); await mongo.clear(DB_TYPE);
await mongo.disconnect(); await mongo.disconnect();
}); });
describe("create", () => { describe("create", () => {
it('should insert a document', async() => { it('should insert a document', async () => {
const r = await mongo.create({_id: '0'}, DB_TYPE); const r = await mongo.create({_id: '0'}, DB_TYPE);
expect(r.insertedCount).to.equal(1); expect(r.insertedCount).to.equal(1);
}); });
it('should fail if two with the same ID are inserted', async() => { it('should fail if two with the same ID are inserted', async () => {
let r = await mongo.create({_id: '0'}, DB_TYPE); let r = await mongo.create({_id: '0'}, DB_TYPE);
expect(r.insertedCount).to.equal(1); expect(r.insertedCount).to.equal(1);
try { try {
@ -41,12 +41,12 @@ describe('Mongo Integration Tests', function() {
}); });
describe("batch", () => { describe("batch", () => {
it('should insert a document', async() => { it('should insert a document', async () => {
const r = await mongo.batch([{_id: '0'}, {_id: '1'}], DB_TYPE); const r = await mongo.batch([{_id: '0'}, {_id: '1'}], DB_TYPE);
expect(r.insertedCount).to.equal(2); expect(r.insertedCount).to.equal(2);
}); });
it('should fail if docs with the same ID are inserted', async() => { it('should fail if docs with the same ID are inserted', async () => {
let r = await mongo.batch([{_id: '0'}, {_id: '1'}], DB_TYPE); let r = await mongo.batch([{_id: '0'}, {_id: '1'}], DB_TYPE);
expect(r.insertedCount).to.equal(2); expect(r.insertedCount).to.equal(2);
try { try {
@ -58,7 +58,7 @@ describe('Mongo Integration Tests', function() {
}); });
describe("update", () => { describe("update", () => {
it('should update a document', async() => { it('should update a document', async () => {
let r = await mongo.create({_id: '0'}, DB_TYPE); let r = await mongo.create({_id: '0'}, DB_TYPE);
r = await mongo.update({_id: '0'}, {foo: 'bar'}, DB_TYPE); r = await mongo.update({_id: '0'}, {foo: 'bar'}, DB_TYPE);
expect(r.modifiedCount).to.equal(1); expect(r.modifiedCount).to.equal(1);
@ -68,7 +68,7 @@ describe('Mongo Integration Tests', function() {
}); });
describe("get", () => { describe("get", () => {
it('should get a document', async() => { it('should get a document', async () => {
let r = await mongo.create({_id: '0'}, DB_TYPE); let r = await mongo.create({_id: '0'}, DB_TYPE);
r = await mongo.get({_id: '0'}, DB_TYPE); r = await mongo.get({_id: '0'}, DB_TYPE);
expect(r).to.exist; expect(r).to.exist;
@ -76,7 +76,7 @@ describe('Mongo Integration Tests', function() {
}); });
describe("list", () => { describe("list", () => {
it('should list documents', async() => { it('should list documents', async () => {
let r = await mongo.batch([{_id: '0', foo: 'bar'}, {_id: '1', foo: 'bar'}], DB_TYPE); let r = await mongo.batch([{_id: '0', foo: 'bar'}, {_id: '1', foo: 'bar'}], DB_TYPE);
r = await mongo.list({foo: 'bar'}, DB_TYPE); r = await mongo.list({foo: 'bar'}, DB_TYPE);
expect(r).to.deep.equal([{_id: '0', foo: 'bar'}, {_id: '1', foo: 'bar'}], DB_TYPE); expect(r).to.deep.equal([{_id: '0', foo: 'bar'}, {_id: '1', foo: 'bar'}], DB_TYPE);
@ -84,7 +84,7 @@ describe('Mongo Integration Tests', function() {
}); });
describe("remove", () => { describe("remove", () => {
it('should remove a document', async() => { it('should remove a document', async () => {
let r = await mongo.create({_id: '0'}, DB_TYPE); let r = await mongo.create({_id: '0'}, DB_TYPE);
r = await mongo.remove({_id: '0'}, DB_TYPE); r = await mongo.remove({_id: '0'}, DB_TYPE);
r = await mongo.get({_id: '0'}, DB_TYPE); r = await mongo.get({_id: '0'}, DB_TYPE);

View File

@ -25,14 +25,14 @@ describe('Public Key Integration Tests', function() {
const primaryEmail2 = 'test2@example.com'; const primaryEmail2 = 'test2@example.com';
const origin = {host: 'localhost', protocol: 'http'}; const origin = {host: 'localhost', protocol: 'http'};
before(async() => { before(async () => {
publicKeyArmored = require('fs').readFileSync(`${__dirname}/../key3.asc`, 'utf8'); publicKeyArmored = require('fs').readFileSync(`${__dirname}/../key3.asc`, 'utf8');
publicKeyArmored2 = require('fs').readFileSync(`${__dirname}/../key4.asc`, 'utf8'); publicKeyArmored2 = require('fs').readFileSync(`${__dirname}/../key4.asc`, 'utf8');
mongo = new Mongo(); mongo = new Mongo();
await mongo.init(config.mongo); await mongo.init(config.mongo);
}); });
beforeEach(async() => { beforeEach(async () => {
sandbox = sinon.sandbox.create(); sandbox = sinon.sandbox.create();
await mongo.clear(DB_TYPE); await mongo.clear(DB_TYPE);
@ -64,32 +64,32 @@ describe('Public Key Integration Tests', function() {
sandbox.restore(); sandbox.restore();
}); });
after(async() => { after(async () => {
await mongo.clear(DB_TYPE); await mongo.clear(DB_TYPE);
await mongo.disconnect(); await mongo.disconnect();
}); });
describe('put', () => { describe('put', () => {
it('should persist key and send verification email with primaryEmail', async() => { it('should persist key and send verification email with primaryEmail', async () => {
await publicKey.put({publicKeyArmored, primaryEmail, origin}); await publicKey.put({publicKeyArmored, primaryEmail, origin});
expect(mailsSent.length).to.equal(1); expect(mailsSent.length).to.equal(1);
expect(mailsSent[0].to).to.equal(primaryEmail); expect(mailsSent[0].to).to.equal(primaryEmail);
expect(mailsSent[0].params.keyId).to.exist; expect(mailsSent[0].params.keyId).to.exist;
expect(mailsSent[0].params.nonce).to.exist; expect(mailsSent[0].params.nonce).to.exist;
}); });
it('should persist key and send verification email without primaryEmail', async() => { it('should persist key and send verification email without primaryEmail', async () => {
await publicKey.put({publicKeyArmored, origin}); await publicKey.put({publicKeyArmored, origin});
expect(mailsSent.length).to.equal(4); expect(mailsSent.length).to.equal(4);
}); });
it('should work twice if not yet verified', async() => { it('should work twice if not yet verified', async () => {
await publicKey.put({publicKeyArmored, primaryEmail, origin}); await publicKey.put({publicKeyArmored, primaryEmail, origin});
expect(mailsSent.length).to.equal(1); expect(mailsSent.length).to.equal(1);
await publicKey.put({publicKeyArmored, primaryEmail, origin}); await publicKey.put({publicKeyArmored, primaryEmail, origin});
expect(mailsSent.length).to.equal(2); expect(mailsSent.length).to.equal(2);
}); });
it('should throw 304 if key already exists', async() => { it('should throw 304 if key already exists', async () => {
await publicKey.put({publicKeyArmored, primaryEmail, origin}); await publicKey.put({publicKeyArmored, primaryEmail, origin});
await publicKey.verify(mailsSent[0].params); await publicKey.verify(mailsSent[0].params);
try { try {
@ -102,7 +102,7 @@ describe('Public Key Integration Tests', function() {
}); });
describe('verify', () => { describe('verify', () => {
it('should update the document', async() => { it('should update the document', async () => {
await publicKey.put({publicKeyArmored, primaryEmail, origin}); await publicKey.put({publicKeyArmored, primaryEmail, origin});
const emailParams = mailsSent[0].params; const emailParams = mailsSent[0].params;
await publicKey.verify(emailParams); await publicKey.verify(emailParams);
@ -113,7 +113,7 @@ describe('Public Key Integration Tests', function() {
expect(gotten.userIds[1].nonce).to.exist; expect(gotten.userIds[1].nonce).to.exist;
}); });
it('should not find the document', async() => { it('should not find the document', async () => {
await publicKey.put({publicKeyArmored, primaryEmail, origin}); await publicKey.put({publicKeyArmored, primaryEmail, origin});
const emailParams = mailsSent[0].params; const emailParams = mailsSent[0].params;
try { try {
@ -129,7 +129,7 @@ describe('Public Key Integration Tests', function() {
expect(gotten.userIds[1].nonce).to.exist; expect(gotten.userIds[1].nonce).to.exist;
}); });
it('should not verify a second key for already verified user id of another key', async() => { it('should not verify a second key for already verified user id of another key', async () => {
await publicKey.put({publicKeyArmored, primaryEmail: primaryEmail2, origin}); await publicKey.put({publicKeyArmored, primaryEmail: primaryEmail2, origin});
expect(mailsSent.length).to.equal(1); expect(mailsSent.length).to.equal(1);
await publicKey.put({publicKeyArmored: publicKeyArmored2, primaryEmail: primaryEmail2, origin}); await publicKey.put({publicKeyArmored: publicKeyArmored2, primaryEmail: primaryEmail2, origin});
@ -148,7 +148,7 @@ describe('Public Key Integration Tests', function() {
expect(gotten.userIds[1].nonce).to.equal(mailsSent[0].params.nonce); expect(gotten.userIds[1].nonce).to.equal(mailsSent[0].params.nonce);
}); });
it('should be able to verify multiple user ids', async() => { it('should be able to verify multiple user ids', async () => {
await publicKey.put({publicKeyArmored, origin}); await publicKey.put({publicKeyArmored, origin});
expect(mailsSent.length).to.equal(4); expect(mailsSent.length).to.equal(4);
await publicKey.verify(mailsSent[0].params); await publicKey.verify(mailsSent[0].params);
@ -167,66 +167,66 @@ describe('Public Key Integration Tests', function() {
let key; let key;
describe('should find a verified key', () => { describe('should find a verified key', () => {
beforeEach(async() => { beforeEach(async () => {
key = pgp.parseKey(publicKeyArmored); key = pgp.parseKey(publicKeyArmored);
await publicKey.put({publicKeyArmored, primaryEmail, origin}); await publicKey.put({publicKeyArmored, primaryEmail, origin});
await publicKey.verify(mailsSent[0].params); await publicKey.verify(mailsSent[0].params);
}); });
it('by fingerprint', async() => { it('by fingerprint', async () => {
const verified = await publicKey.getVerified({fingerprint: key.fingerprint}); const verified = await publicKey.getVerified({fingerprint: key.fingerprint});
expect(verified).to.exist; expect(verified).to.exist;
}); });
it('by all userIds', async() => { it('by all userIds', async () => {
const verified = await publicKey.getVerified({userIds: key.userIds}); const verified = await publicKey.getVerified({userIds: key.userIds});
expect(verified).to.exist; expect(verified).to.exist;
}); });
it('by verified userId', async() => { it('by verified userId', async () => {
const verified = await publicKey.getVerified({userIds: [key.userIds[0]]}); const verified = await publicKey.getVerified({userIds: [key.userIds[0]]});
expect(verified).to.exist; expect(verified).to.exist;
}); });
it('by unverified userId', async() => { it('by unverified userId', async () => {
const verified = await publicKey.getVerified({userIds: [key.userIds[1]]}); const verified = await publicKey.getVerified({userIds: [key.userIds[1]]});
expect(verified).to.not.exist; expect(verified).to.not.exist;
}); });
it('by keyId', async() => { it('by keyId', async () => {
const verified = await publicKey.getVerified({keyId: key.keyId}); const verified = await publicKey.getVerified({keyId: key.keyId});
expect(verified).to.exist; expect(verified).to.exist;
}); });
it('by all params', async() => { it('by all params', async () => {
const verified = await publicKey.getVerified(key); const verified = await publicKey.getVerified(key);
expect(verified).to.exist; expect(verified).to.exist;
}); });
}); });
describe('should not find an unverified key', () => { describe('should not find an unverified key', () => {
beforeEach(async() => { beforeEach(async () => {
key = pgp.parseKey(publicKeyArmored); key = pgp.parseKey(publicKeyArmored);
key.userIds[0].verified = false; key.userIds[0].verified = false;
await mongo.create(key, DB_TYPE); await mongo.create(key, DB_TYPE);
}); });
it('by fingerprint', async() => { it('by fingerprint', async () => {
const verified = await publicKey.getVerified({fingerprint: key.fingerprint}); const verified = await publicKey.getVerified({fingerprint: key.fingerprint});
expect(verified).to.not.exist; expect(verified).to.not.exist;
}); });
it('by userIds', async() => { it('by userIds', async () => {
const verified = await publicKey.getVerified({userIds: key.userIds}); const verified = await publicKey.getVerified({userIds: key.userIds});
expect(verified).to.not.exist; expect(verified).to.not.exist;
}); });
it('by keyId', async() => { it('by keyId', async () => {
const verified = await publicKey.getVerified({keyId: key.keyId}); const verified = await publicKey.getVerified({keyId: key.keyId});
expect(verified).to.not.exist; expect(verified).to.not.exist;
}); });
it('by all params', async() => { it('by all params', async () => {
const verified = await publicKey.getVerified(key); const verified = await publicKey.getVerified(key);
expect(verified).to.not.exist; expect(verified).to.not.exist;
}); });
@ -236,50 +236,50 @@ describe('Public Key Integration Tests', function() {
describe('get', () => { describe('get', () => {
let emailParams; let emailParams;
beforeEach(async() => { beforeEach(async () => {
await publicKey.put({publicKeyArmored, primaryEmail, origin}); await publicKey.put({publicKeyArmored, primaryEmail, origin});
emailParams = mailsSent[0].params; emailParams = mailsSent[0].params;
}); });
it('should return verified key by key id', async() => { it('should return verified key by key id', async () => {
await publicKey.verify(emailParams); await publicKey.verify(emailParams);
const key = await publicKey.get({keyId: emailParams.keyId}); const key = await publicKey.get({keyId: emailParams.keyId});
expect(key.publicKeyArmored).to.exist; expect(key.publicKeyArmored).to.exist;
}); });
it('should return verified key by key id (uppercase)', async() => { it('should return verified key by key id (uppercase)', async () => {
await publicKey.verify(emailParams); await publicKey.verify(emailParams);
const key = await publicKey.get({keyId: emailParams.keyId.toUpperCase()}); const key = await publicKey.get({keyId: emailParams.keyId.toUpperCase()});
expect(key.publicKeyArmored).to.exist; expect(key.publicKeyArmored).to.exist;
}); });
it('should return verified key by fingerprint', async() => { it('should return verified key by fingerprint', async () => {
await publicKey.verify(emailParams); await publicKey.verify(emailParams);
const fingerprint = pgp.parseKey(publicKeyArmored).fingerprint; const fingerprint = pgp.parseKey(publicKeyArmored).fingerprint;
const key = await publicKey.get({fingerprint}); const key = await publicKey.get({fingerprint});
expect(key.publicKeyArmored).to.exist; expect(key.publicKeyArmored).to.exist;
}); });
it('should return verified key by fingerprint (uppercase)', async() => { it('should return verified key by fingerprint (uppercase)', async () => {
await publicKey.verify(emailParams); await publicKey.verify(emailParams);
const fingerprint = pgp.parseKey(publicKeyArmored).fingerprint.toUpperCase(); const fingerprint = pgp.parseKey(publicKeyArmored).fingerprint.toUpperCase();
const key = await publicKey.get({fingerprint}); const key = await publicKey.get({fingerprint});
expect(key.publicKeyArmored).to.exist; expect(key.publicKeyArmored).to.exist;
}); });
it('should return verified key by email address', async() => { it('should return verified key by email address', async () => {
await publicKey.verify(emailParams); await publicKey.verify(emailParams);
const key = await publicKey.get({email: primaryEmail}); const key = await publicKey.get({email: primaryEmail});
expect(key.publicKeyArmored).to.exist; expect(key.publicKeyArmored).to.exist;
}); });
it('should return verified key by email address (uppercase)', async() => { it('should return verified key by email address (uppercase)', async () => {
await publicKey.verify(emailParams); await publicKey.verify(emailParams);
const key = await publicKey.get({email: primaryEmail.toUpperCase()}); const key = await publicKey.get({email: primaryEmail.toUpperCase()});
expect(key.publicKeyArmored).to.exist; expect(key.publicKeyArmored).to.exist;
}); });
it('should throw 404 for unverified key', async() => { it('should throw 404 for unverified key', async () => {
try { try {
await publicKey.get({keyId: emailParams.keyId}); await publicKey.get({keyId: emailParams.keyId});
expect(false).to.be.true; expect(false).to.be.true;
@ -292,28 +292,28 @@ describe('Public Key Integration Tests', function() {
describe('requestRemove', () => { describe('requestRemove', () => {
let keyId; let keyId;
beforeEach(async() => { beforeEach(async () => {
await publicKey.put({publicKeyArmored, primaryEmail, origin}); await publicKey.put({publicKeyArmored, primaryEmail, origin});
keyId = mailsSent[0].params.keyId; keyId = mailsSent[0].params.keyId;
}); });
it('should work for verified key', async() => { it('should work for verified key', async () => {
await publicKey.verify(mailsSent[0].params); await publicKey.verify(mailsSent[0].params);
await publicKey.requestRemove({keyId, origin}); await publicKey.requestRemove({keyId, origin});
expect(mailsSent.length).to.equal(5); expect(mailsSent.length).to.equal(5);
}); });
it('should work for unverified key', async() => { it('should work for unverified key', async () => {
await publicKey.requestRemove({keyId, origin}); await publicKey.requestRemove({keyId, origin});
expect(mailsSent.length).to.equal(5); expect(mailsSent.length).to.equal(5);
}); });
it('should work by email address', async() => { it('should work by email address', async () => {
await publicKey.requestRemove({email: primaryEmail, origin}); await publicKey.requestRemove({email: primaryEmail, origin});
expect(mailsSent.length).to.equal(2); expect(mailsSent.length).to.equal(2);
}); });
it('should throw 404 for no key', async() => { it('should throw 404 for no key', async () => {
await mongo.remove({keyId}, DB_TYPE); await mongo.remove({keyId}, DB_TYPE);
try { try {
await publicKey.requestRemove({keyId, origin}); await publicKey.requestRemove({keyId, origin});
@ -327,19 +327,19 @@ describe('Public Key Integration Tests', function() {
describe('verifyRemove', () => { describe('verifyRemove', () => {
let keyId; let keyId;
beforeEach(async() => { beforeEach(async () => {
await publicKey.put({publicKeyArmored, primaryEmail, origin}); await publicKey.put({publicKeyArmored, primaryEmail, origin});
keyId = mailsSent[0].params.keyId; keyId = mailsSent[0].params.keyId;
await publicKey.requestRemove({keyId, origin}); await publicKey.requestRemove({keyId, origin});
}); });
it('should remove key', async() => { it('should remove key', async () => {
await publicKey.verifyRemove(mailsSent[1].params); await publicKey.verifyRemove(mailsSent[1].params);
const key = await mongo.get({keyId}, DB_TYPE); const key = await mongo.get({keyId}, DB_TYPE);
expect(key).to.not.exist; expect(key).to.not.exist;
}); });
it('should throw 404 for no key', async() => { it('should throw 404 for no key', async () => {
await mongo.remove({keyId}, DB_TYPE); await mongo.remove({keyId}, DB_TYPE);
try { try {
await publicKey.verifyRemove(mailsSent[1].params); await publicKey.verifyRemove(mailsSent[1].params);

View File

@ -64,7 +64,7 @@ describe('Email Unit Tests', () => {
sandbox.stub(email, '_sendHelper').returns(Promise.resolve({response: '250'})); sandbox.stub(email, '_sendHelper').returns(Promise.resolve({response: '250'}));
}); });
it('should work', async() => { it('should work', async () => {
const info = await email.send({template, userId: userId1, keyId, origin}); const info = await email.send({template, userId: userId1, keyId, origin});
expect(info.response).to.match(/^250/); expect(info.response).to.match(/^250/);
@ -72,7 +72,7 @@ describe('Email Unit Tests', () => {
}); });
describe("_sendHelper", () => { describe("_sendHelper", () => {
it('should work', async() => { it('should work', async () => {
sendFnStub.returns(Promise.resolve({response: '250'})); sendFnStub.returns(Promise.resolve({response: '250'}));
const info = await email._sendHelper(mailOptions); const info = await email._sendHelper(mailOptions);
@ -80,7 +80,7 @@ describe('Email Unit Tests', () => {
expect(info.response).to.match(/^250/); expect(info.response).to.match(/^250/);
}); });
it('should log warning for reponse error', async() => { it('should log warning for reponse error', async () => {
sendFnStub.returns(Promise.resolve({response: '554'})); sendFnStub.returns(Promise.resolve({response: '554'}));
const info = await email._sendHelper(mailOptions); const info = await email._sendHelper(mailOptions);
@ -89,7 +89,7 @@ describe('Email Unit Tests', () => {
expect(log.warn.calledOnce).to.be.true; expect(log.warn.calledOnce).to.be.true;
}); });
it('should fail', async() => { it('should fail', async () => {
sendFnStub.returns(Promise.reject(new Error('boom'))); sendFnStub.returns(Promise.reject(new Error('boom')));
try { try {