-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathindex.test.ts
More file actions
84 lines (67 loc) · 2.59 KB
/
index.test.ts
File metadata and controls
84 lines (67 loc) · 2.59 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
84
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { ReplicationPlugin } from './index'
describe('ReplicationPlugin', () => {
let plugin: ReplicationPlugin
beforeEach(() => {
plugin = new ReplicationPlugin()
})
it('should have the correct plugin name', () => {
expect(plugin.name).toBe('starbasedb:replication')
})
it('should require authentication', () => {
expect(plugin.opts.requiresAuth).toBe(true)
})
it('should have the correct route prefix', () => {
expect(plugin.prefix).toBe('/replication')
})
it('should register event callbacks', () => {
const callback = vi.fn()
plugin.onEvent(callback)
// Verify the callback is registered by checking it doesn't throw
expect(() => plugin.onEvent(callback)).not.toThrow()
})
it('should throw error when syncTable is called without initialization', async () => {
await expect(plugin.syncTable('test_table')).rejects.toThrow(
'ReplicationPlugin not initialized'
)
})
it('should throw error when syncAll is called without initialization', async () => {
// syncAll calls getConfigs which requires dataSource
// Since dataSource is undefined, getConfigs returns []
// so syncAll should return empty array
const results = await plugin.syncAll()
expect(results).toEqual([])
})
})
describe('ReplicationPlugin SQL Queries', () => {
it('should define all required SQL queries', () => {
// Verify the plugin can be instantiated without errors
// indicating all internal SQL query constants are properly defined
const plugin = new ReplicationPlugin()
expect(plugin).toBeDefined()
expect(plugin.name).toBe('starbasedb:replication')
})
})
describe('ReplicationPlugin Event System', () => {
let plugin: ReplicationPlugin
beforeEach(() => {
plugin = new ReplicationPlugin()
})
it('should support multiple event callbacks', () => {
const callback1 = vi.fn()
const callback2 = vi.fn()
plugin.onEvent(callback1)
plugin.onEvent(callback2)
// Both callbacks should be registered without errors
expect(() => {
plugin.onEvent(callback1)
plugin.onEvent(callback2)
}).not.toThrow()
})
it('should support async event callbacks', () => {
const asyncCallback = async () => {
await new Promise((resolve) => setTimeout(resolve, 10))
}
expect(() => plugin.onEvent(asyncCallback)).not.toThrow()
})
})