From 5c675474d7d7672bed5dbbb6b50b3874ea76004c Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Tue, 31 May 2016 13:52:18 +0200 Subject: [PATCH] Use arrow functions in mocha tests --- test/integration/app-test.js | 20 ++++++++++---------- test/integration/email-test.js | 6 +++--- test/integration/mongo-test.js | 14 ++++++-------- test/integration/user-id-test.js | 12 +++++------- test/unit/email-test.js | 28 ++++++++++++++-------------- 5 files changed, 38 insertions(+), 42 deletions(-) diff --git a/test/integration/app-test.js b/test/integration/app-test.js index 0d9d3d1..fbb5701 100644 --- a/test/integration/app-test.js +++ b/test/integration/app-test.js @@ -17,9 +17,9 @@ describe.skip('Koa App (HTTP Server) Integration Tests', function() { app = yield init(); }); - describe('REST api', function() { - describe('POST /api/v1/key', function() { - it('should return 400 for an invalid body', function (done) { + describe('REST api', () => { + describe('POST /api/v1/key', () => { + it('should return 400 for an invalid body', done => { request(app.listen()) .post('/api/v1/key') .send({ foo: 'bar' }) @@ -29,16 +29,16 @@ describe.skip('Koa App (HTTP Server) Integration Tests', function() { }); }); - describe('HKP api', function() { - describe('GET /pks/add', function() { - it.skip('should return 200 for a valid request', function (done) { + describe('HKP api', () => { + describe('GET /pks/add', () => { + it.skip('should return 200 for a valid request', done => { request(app.listen()) .get('/pks/lookup?op=get&search=0xDBC0B3D92B1B86E9') .expect(200) .end(done); }); - it('should return 404 if not found', function (done) { + it('should return 404 if not found', done => { request(app.listen()) .get('/pks/lookup?op=get&search=0xDBC0B3D92A1B86E9') .expect(404) @@ -46,8 +46,8 @@ describe.skip('Koa App (HTTP Server) Integration Tests', function() { }); }); - describe('POST /pks/add', function() { - it('should return 400 for an invalid body', function (done) { + describe('POST /pks/add', () => { + it('should return 400 for an invalid body', done => { request(app.listen()) .post('/pks/add') .type('form') @@ -56,7 +56,7 @@ describe.skip('Koa App (HTTP Server) Integration Tests', function() { .end(done); }); - it('should return 201 for a valid PGP key', function (done) { + it('should return 201 for a valid PGP key', done => { request(app.listen()) .post('/pks/add') .type('form') diff --git a/test/integration/email-test.js b/test/integration/email-test.js index d7aefce..dc772ae 100644 --- a/test/integration/email-test.js +++ b/test/integration/email-test.js @@ -15,7 +15,7 @@ describe('Email Integration Tests', function() { let email, credentials; - before(function() { + before(() => { try { credentials = require('../../credentials.json'); } catch(e) { @@ -37,7 +37,7 @@ describe('Email Integration Tests', function() { }); }); - describe("send", function() { + describe("send", () => { it('should work', function *() { let mailOptions = { from: credentials.sender, @@ -51,7 +51,7 @@ describe('Email Integration Tests', function() { }); }); - describe("sendVerifyKey", function() { + describe("sendVerifyKey", () => { it('should work', function *() { let options = { userIds: [{ diff --git a/test/integration/mongo-test.js b/test/integration/mongo-test.js index 1f11566..cf375ec 100644 --- a/test/integration/mongo-test.js +++ b/test/integration/mongo-test.js @@ -31,14 +31,12 @@ describe('Mongo Integration Tests', function() { yield mongo.clear(DB_TYPE); }); - afterEach(function() {}); - after(function *() { yield mongo.clear(DB_TYPE); yield mongo.disconnect(); }); - describe("create", function() { + describe("create", () => { it('should insert a document', function *() { let r = yield mongo.create({ _id:'0' }, DB_TYPE); expect(r.insertedCount).to.equal(1); @@ -55,7 +53,7 @@ describe('Mongo Integration Tests', function() { }); }); - describe("batch", function() { + describe("batch", () => { it('should insert a document', function *() { let r = yield mongo.batch([{ _id:'0' }, { _id:'1' }], DB_TYPE); expect(r.insertedCount).to.equal(2); @@ -72,7 +70,7 @@ describe('Mongo Integration Tests', function() { }); }); - describe("update", function() { + describe("update", () => { it('should update a document', function *() { let r = yield mongo.create({ _id:'0' }, DB_TYPE); r = yield mongo.update({ _id:'0' }, { foo:'bar' }, DB_TYPE); @@ -82,7 +80,7 @@ describe('Mongo Integration Tests', function() { }); }); - describe("get", function() { + describe("get", () => { it('should get a document', function *() { let r = yield mongo.create({ _id:'0' }, DB_TYPE); r = yield mongo.get({ _id:'0' }, DB_TYPE); @@ -90,7 +88,7 @@ describe('Mongo Integration Tests', function() { }); }); - describe("list", function() { + describe("list", () => { it('should list documents', function *() { let r = yield mongo.batch([{ _id:'0', foo:'bar' }, { _id:'1', foo:'bar' }], DB_TYPE); r = yield mongo.list({ foo:'bar' }, DB_TYPE); @@ -98,7 +96,7 @@ describe('Mongo Integration Tests', function() { }); }); - describe("remove", function() { + describe("remove", () => { it('should remove a document', function *() { let r = yield mongo.create({ _id:'0' }, DB_TYPE); r = yield mongo.remove({ _id:'0' }, DB_TYPE); diff --git a/test/integration/user-id-test.js b/test/integration/user-id-test.js index 77f643e..e3a0388 100644 --- a/test/integration/user-id-test.js +++ b/test/integration/user-id-test.js @@ -42,14 +42,12 @@ describe('User ID Integration Tests', function() { yield mongo.clear(DB_TYPE); }); - afterEach(function() {}); - after(function *() { yield mongo.clear(DB_TYPE); yield mongo.disconnect(); }); - describe("batch", function() { + describe("batch", () => { it('should persist all the things', function *() { let uids = yield userId.batch({ userIds:[uid1, uid2], keyid }); expect(uids[0].keyid).to.equal(keyid); @@ -63,7 +61,7 @@ describe('User ID Integration Tests', function() { }); }); - describe("verify", function() { + describe("verify", () => { it('should update the document', function *() { let uids = yield userId.batch({ userIds:[uid1], keyid }); yield userId.verify({ keyid, nonce:uids[0].nonce }); @@ -85,7 +83,7 @@ describe('User ID Integration Tests', function() { }); }); - describe("getVerfied", function() { + describe("getVerfied", () => { beforeEach(function *() { let uids = yield userId.batch({ userIds:[uid1], keyid }); yield userId.verify({ keyid, nonce:uids[0].nonce }); @@ -102,7 +100,7 @@ describe('User ID Integration Tests', function() { }); }); - describe("flagForRemove", function() { + describe("flagForRemove", () => { it('should flag all documents', function *() { let stored = yield userId.batch({ userIds:[uid1, uid2], keyid }); let flagged = yield userId.flagForRemove({ keyid }); @@ -113,7 +111,7 @@ describe('User ID Integration Tests', function() { }); }); - describe("remove", function() { + describe("remove", () => { it('should delete all documents', function *() { yield userId.batch({ userIds:[uid1, uid2], keyid }); yield userId.remove({ keyid }); diff --git a/test/unit/email-test.js b/test/unit/email-test.js index 4c9dbcf..7fe4504 100644 --- a/test/unit/email-test.js +++ b/test/unit/email-test.js @@ -9,7 +9,7 @@ const nodemailer = require('nodemailer'); const sinon = require('sinon'); -describe('Email Unit Tests', function() { +describe('Email Unit Tests', () => { let email, sendFnStub; let sender = { @@ -40,10 +40,10 @@ describe('Email Unit Tests', function() { html: 'Hello world 🐴' // html body }; - beforeEach(function() { + beforeEach(() => { sendFnStub = sinon.stub(); sinon.stub(nodemailer, 'createTransport').returns({ - templateSender: function() { return sendFnStub; } + templateSender: () => { return sendFnStub; } }); sinon.stub(log, 'warn'); @@ -58,19 +58,19 @@ describe('Email Unit Tests', function() { expect(email._sender).to.equal(sender); }); - afterEach(function() { + afterEach(() => { nodemailer.createTransport.restore(); log.warn.restore(); log.error.restore(); }); - describe("sendVerifyKey", function() { + describe("sendVerifyKey", () => { - beforeEach(function() { + beforeEach(() => { sinon.stub(email, '_sendVerifyKeyHelper').returns(Promise.resolve({ response:'250' })); }); - afterEach(function() { + afterEach(() => { email._sendVerifyKeyHelper.restore(); }); @@ -107,12 +107,12 @@ describe('Email Unit Tests', function() { }); }); - describe("_sendVerifyKeyHelper", function() { - beforeEach(function() { + describe("_sendVerifyKeyHelper", () => { + beforeEach(() => { sinon.stub(email, 'send').returns(Promise.resolve({ response:'250' })); }); - afterEach(function() { + afterEach(() => { email.send.restore(); }); @@ -123,12 +123,12 @@ describe('Email Unit Tests', function() { }); }); - describe("sendVerifyRemove", function() { - beforeEach(function() { + describe("sendVerifyRemove", () => { + beforeEach(() => { sinon.stub(email, 'send').returns(Promise.resolve({ response:'250' })); }); - afterEach(function() { + afterEach(() => { email.send.restore(); }); @@ -139,7 +139,7 @@ describe('Email Unit Tests', function() { }); }); - describe("send", function() { + describe("send", () => { it('should work', function *() { sendFnStub.returns(Promise.resolve({ response:'250' }));