diff --git a/src/cache/index.test.ts b/src/cache/index.test.ts index 8438ab0..f466e8d 100644 --- a/src/cache/index.test.ts +++ b/src/cache/index.test.ts @@ -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(), @@ -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([]) diff --git a/tests/assets/cache-batched-mutations-demo.webm b/tests/assets/cache-batched-mutations-demo.webm new file mode 100644 index 0000000..056f5f1 Binary files /dev/null and b/tests/assets/cache-batched-mutations-demo.webm differ