integration test fixes + added new ai models and recipeSuggestion
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 13m3s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 13m3s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// src/tests/integration/recipe.integration.test.ts
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||||
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
|
||||
import supertest from 'supertest';
|
||||
import app from '../../../server';
|
||||
import { createAndLoginUser } from '../utils/testHelpers';
|
||||
@@ -7,6 +7,14 @@ import { cleanupDb } from '../utils/cleanup';
|
||||
import type { UserProfile, Recipe, RecipeComment } from '../../types';
|
||||
import { getPool } from '../../services/db/connection.db';
|
||||
|
||||
// Mock the AI service
|
||||
vi.mock('../../services/aiService.server', () => ({
|
||||
aiService: {
|
||||
generateRecipeSuggestion: vi.fn(),
|
||||
},
|
||||
}));
|
||||
import { aiService } from '../../services/aiService.server';
|
||||
|
||||
/**
|
||||
* @vitest-environment node
|
||||
*/
|
||||
@@ -124,4 +132,24 @@ describe('Recipe API Routes Integration Tests', () => {
|
||||
it.todo('should prevent a user from deleting another user\'s recipe');
|
||||
it.todo('should allow an authenticated user to post a comment on a recipe');
|
||||
it.todo('should allow an authenticated user to fork a recipe');
|
||||
|
||||
describe('POST /api/recipes/suggest', () => {
|
||||
it('should return a recipe suggestion based on ingredients', async () => {
|
||||
const ingredients = ['chicken', 'rice', 'broccoli'];
|
||||
const mockSuggestion = 'Chicken and Broccoli Stir-fry with Rice';
|
||||
vi.mocked(aiService.generateRecipeSuggestion).mockResolvedValue(mockSuggestion);
|
||||
|
||||
const response = await request
|
||||
.post('/api/recipes/suggest')
|
||||
.set('Authorization', `Bearer ${authToken}`)
|
||||
.send({ ingredients });
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.body).toEqual({ suggestion: mockSuggestion });
|
||||
expect(aiService.generateRecipeSuggestion).toHaveBeenCalledWith(
|
||||
ingredients,
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user