Increased 100% test coverage for use-case index.js

This commit is contained in:
Chris Troutner
2021-07-11 08:25:48 -07:00
parent 8d2719ff86
commit eae2b05aad
4 changed files with 67 additions and 17 deletions
+2 -4
View File
@@ -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 <chris.troutner@gmail.com>",
"license": "MIT",
@@ -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.'
)
}
})
})
})
+15 -13
View File
@@ -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')