fix(logapi): Fixing issues with unit tests

This commit is contained in:
Chris Troutner
2022-06-27 11:29:27 -07:00
parent 434a4d7bd6
commit 3b17ba8e8b
2 changed files with 10 additions and 3 deletions
+3 -1
View File
@@ -135,8 +135,10 @@ class LogsApi {
if (!filename || typeof filename !== 'string') { if (!filename || typeof filename !== 'string') {
throw new Error('filename must be a string') throw new Error('filename must be a string')
} }
// Throw an error if the file does not exist.
console.log('readLines() filename: ', filename)
// Throw an error if the file does not exist.
if (!_this.fs.existsSync(filename)) { if (!_this.fs.existsSync(filename)) {
throw new Error('file does not exist') throw new Error('file does not exist')
} }
+7 -2
View File
@@ -32,6 +32,9 @@ describe('#LogsApiLib', () => {
}) })
it('should return log', async () => { it('should return log', async () => {
// Mock dependencies
sandbox.stub(uut, 'generateFileName').returns(`${__dirname.toString()}/../mocks/adapters/test.log`)
const pass = 'test' const pass = 'test'
const result = await uut.getLogs(pass) const result = await uut.getLogs(pass)
// console.log('result', result) // console.log('result', result)
@@ -201,13 +204,15 @@ describe('#LogsApiLib', () => {
// About yields // About yields
sandbox.stub(uut.lineReader, 'eachLine').yieldsRight({}, true) sandbox.stub(uut.lineReader, 'eachLine').yieldsRight({}, true)
const fileName = context.fileName const fileName = `${__dirname.toString()}/../mocks/adapters/test.log`
const result = await uut.readLines(fileName) const result = await uut.readLines(fileName)
assert.isArray(result) assert.isArray(result)
}) })
it('should return data', async () => { it('should return data', async () => {
const fileName = context.fileName const fileName = `${__dirname.toString()}/../mocks/adapters/test.log`
const result = await uut.readLines(fileName) const result = await uut.readLines(fileName)
assert.isArray(result) assert.isArray(result)