Refactor tests to use mockClient for database interactions, improve error handling, and enhance modal functionality
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Has been cancelled
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Has been cancelled
- Updated personalization.db.test.ts to use mockClient for query calls in addWatchedItem tests. - Simplified error handling in shopping.db.test.ts, ensuring clearer error messages. - Added comprehensive tests for VoiceAssistant component, including rendering and interaction tests. - Introduced useModal hook with tests to manage modal state effectively. - Created deals.db.test.ts to test deals repository functionality with mocked database interactions. - Implemented error handling tests for custom error classes in errors.db.test.ts. - Developed googleGeocodingService.server.test.ts to validate geocoding service behavior with mocked fetch.
This commit is contained in:
@@ -9,7 +9,9 @@ import { errorHandler } from '../middleware/errorHandler';
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock('../services/geocodingService.server', () => ({
|
||||
clearGeocodeCache: vi.fn(),
|
||||
geocodingService: {
|
||||
clearGeocodeCache: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock other dependencies that are part of the adminRouter setup but not directly tested here
|
||||
@@ -30,7 +32,7 @@ vi.mock('@bull-board/express', () => ({
|
||||
}));
|
||||
|
||||
// Import the mocked modules to control them
|
||||
import { clearGeocodeCache } from '../services/geocodingService.server';
|
||||
import { geocodingService } from '../services/geocodingService.server';
|
||||
|
||||
// Mock the logger
|
||||
vi.mock('../services/logger.server', () => ({
|
||||
@@ -66,14 +68,14 @@ describe('Admin System Routes (/api/admin/system)', () => {
|
||||
|
||||
describe('POST /system/clear-geocode-cache', () => {
|
||||
it('should return 200 on successful cache clear', async () => {
|
||||
vi.mocked(clearGeocodeCache).mockResolvedValue(10);
|
||||
vi.mocked(geocodingService.clearGeocodeCache).mockResolvedValue(10);
|
||||
const response = await supertest(app).post('/api/admin/system/clear-geocode-cache');
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.body.message).toContain('10 keys were removed');
|
||||
});
|
||||
|
||||
it('should return 500 if clearing the cache fails', async () => {
|
||||
vi.mocked(clearGeocodeCache).mockRejectedValue(new Error('Redis is down'));
|
||||
vi.mocked(geocodingService.clearGeocodeCache).mockRejectedValue(new Error('Redis is down'));
|
||||
const response = await supertest(app).post('/api/admin/system/clear-geocode-cache');
|
||||
expect(response.status).toBe(500);
|
||||
expect(response.body.message).toContain('Redis is down');
|
||||
|
||||
Reference in New Issue
Block a user