-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathindex.test.ts
More file actions
35 lines (29 loc) · 1.1 KB
/
index.test.ts
File metadata and controls
35 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { StarbaseApp } from '../../src/handler'
import { DataSource } from '../../src/types'
import { PullReplicatorPlugin } from './index'
let plugin: PullReplicatorPlugin
let mockDataSource: DataSource
beforeEach(() => {
vi.clearAllMocks()
mockDataSource = { rpc: { executeQuery: vi.fn().mockResolvedValue([]) } } as unknown as DataSource
plugin = new PullReplicatorPlugin()
})
describe('PullReplicatorPlugin', () => {
it('register creates replication tables in middleware', async () => {
const mockApp = {
use: vi.fn((middleware) => middleware({ get: vi.fn(() => mockDataSource) }, vi.fn())),
get: vi.fn(),
} as unknown as StarbaseApp
await plugin.register(mockApp)
expect(mockDataSource.rpc.executeQuery).toHaveBeenCalledTimes(2)
expect(mockDataSource.rpc.executeQuery).toHaveBeenNthCalledWith(1, {
sql: expect.stringContaining('tmp_replication_jobs'),
params: [],
})
expect(mockDataSource.rpc.executeQuery).toHaveBeenNthCalledWith(2, {
sql: expect.stringContaining('tmp_replication_runs'),
params: [],
})
})
})