Files

83 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

/*
Unit tests for the REST API controllers/rest-api/index.js library.
*/
// Public npm libraries
2022-09-08 08:58:39 -07:00
import { assert } from 'chai'
import sinon from 'sinon'
// Local libraries
2022-09-08 08:58:39 -07:00
import RESTControllers from '../../../../src/controllers/rest-api/index.js'
// const mockContext = require('../../../unit/mocks/ctx-mock').context
2022-09-08 08:58:39 -07:00
import adapters from '../../mocks/adapters/index.js'
import UseCasesMock from '../../mocks/use-cases/index.js'
describe('#RESTControllers', () => {
let uut
let sandbox
// let ctx
2025-06-27 20:11:27 -04:00
before(async () => { })
beforeEach(() => {
const useCases = new UseCasesMock()
uut = new RESTControllers({ adapters, useCases })
sandbox = sinon.createSandbox()
// Mock the context object.
// ctx = mockContext()
})
afterEach(() => sandbox.restore())
describe('#constructor', () => {
it('should throw an error if adapters are not passed in', () => {
try {
uut = new RESTControllers()
assert.fail('Unexpected code path')
} catch (err) {
assert.include(
err.message,
'Instance of Adapters library required when instantiating REST Controller libraries.'
)
}
})
it('should throw an error if useCases are not passed in', () => {
try {
uut = new RESTControllers({ adapters })
assert.fail('Unexpected code path')
// use to prevent complaints from linter.
console.log('uut: ', uut)
} catch (err) {
assert.include(
err.message,
'Instance of Use Cases library required when instantiating REST Controller libraries.'
)
}
})
})
2025-06-27 20:11:27 -04:00
describe('#attachRESTControllers', () => {
it('should attach controllers without mongo service', () => {
uut.config.noMongo = true
const app = { use: () => {} }
uut.attachRESTControllers(app)
})
it('should attach controllers with mongo service', () => {
uut.config.noMongo = false
const app = { use: () => {} }
uut.attachRESTControllers(app)
})
})
})