fix logging tests
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 5m53s
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 5m53s
This commit is contained in:
@@ -6,7 +6,17 @@
|
||||
//
|
||||
// --- END FIX REGISTRY ---
|
||||
// src/services/db/user.db.test.ts
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
|
||||
// Mock the logger to prevent stderr noise during tests
|
||||
vi.mock('../logger.server', () => ({
|
||||
logger: {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Un-mock the module we are testing to ensure we use the real implementation.
|
||||
vi.unmock('./user.db');
|
||||
@@ -18,15 +28,16 @@ import { UniqueConstraintError, ForeignKeyConstraintError } from './errors.db';
|
||||
import type { Profile, ActivityLogItem, SearchQuery } from '../../types';
|
||||
|
||||
// Mock other db services that are used by functions in user.db.ts
|
||||
// Update mocks to put methods on prototype so spyOn works in exportUserData tests
|
||||
vi.mock('./shopping.db', () => ({
|
||||
ShoppingRepository: class {
|
||||
getShoppingLists = vi.fn();
|
||||
createShoppingList = vi.fn(); // FIX: Add missing mock for createShoppingList.
|
||||
getShoppingLists() { return Promise.resolve([]); }
|
||||
createShoppingList() { return Promise.resolve({}); }
|
||||
},
|
||||
}));
|
||||
vi.mock('./personalization.db', () => ({
|
||||
PersonalizationRepository: class {
|
||||
getWatchedItems = vi.fn();
|
||||
getWatchedItems() { return Promise.resolve([]); }
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -34,6 +45,11 @@ describe('User DB Service', () => {
|
||||
// Instantiate the repository with the mock pool for each test
|
||||
let userRepo: UserRepository;
|
||||
|
||||
// Restore mocks after each test to ensure spies on prototypes (like in exportUserData) don't leak
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
userRepo = new UserRepository(mockPoolInstance as any);
|
||||
|
||||
@@ -11,14 +11,10 @@ const mocks = vi.hoisted(() => {
|
||||
|
||||
// Mock the sharp function and attach static properties required by the implementation
|
||||
const sharp = vi.fn(() => sharpInstance);
|
||||
Object.assign(sharp, {
|
||||
fit: {
|
||||
cover: 'cover',
|
||||
},
|
||||
});
|
||||
Object.assign(sharp, { fit: { cover: 'cover' } });
|
||||
|
||||
return {
|
||||
sharp,
|
||||
sharp: sharp,
|
||||
resize,
|
||||
webp,
|
||||
toFile,
|
||||
|
||||
Reference in New Issue
Block a user