Skip to content

Commit

Permalink
test: initLogger asserts when no filepath is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
thuoe committed Apr 22, 2024
1 parent 6cbc3ff commit 6eabea9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/log.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ describe('@log directive', () => {

assert(response.body.kind === 'single')
expect(response.body.singleResult.errors).toBeUndefined();
expect(directive.initLogger).toHaveBeenCalledTimes(1)
expect(directive.initLogger).toHaveBeenCalledWith(undefined, directive.LogLevel.INFO)
expect(directive.log).toHaveBeenCalled()
expect(directive.log).toHaveBeenCalledWith({ message: 'Operation Name: TestQuery', level: directive.LogLevel.INFO })
})

it('can write to a log file with the preferred file name with a log level, label, timestamp & message', async () => {
const filePath = path.join(__dirname, 'testLogs', 'test.log')
const fileName = 'test.log'
const folderName = 'testLogs'
const filePath = path.join(__dirname, folderName, fileName)
const { logDirectiveTypeDefs: typeDefs, logDirectiveTransformer: transformer } = directive.default({
filePath,
})
Expand Down Expand Up @@ -104,6 +108,7 @@ describe('@log directive', () => {

assert(response.body.kind === 'single')
expect(response.body.singleResult.errors).toBeUndefined();
expect(directive.initLogger).toHaveBeenCalledTimes(1)
expect(directive.initLogger).toHaveBeenCalledWith(filePath, directive.LogLevel.INFO)
})

Expand Down

0 comments on commit 6eabea9

Please sign in to comment.