diff --git a/package.json b/package.json index fac6e88..dad4b95 100644 --- a/package.json +++ b/package.json @@ -7,15 +7,13 @@ "start": "node index.js", "test": "npm run test:all", "test:all": "export SVC_ENV=test && nyc --reporter=text mocha --exit --timeout 15000 --recursive test/unit test/e2e/automated/", - "test:unit:lib": "export SVC_ENV=test && mocha --exit --timeout 15000 test/unit/biz-logic/", - "test:unit:rest": "export SVC_ENV=test && mocha --exit --timeout 15000 test/unit/rest-api/", - "test:unit:jsonrpc": "export SVC_ENV=test && mocha --exit --timeout 15000 test/unit/json-rpc/", + "test:unit": "export SVC_ENV=test && mocha --exit --timeout 15000 --recursive test/unit/", "test:e2e:auto": "export SVC_ENV=test && mocha --exit --timeout 15000 test/e2e/automated/", "test:temp": "export SVC_ENV=test && mocha --exit --timeout 15000 -g '#rate-limit' test/unit/json-rpc/", "lint": "standard --env mocha --fix", "docs": "./node_modules/.bin/apidoc -i src/ -o docs", "coverage": "nyc report --reporter=text-lcov | coveralls", - "coverage:report": "export SVC_ENV=test && nyc --reporter=html mocha --exit --timeout 15000 test/unit/biz-logic/ test/unit/json-rpc/ test/unit/rest-api/ test/e2e/automated/" + "coverage:report": "export SVC_ENV=test && nyc --reporter=html mocha --exit --timeout 15000 --recursive test/unit/ test/e2e/automated/" }, "author": "Chris Troutner ", "license": "MIT", diff --git a/test/unit/adapters/wlogger.adapter.unit.js b/test/unit/adapters/wlogger.adapter.unit.js new file mode 100644 index 0000000..e69de29 diff --git a/test/unit/use-cases/index.use-case.unit.js b/test/unit/use-cases/index.use-case.unit.js new file mode 100644 index 0000000..2bc4937 --- /dev/null +++ b/test/unit/use-cases/index.use-case.unit.js @@ -0,0 +1,50 @@ +/* + Unit tests for the index.js file that aggregates all use-cases. +*/ + +// Public npm libraries +const assert = require('chai').assert +const sinon = require('sinon') + +// Local support libraries +const testUtils = require('../../utils/test-utils') + +// Unit under test (uut) +const UseCases = require('../../../src/use-cases') +const adapters = require('../mocks/adapters') + +describe('#use-cases', () => { + let uut + let sandbox + + before(async () => { + // Delete all previous users in the database. + await testUtils.deleteAllUsers() + }) + + beforeEach(() => { + sandbox = sinon.createSandbox() + + uut = new UseCases({ adapters }) + }) + + afterEach(() => sandbox.restore()) + + describe('#constructor', () => { + it('should throw an error if adapters are not passed in', () => { + try { + uut = new UseCases() + + assert.fail('Unexpected code path') + + // This is here to prevent the linter from complaining. + assert.isOk(uut) + } catch (err) { + assert.include( + err.message, + 'Instance of adapters must be passed in when instantiating Use Cases library.' + ) + } + }) + }) +}) diff --git a/test/unit/use-cases/users.use-case.unit.js b/test/unit/use-cases/users.use-case.unit.js index 0468d0c..8260403 100644 --- a/test/unit/use-cases/users.use-case.unit.js +++ b/test/unit/use-cases/users.use-case.unit.js @@ -5,12 +5,10 @@ */ // Public npm libraries -const mongoose = require('mongoose') const assert = require('chai').assert const sinon = require('sinon') // Local support libraries -const config = require('../../../config') const testUtils = require('../../utils/test-utils') // Unit under test (uut) @@ -23,15 +21,6 @@ describe('#users', () => { let testUser = {} before(async () => { - // Connect to the Mongo Database. - console.log(`Connecting to database: ${config.database}`) - mongoose.Promise = global.Promise - mongoose.set('useCreateIndex', true) // Stop deprecation warning. - await mongoose.connect(config.database, { - useUnifiedTopology: true, - useNewUrlParser: true - }) - // Delete all previous users in the database. await testUtils.deleteAllUsers() }) @@ -44,8 +33,19 @@ describe('#users', () => { afterEach(() => sandbox.restore()) - after(() => { - mongoose.connection.close() + describe('#constructor', () => { + it('should throw an error if adapters are not passed in', () => { + try { + uut = new UserLib() + + assert.fail('Unexpected code path') + } catch (err) { + assert.include( + err.message, + 'Instance of adapters must be passed in when instantiating User Use Cases library.' + ) + } + }) }) describe('#createUser', () => { @@ -133,6 +133,8 @@ describe('#users', () => { testUser = userData + // Commented out because there is some sophisticated mocking required that + // I didn't have time to figure out. -CT 6/11/21 // Assert that the user model has the expected properties with expected values. // assert.property(userData, 'type') // assert.equal(userData.type, 'user')