2021-04-09 08:39:53 -07:00
|
|
|
/*
|
|
|
|
|
Unit tests for the REST API handler for the /users endpoints.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Public npm libraries
|
2022-09-08 08:58:39 -07:00
|
|
|
import { assert } from 'chai'
|
2021-04-09 08:39:53 -07:00
|
|
|
|
2022-09-08 08:58:39 -07:00
|
|
|
import sinon from 'sinon'
|
|
|
|
|
import LogsApiController from '../../../../../src/controllers/rest-api/logs/controller.js'
|
|
|
|
|
|
|
|
|
|
import { context as mockContext } from '../../../../unit/mocks/ctx-mock.js'
|
2021-04-09 08:39:53 -07:00
|
|
|
let uut
|
|
|
|
|
let sandbox
|
|
|
|
|
let ctx
|
|
|
|
|
|
|
|
|
|
describe('Logapi', () => {
|
2022-03-08 09:39:54 -08:00
|
|
|
before(async () => {
|
|
|
|
|
})
|
2021-04-09 08:39:53 -07:00
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
uut = new LogsApiController()
|
|
|
|
|
|
|
|
|
|
sandbox = sinon.createSandbox()
|
|
|
|
|
|
|
|
|
|
// Mock the context object.
|
|
|
|
|
ctx = mockContext()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
afterEach(() => sandbox.restore())
|
|
|
|
|
|
|
|
|
|
describe('#POST /logapi', () => {
|
|
|
|
|
it('should return 422 status on biz logic error', async () => {
|
|
|
|
|
try {
|
|
|
|
|
await uut.getLogs(ctx)
|
|
|
|
|
|
|
|
|
|
assert.fail('Unexpected result')
|
|
|
|
|
} catch (err) {
|
|
|
|
|
assert.equal(err.status, 422)
|
2022-03-08 09:39:54 -08:00
|
|
|
assert.include(err.message, 'Cannot read')
|
2021-04-09 08:39:53 -07:00
|
|
|
}
|
|
|
|
|
})
|
2021-07-13 08:57:57 -07:00
|
|
|
|
2021-04-09 08:39:53 -07:00
|
|
|
it('should return 500 status on biz logic Unhandled error', async () => {
|
|
|
|
|
try {
|
|
|
|
|
// eslint-disable
|
2021-07-06 14:47:43 -07:00
|
|
|
sandbox
|
|
|
|
|
.stub(uut.logsApiLib, 'getLogs')
|
|
|
|
|
.returns(Promise.reject(new Error()))
|
2021-04-09 08:39:53 -07:00
|
|
|
|
|
|
|
|
ctx.request.body = {
|
|
|
|
|
password: 'test'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await uut.getLogs(ctx)
|
|
|
|
|
|
|
|
|
|
assert.fail('Unexpected result')
|
|
|
|
|
} catch (err) {
|
|
|
|
|
assert.equal(err.status, 500)
|
|
|
|
|
assert.include(err.message, 'Unhandled error')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should return 200 status on success', async () => {
|
2021-07-13 08:57:57 -07:00
|
|
|
// Mock dependencies
|
|
|
|
|
sandbox.stub(uut.logsApiLib, 'getLogs').resolves({})
|
|
|
|
|
|
2021-04-09 08:39:53 -07:00
|
|
|
ctx.request.body = {
|
|
|
|
|
password: 'test'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await uut.getLogs(ctx)
|
|
|
|
|
|
2021-07-13 08:57:57 -07:00
|
|
|
assert.isOk(ctx.body)
|
2021-04-09 08:39:53 -07:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|