Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions plugins/query-log/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ describe('QueryLogPlugin - addQuery()', () => {
params: ['SELECT * FROM test', 50],
})
})

it('should swallow insert failures and return an empty list', async () => {
const consoleErrorSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => {})
vi.mocked(mockDataSource.rpc.executeQuery).mockRejectedValueOnce(
new Error('insert failed')
)

queryLogPlugin['state'].query = 'SELECT * FROM failing_query'
queryLogPlugin['state'].totalTime = 25

await expect(
queryLogPlugin['addQuery'](mockDataSource)
).resolves.toEqual([])
expect(consoleErrorSpy).toHaveBeenCalledWith(
'Error inserting rejected allowlist query:',
expect.any(Error)
)
})
})

describe('QueryLogPlugin - expireLog()', () => {
Expand All @@ -135,4 +155,20 @@ describe('QueryLogPlugin - expireLog()', () => {
const result = await queryLogPlugin['expireLog']()
expect(result).toBe(false)
})

it('should return false when log expiration fails', async () => {
const consoleErrorSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => {})
vi.mocked(mockDataSource.rpc.executeQuery).mockRejectedValueOnce(
new Error('delete failed')
)
queryLogPlugin['dataSource'] = mockDataSource

await expect(queryLogPlugin['expireLog']()).resolves.toBe(false)
expect(consoleErrorSpy).toHaveBeenCalledWith(
'Error purging old query logs:',
expect.any(Error)
)
})
})