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
@@ -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')