mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-10 23:31:08 +00:00
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import Fastify from 'fastify';
|
|
import { WebhookController } from '../../../src/app/controllers/WebhookController';
|
|
import type { PromptService } from '../../../src/core/langfuse/PromptService';
|
|
|
|
describe('WebhookController', () => {
|
|
it('invalidates a single prompt when promptName is given', async () => {
|
|
const invalidate = vi.fn();
|
|
const app = Fastify();
|
|
new WebhookController({ invalidate } as unknown as PromptService).register(app);
|
|
|
|
const res = await app.inject({
|
|
method: 'POST',
|
|
url: '/webhooks/langfuse/invalidate',
|
|
payload: { promptName: 'movie-recommender' },
|
|
});
|
|
expect(res.statusCode).toBe(200);
|
|
expect(invalidate).toHaveBeenCalledWith('movie-recommender');
|
|
expect(res.json()).toEqual({ invalidated: true, promptName: 'movie-recommender' });
|
|
});
|
|
|
|
it('invalidates the whole cache when no promptName is given', async () => {
|
|
const invalidate = vi.fn();
|
|
const app = Fastify();
|
|
new WebhookController({ invalidate } as unknown as PromptService).register(app);
|
|
|
|
const res = await app.inject({ method: 'POST', url: '/webhooks/langfuse/invalidate', payload: {} });
|
|
expect(invalidate).toHaveBeenCalledWith(undefined);
|
|
expect(res.json()).toEqual({ invalidated: true, promptName: 'all' });
|
|
});
|
|
});
|