-
-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathpublications.ts
74 lines (68 loc) · 1.88 KB
/
publications.ts
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
import { expect, test } from 'vitest'
import { app } from './utils'
test('publication list filtering', async () => {
const res = await app.inject({
method: 'GET',
path: '/publications?limit=5',
})
expect(res.statusCode).toBe(200)
const publications = res.json()
expect(Array.isArray(publications)).toBe(true)
expect(publications.length).toBeLessThanOrEqual(5)
})
test('publication with invalid id', async () => {
const res = await app.inject({
method: 'GET',
path: '/publications/99999999',
})
expect(res.statusCode).toBe(404)
})
test('create publication with invalid options', async () => {
const res = await app.inject({
method: 'POST',
path: '/publications',
payload: {
name: 'test_publication',
publish_insert: 'invalid', // Should be boolean but seems to be converted automatically
publish_update: true,
publish_delete: true,
publish_truncate: true,
tables: ['public.users'],
},
})
// API accepts invalid type and converts it
// TODO: This should error out with invalid parameter
expect(res.statusCode).toBe(200)
})
test('create publication with empty name', async () => {
const res = await app.inject({
method: 'POST',
path: '/publications',
payload: {
name: '',
publish_insert: true,
publish_update: true,
publish_delete: true,
publish_truncate: true,
tables: ['public.users'],
},
})
expect(res.statusCode).toBe(400)
})
test('update publication with invalid id', async () => {
const res = await app.inject({
method: 'PATCH',
path: '/publications/99999999',
payload: {
name: 'renamed_publication',
},
})
expect(res.statusCode).toBe(404)
})
test('delete publication with invalid id', async () => {
const res = await app.inject({
method: 'DELETE',
path: '/publications/99999999',
})
expect(res.statusCode).toBe(404)
})