|
| 1 | +import { expect, test } from 'vitest' |
| 2 | +import { app } from './utils' |
| 3 | + |
| 4 | +test('function list filtering', async () => { |
| 5 | + const res = await app.inject({ |
| 6 | + method: 'GET', |
| 7 | + path: '/functions?limit=5', |
| 8 | + }) |
| 9 | + expect(res.statusCode).toBe(200) |
| 10 | + const functions = res.json() |
| 11 | + expect(Array.isArray(functions)).toBe(true) |
| 12 | + expect(functions.length).toBeLessThanOrEqual(5) |
| 13 | +}) |
| 14 | + |
| 15 | +test('function list with specific included schema', async () => { |
| 16 | + const res = await app.inject({ |
| 17 | + method: 'GET', |
| 18 | + path: '/functions?includedSchemas=public', |
| 19 | + }) |
| 20 | + expect(res.statusCode).toBe(200) |
| 21 | + const functions = res.json() |
| 22 | + expect(Array.isArray(functions)).toBe(true) |
| 23 | + // All functions should be in the public schema |
| 24 | + functions.forEach((func) => { |
| 25 | + expect(func.schema).toBe('public') |
| 26 | + }) |
| 27 | +}) |
| 28 | + |
| 29 | +test('function list exclude system schemas', async () => { |
| 30 | + const res = await app.inject({ |
| 31 | + method: 'GET', |
| 32 | + path: '/functions?includeSystemSchemas=false', |
| 33 | + }) |
| 34 | + expect(res.statusCode).toBe(200) |
| 35 | + const functions = res.json() |
| 36 | + expect(Array.isArray(functions)).toBe(true) |
| 37 | + // No functions should be in pg_ schemas |
| 38 | + functions.forEach((func) => { |
| 39 | + expect(func.schema).not.toMatch(/^pg_/) |
| 40 | + }) |
| 41 | +}) |
| 42 | + |
| 43 | +test('function with invalid id', async () => { |
| 44 | + const res = await app.inject({ |
| 45 | + method: 'GET', |
| 46 | + path: '/functions/99999999', |
| 47 | + }) |
| 48 | + expect(res.statusCode).toBe(404) |
| 49 | +}) |
| 50 | + |
| 51 | +test('create function with invalid arguments', async () => { |
| 52 | + const res = await app.inject({ |
| 53 | + method: 'POST', |
| 54 | + path: '/functions', |
| 55 | + payload: { |
| 56 | + name: 'invalid_function', |
| 57 | + schema: 'public', |
| 58 | + // Missing required args |
| 59 | + }, |
| 60 | + }) |
| 61 | + expect(res.statusCode).toBe(400) |
| 62 | +}) |
| 63 | + |
| 64 | +test('update function with invalid id', async () => { |
| 65 | + const res = await app.inject({ |
| 66 | + method: 'PATCH', |
| 67 | + path: '/functions/99999999', |
| 68 | + payload: { |
| 69 | + name: 'renamed_function', |
| 70 | + }, |
| 71 | + }) |
| 72 | + expect(res.statusCode).toBe(404) |
| 73 | +}) |
| 74 | + |
| 75 | +test('delete function with invalid id', async () => { |
| 76 | + const res = await app.inject({ |
| 77 | + method: 'DELETE', |
| 78 | + path: '/functions/99999999', |
| 79 | + }) |
| 80 | + expect(res.statusCode).toBe(404) |
| 81 | +}) |
0 commit comments