72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
|
|
import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
|
||
|
|
import type { PrismaClient } from '@prisma/client';
|
||
|
|
import { setupTestDb, cleanupTestDb, clearAllTables } from './helpers.js';
|
||
|
|
import { seedMcpServers, defaultServers } from '../src/seed/index.js';
|
||
|
|
|
||
|
|
let prisma: PrismaClient;
|
||
|
|
|
||
|
|
beforeAll(async () => {
|
||
|
|
prisma = await setupTestDb();
|
||
|
|
}, 30_000);
|
||
|
|
|
||
|
|
afterAll(async () => {
|
||
|
|
await cleanupTestDb();
|
||
|
|
});
|
||
|
|
|
||
|
|
beforeEach(async () => {
|
||
|
|
await clearAllTables(prisma);
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('seedMcpServers', () => {
|
||
|
|
it('seeds all default servers', async () => {
|
||
|
|
const count = await seedMcpServers(prisma);
|
||
|
|
expect(count).toBe(defaultServers.length);
|
||
|
|
|
||
|
|
const servers = await prisma.mcpServer.findMany({ orderBy: { name: 'asc' } });
|
||
|
|
expect(servers).toHaveLength(defaultServers.length);
|
||
|
|
|
||
|
|
const names = servers.map((s) => s.name);
|
||
|
|
expect(names).toContain('slack');
|
||
|
|
expect(names).toContain('github');
|
||
|
|
expect(names).toContain('jira');
|
||
|
|
expect(names).toContain('terraform');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('is idempotent (upsert)', async () => {
|
||
|
|
await seedMcpServers(prisma);
|
||
|
|
const count = await seedMcpServers(prisma);
|
||
|
|
expect(count).toBe(defaultServers.length);
|
||
|
|
|
||
|
|
const servers = await prisma.mcpServer.findMany();
|
||
|
|
expect(servers).toHaveLength(defaultServers.length);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('seeds envTemplate correctly', async () => {
|
||
|
|
await seedMcpServers(prisma);
|
||
|
|
const slack = await prisma.mcpServer.findUnique({ where: { name: 'slack' } });
|
||
|
|
const envTemplate = slack!.envTemplate as Array<{ name: string; isSecret: boolean }>;
|
||
|
|
expect(envTemplate).toHaveLength(2);
|
||
|
|
expect(envTemplate[0].name).toBe('SLACK_BOT_TOKEN');
|
||
|
|
expect(envTemplate[0].isSecret).toBe(true);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('accepts custom server list', async () => {
|
||
|
|
const custom = [
|
||
|
|
{
|
||
|
|
name: 'custom-server',
|
||
|
|
description: 'Custom test server',
|
||
|
|
packageName: '@test/custom',
|
||
|
|
transport: 'STDIO' as const,
|
||
|
|
repositoryUrl: 'https://example.com',
|
||
|
|
envTemplate: [],
|
||
|
|
},
|
||
|
|
];
|
||
|
|
const count = await seedMcpServers(prisma, custom);
|
||
|
|
expect(count).toBe(1);
|
||
|
|
|
||
|
|
const servers = await prisma.mcpServer.findMany();
|
||
|
|
expect(servers).toHaveLength(1);
|
||
|
|
expect(servers[0].name).toBe('custom-server');
|
||
|
|
});
|
||
|
|
});
|