Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions src/cache/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ describe('Cache Module', () => {
expect(result).toBeNull()
})

it('should not read from cache when a SQL batch contains a modifying statement', async () => {
const result = await beforeQueryCache({
sql: 'SELECT * FROM users; DELETE FROM users WHERE id = 1',
dataSource: mockDataSource,
})

expect(result).toBeNull()
expect(mockDataSource.rpc.executeQuery).not.toHaveBeenCalled()
})

it('should return cached result if present and valid', async () => {
const cachedData = {
timestamp: new Date().toISOString(),
Expand Down Expand Up @@ -122,6 +132,17 @@ describe('Cache Module', () => {
expect(mockDataSource.rpc.executeQuery).not.toHaveBeenCalled()
})

it('should not write to cache when a SQL batch contains a modifying statement', async () => {
await afterQueryCache({
sql: 'SELECT * FROM users; DELETE FROM users WHERE id = 1',
params: undefined,
result: [{ id: 1, name: 'John' }],
dataSource: mockDataSource,
})

expect(mockDataSource.rpc.executeQuery).not.toHaveBeenCalled()
})

it('should insert new cache entry if query not cached', async () => {
vi.mocked(mockDataSource.rpc.executeQuery).mockResolvedValue([])

Expand Down
Binary file added tests/assets/cache-batched-mutations-demo.webm
Binary file not shown.