From aafc2fefd6049962d6c476e187f39eb70f1d49f7 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Wed, 25 May 2016 07:12:15 +0200 Subject: [PATCH 1/3] Rename and refactor existing plugins Rename the existing plugins to match the new naming convention. Fix bugs / refactor code / enhance test coverage alongside. --- bin/serverless | 2 +- lib/plugins/HelloWorld/tests/HelloWorld.js | 91 ++++++++++++++++++---- lib/plugins/Plugins.json | 2 +- lib/plugins/Tests/tests/Tests.js | 6 +- tests/classes/PluginManager.js | 4 +- tests/integration/Serverless.js | 2 +- 6 files changed, 85 insertions(+), 22 deletions(-) diff --git a/bin/serverless b/bin/serverless index 0b5a0e911..8a3d357de 100755 --- a/bin/serverless +++ b/bin/serverless @@ -3,7 +3,7 @@ 'use strict'; // Note: TestsPlugin is only used for tests -const TestsPlugin = require('../lib/plugins/Tests/Tests'); +const TestsPlugin = require('../lib/plugins/tests/tests'); let SUtils = require('../lib/classes/Utils'); SUtils = new SUtils(); diff --git a/lib/plugins/HelloWorld/tests/HelloWorld.js b/lib/plugins/HelloWorld/tests/HelloWorld.js index 3d7c69293..e3a32a1d8 100644 --- a/lib/plugins/HelloWorld/tests/HelloWorld.js +++ b/lib/plugins/HelloWorld/tests/HelloWorld.js @@ -5,7 +5,7 @@ */ const expect = require('chai').expect; -const HelloWorld = require('../HelloWorld'); +const HelloWorld = require('../helloWorld'); describe('HelloWorld', () => { let helloWorld; @@ -20,27 +20,90 @@ describe('HelloWorld', () => { it('should have hooks', () => expect(helloWorld.hooks).to.be.not.empty); }); - describe('#printGoodMorning()', () => { - it('should print "Good morning"', () => { - const greeting = helloWorld.printGoodMorning(); + describe('when gender is "female"', () => { + describe('#printGoodMorning()', () => { + it('should print "Good morning madam"', () => { + const optionsMock = { gender: 'female' }; + const greeting = helloWorld.printGoodMorning(optionsMock); - expect(greeting).to.equal('Good morning'); + expect(greeting).to.equal('Good morning madam'); + }); + }); + + describe('#printHello()', () => { + it('should print "Hello madam"', () => { + const optionsMock = { gender: 'female' }; + const greeting = helloWorld.printHello(optionsMock); + + expect(greeting).to.equal('Hello madam'); + }); + }); + + describe('#printGoodEvening()', () => { + it('should print "Good evening madam"', () => { + const optionsMock = { gender: 'female' }; + const greeting = helloWorld.printGoodEvening(optionsMock); + + expect(greeting).to.equal('Good evening madam'); + }); }); }); - describe('#printHello()', () => { - it('should print "Hello"', () => { - const greeting = helloWorld.printHello(); + describe('when gender is "male"', () => { + describe('#printGoodMorning()', () => { + it('should print "Good morning sir"', () => { + const optionsMock = { gender: 'male' }; + const greeting = helloWorld.printGoodMorning(optionsMock); - expect(greeting).to.equal('Hello'); + expect(greeting).to.equal('Good morning sir'); + }); }); - }); - describe('#printGoodEvening()', () => { - it('should print "Good evening"', () => { - const greeting = helloWorld.printGoodEvening(); + describe('#printHello()', () => { + it('should print "Hello sir"', () => { + const optionsMock = { gender: 'male' }; + const greeting = helloWorld.printHello(optionsMock); - expect(greeting).to.equal('Good evening'); + expect(greeting).to.equal('Hello sir'); + }); + }); + + describe('#printGoodEvening()', () => { + it('should print "Good evening sir"', () => { + const optionsMock = { gender: 'male' }; + const greeting = helloWorld.printGoodEvening(optionsMock); + + expect(greeting).to.equal('Good evening sir'); + }); + }); + + describe('when gender is not given', () => { + describe('#printGoodMorning()', () => { + it('should print "Good morning madam"', () => { + const optionsMock = { gender: '' }; + const greeting = helloWorld.printGoodMorning(optionsMock); + + expect(greeting).to.equal('Good morning madam'); + }); + }); + + describe('#printHello()', () => { + it('should print "Hello madam"', () => { + const optionsMock = { gender: '' }; + const greeting = helloWorld.printHello(optionsMock); + + expect(greeting).to.equal('Hello madam'); + }); + }); + + describe('#printGoodEvening()', () => { + it('should print "Good evening madam"', () => { + const optionsMock = { gender: '' }; + const greeting = helloWorld.printGoodEvening(optionsMock); + + expect(greeting).to.equal('Good evening madam'); + }); + }); }); }); }); diff --git a/lib/plugins/Plugins.json b/lib/plugins/Plugins.json index b804f84c9..55c1f0b4a 100644 --- a/lib/plugins/Plugins.json +++ b/lib/plugins/Plugins.json @@ -2,6 +2,6 @@ "plugins": [ "./deploy/deploy.js", "./create/create.js", - "./HelloWorld/HelloWorld.js" + "./helloWorld/helloWorld.js" ] } diff --git a/lib/plugins/Tests/tests/Tests.js b/lib/plugins/Tests/tests/Tests.js index b03be166b..9c4892d3b 100644 --- a/lib/plugins/Tests/tests/Tests.js +++ b/lib/plugins/Tests/tests/Tests.js @@ -5,12 +5,12 @@ */ const expect = require('chai').expect; -const Tests = require('../Tests'); -const TestsPlugin = require('../Tests'); +const Tests = require('../tests'); +const TestsPlugin = require('../tests'); const exec = require('child_process').exec; const path = require('path'); -describe('Test', () => { +describe('Tests', () => { let tests; beforeEach(() => { diff --git a/tests/classes/PluginManager.js b/tests/classes/PluginManager.js index 3964c32a3..a57a04c9b 100644 --- a/tests/classes/PluginManager.js +++ b/tests/classes/PluginManager.js @@ -3,7 +3,7 @@ const expect = require('chai').expect; const PluginManager = require('../../lib/classes/PluginManager'); const Serverless = require('../../lib/Serverless'); -const HelloWorld = require('../../lib/plugins/HelloWorld/HelloWorld'); +const HelloWorld = require('../../lib/plugins/helloWorld/helloWorld'); describe('PluginManager', () => { let pluginManager; @@ -180,7 +180,7 @@ describe('PluginManager', () => { describe('#loadAllPlugins()', () => { it('should load only core plugins when no service plugins are given', () => { - // Note: We need the HelloWorld plugin for this test to pass + // Note: We need the helloWorld plugin for this test to pass pluginManager.loadAllPlugins(); expect(pluginManager.plugins).to.include(helloWorld); diff --git a/tests/integration/Serverless.js b/tests/integration/Serverless.js index f070108f7..e0fc37499 100644 --- a/tests/integration/Serverless.js +++ b/tests/integration/Serverless.js @@ -7,7 +7,7 @@ const expect = require('chai').expect; const exec = require('child_process').exec; const path = require('path'); -const TestsPlugin = require('../../lib/plugins/Tests/Tests'); +const TestsPlugin = require('../../lib/plugins/tests/tests'); describe('Serverless integration tests', () => { it('should successfully run the "serverless test integration" command', (done) => { From 7c998f3209c2f5961707a14db99f16d6240e3d1c Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Wed, 25 May 2016 07:19:13 +0200 Subject: [PATCH 2/3] Rename directory of HelloWorld plugin Rename the directory to be lowercased (so that the tests won't crash). --- lib/plugins/{HelloWorld => helloWorld}/README.md | 0 .../{HelloWorld/HelloWorld.js => helloWorld/helloWorld.js} | 0 lib/plugins/{HelloWorld => helloWorld}/package.json | 0 .../tests/HelloWorld.js => helloWorld/tests/helloWorld.js} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename lib/plugins/{HelloWorld => helloWorld}/README.md (100%) rename lib/plugins/{HelloWorld/HelloWorld.js => helloWorld/helloWorld.js} (100%) rename lib/plugins/{HelloWorld => helloWorld}/package.json (100%) rename lib/plugins/{HelloWorld/tests/HelloWorld.js => helloWorld/tests/helloWorld.js} (100%) diff --git a/lib/plugins/HelloWorld/README.md b/lib/plugins/helloWorld/README.md similarity index 100% rename from lib/plugins/HelloWorld/README.md rename to lib/plugins/helloWorld/README.md diff --git a/lib/plugins/HelloWorld/HelloWorld.js b/lib/plugins/helloWorld/helloWorld.js similarity index 100% rename from lib/plugins/HelloWorld/HelloWorld.js rename to lib/plugins/helloWorld/helloWorld.js diff --git a/lib/plugins/HelloWorld/package.json b/lib/plugins/helloWorld/package.json similarity index 100% rename from lib/plugins/HelloWorld/package.json rename to lib/plugins/helloWorld/package.json diff --git a/lib/plugins/HelloWorld/tests/HelloWorld.js b/lib/plugins/helloWorld/tests/helloWorld.js similarity index 100% rename from lib/plugins/HelloWorld/tests/HelloWorld.js rename to lib/plugins/helloWorld/tests/helloWorld.js From 6189a63f376f8db472531afe611d70697228ce25 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Wed, 25 May 2016 07:31:55 +0200 Subject: [PATCH 3/3] Rename directory of Tests plugin Rename the directory to be lowercased (so that the tests won't crash). --- lib/plugins/{Tests => tests}/README.md | 0 lib/plugins/{Tests => tests}/package.json | 0 lib/plugins/{Tests/Tests.js => tests/tests.js} | 0 lib/plugins/{Tests/tests/Tests.js => tests/tests/tests.js} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename lib/plugins/{Tests => tests}/README.md (100%) rename lib/plugins/{Tests => tests}/package.json (100%) rename lib/plugins/{Tests/Tests.js => tests/tests.js} (100%) rename lib/plugins/{Tests/tests/Tests.js => tests/tests/tests.js} (100%) diff --git a/lib/plugins/Tests/README.md b/lib/plugins/tests/README.md similarity index 100% rename from lib/plugins/Tests/README.md rename to lib/plugins/tests/README.md diff --git a/lib/plugins/Tests/package.json b/lib/plugins/tests/package.json similarity index 100% rename from lib/plugins/Tests/package.json rename to lib/plugins/tests/package.json diff --git a/lib/plugins/Tests/Tests.js b/lib/plugins/tests/tests.js similarity index 100% rename from lib/plugins/Tests/Tests.js rename to lib/plugins/tests/tests.js diff --git a/lib/plugins/Tests/tests/Tests.js b/lib/plugins/tests/tests/tests.js similarity index 100% rename from lib/plugins/Tests/tests/Tests.js rename to lib/plugins/tests/tests/tests.js