mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 07:41:08 +00:00
Add Health/Recommendations/Request/Webhook controllers
This commit is contained in:
31
test/app/controllers/WebhookController.test.ts
Normal file
31
test/app/controllers/WebhookController.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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' });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user