feat(modules): Removed src/modules folder. Ported all REST API to /src/controllers/ folder

This commit is contained in:
Chris Troutner
2021-07-06 14:47:43 -07:00
parent 8a37261995
commit ada35eb092
9 changed files with 84 additions and 103 deletions
@@ -9,7 +9,7 @@ util.inspect.defaultOptions = { depth: 1 }
const LOCALHOST = `http://localhost:${config.port}`
const LogsController = require('../../../src/modules/logapi/controller')
const LogsController = require('../../../src/controllers/rest-api/logs/controller')
const mockContext = require('../../unit/mocks/ctx-mock').context
let sandbox
@@ -23,12 +23,12 @@ describe('LogsApi', () => {
afterEach(() => sandbox.restore())
describe('POST /logapi', () => {
describe('POST /logs', () => {
it('should return false if password is not provided', async () => {
try {
const options = {
method: 'post',
url: `${LOCALHOST}/logapi`,
url: `${LOCALHOST}/logs`,
data: {}
}
@@ -38,11 +38,12 @@ describe('LogsApi', () => {
assert(false, 'Unexpected result')
}
})
it('should return log', async () => {
try {
const options = {
method: 'post',
url: `${LOCALHOST}/logapi`,
url: `${LOCALHOST}/logs`,
data: {
password: 'test'
}
@@ -59,6 +60,7 @@ describe('LogsApi', () => {
assert(false, 'Unexpected result')
}
})
it('should return false if files are not found!', async () => {
try {
sandbox.stub(uut.logsApiLib, 'getLogs').resolves({
@@ -80,10 +82,13 @@ describe('LogsApi', () => {
assert.fail('Unexpected result')
}
})
it('should catch and handle errors', async () => {
try {
// Force an error
sandbox.stub(uut.logsApiLib.fs, 'existsSync').throws(new Error('test error'))
sandbox
.stub(uut.logsApiLib.fs, 'existsSync')
.throws(new Error('test error'))
// Mock the context object.
const ctx = mockContext()
@@ -101,6 +106,7 @@ describe('LogsApi', () => {
assert.include(err.message, 'test error')
}
})
it('should throw unhandled error', async () => {
try {
// Force an error
+5 -4
View File
@@ -6,7 +6,7 @@
const assert = require('chai').assert
const sinon = require('sinon')
const LogsApiController = require('../../../src/modules/logapi/controller')
const LogsApiController = require('../../../src/controllers/rest-api/logs/controller')
let uut
let sandbox
let ctx
@@ -14,8 +14,7 @@ let ctx
const mockContext = require('../../unit/mocks/ctx-mock').context
describe('Logapi', () => {
before(async () => {
})
before(async () => {})
beforeEach(() => {
uut = new LogsApiController()
@@ -42,7 +41,9 @@ describe('Logapi', () => {
it('should return 500 status on biz logic Unhandled error', async () => {
try {
// eslint-disable
sandbox.stub(uut.logsApiLib, 'getLogs').returns(Promise.reject(new Error()))
sandbox
.stub(uut.logsApiLib, 'getLogs')
.returns(Promise.reject(new Error()))
ctx.request.body = {
password: 'test'