-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathfunctions.ts
81 lines (74 loc) · 2.03 KB
/
functions.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
75
76
77
78
79
80
81
import { expect, test } from 'vitest'
import { app } from './utils'
test('function list filtering', async () => {
const res = await app.inject({
method: 'GET',
path: '/functions?limit=5',
})
expect(res.statusCode).toBe(200)
const functions = res.json()
expect(Array.isArray(functions)).toBe(true)
expect(functions.length).toBeLessThanOrEqual(5)
})
test('function list with specific included schema', async () => {
const res = await app.inject({
method: 'GET',
path: '/functions?includedSchemas=public',
})
expect(res.statusCode).toBe(200)
const functions = res.json()
expect(Array.isArray(functions)).toBe(true)
// All functions should be in the public schema
functions.forEach((func) => {
expect(func.schema).toBe('public')
})
})
test('function list exclude system schemas', async () => {
const res = await app.inject({
method: 'GET',
path: '/functions?includeSystemSchemas=false',
})
expect(res.statusCode).toBe(200)
const functions = res.json()
expect(Array.isArray(functions)).toBe(true)
// No functions should be in pg_ schemas
functions.forEach((func) => {
expect(func.schema).not.toMatch(/^pg_/)
})
})
test('function with invalid id', async () => {
const res = await app.inject({
method: 'GET',
path: '/functions/99999999',
})
expect(res.statusCode).toBe(404)
})
test('create function with invalid arguments', async () => {
const res = await app.inject({
method: 'POST',
path: '/functions',
payload: {
name: 'invalid_function',
schema: 'public',
// Missing required args
},
})
expect(res.statusCode).toBe(400)
})
test('update function with invalid id', async () => {
const res = await app.inject({
method: 'PATCH',
path: '/functions/99999999',
payload: {
name: 'renamed_function',
},
})
expect(res.statusCode).toBe(404)
})
test('delete function with invalid id', async () => {
const res = await app.inject({
method: 'DELETE',
path: '/functions/99999999',
})
expect(res.statusCode).toBe(404)
})