-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathindex.test.ts
More file actions
83 lines (73 loc) · 2.5 KB
/
index.test.ts
File metadata and controls
83 lines (73 loc) · 2.5 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { DataReplicationPlugin } from './index'
import { StarbaseApp } from '../../src/handler'
describe('DataReplicationPlugin', () => {
let plugin: DataReplicationPlugin
let mockApp: StarbaseApp
let mockDataSource: any
beforeEach(() => {
plugin = new DataReplicationPlugin()
mockDataSource = {
rpc: {
executeQuery: vi.fn().mockResolvedValue([]),
},
source: 'internal',
executionContext: undefined,
}
mockApp = {
use: vi.fn(),
post: vi.fn(),
get: vi.fn(),
delete: vi.fn(),
} as any
})
it('should create plugin with correct name', () => {
expect(plugin.name).toBe('starbasedb:data-replication')
expect(plugin.pathPrefix).toBe('/data-replication')
})
it('should register routes and middleware', async () => {
await plugin.register(mockApp)
expect(mockApp.use).toHaveBeenCalled()
expect(mockApp.post).toHaveBeenCalledWith(
'/data-replication/configure',
expect.any(Function)
)
expect(mockApp.post).toHaveBeenCalledWith(
'/data-replication/start/:name',
expect.any(Function)
)
expect(mockApp.post).toHaveBeenCalledWith(
'/data-replication/stop/:name',
expect.any(Function)
)
expect(mockApp.post).toHaveBeenCalledWith(
'/data-replication/sync/:name',
expect.any(Function)
)
expect(mockApp.get).toHaveBeenCalledWith(
'/data-replication/status',
expect.any(Function)
)
expect(mockApp.get).toHaveBeenCalledWith(
'/data-replication/logs',
expect.any(Function)
)
expect(mockApp.delete).toHaveBeenCalledWith(
'/data-replication/configure/:name',
expect.any(Function)
)
})
it('should handle event callbacks', () => {
const callback = vi.fn()
plugin.onEvent(callback)
// Trigger a callback (this would normally happen during sync)
const payload = {
config_name: 'test',
status: 'success' as const,
records_processed: 10,
sync_duration_ms: 100,
}
// We can't directly test the private method, but we can verify the callback was registered
expect(typeof callback).toBe('function')
})
})