Refactor: Update test files to improve mock structure and remove unused imports
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 6m51s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 6m51s
This commit is contained in:
@@ -5,7 +5,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|||||||
import { FlyerCountDisplay } from './FlyerCountDisplay';
|
import { FlyerCountDisplay } from './FlyerCountDisplay';
|
||||||
import { useFlyers } from '../hooks/useFlyers';
|
import { useFlyers } from '../hooks/useFlyers';
|
||||||
import { FlyersProvider } from '../providers/FlyersProvider';
|
import { FlyersProvider } from '../providers/FlyersProvider';
|
||||||
import { useInfiniteQuery } from '../hooks/useInfiniteQuery';
|
|
||||||
import type { Flyer } from '../types';
|
import type { Flyer } from '../types';
|
||||||
|
|
||||||
// Mock the dependencies
|
// Mock the dependencies
|
||||||
|
|||||||
@@ -6,9 +6,18 @@ import adminRouter from './admin.routes'; // This was a duplicate, fixed.
|
|||||||
import { createMockUserProfile, createMockSuggestedCorrection, createMockBrand, createMockRecipe, createMockRecipeComment, createMockUnmatchedFlyerItem } from '../tests/utils/mockFactories';
|
import { createMockUserProfile, createMockSuggestedCorrection, createMockBrand, createMockRecipe, createMockRecipeComment, createMockUnmatchedFlyerItem } from '../tests/utils/mockFactories';
|
||||||
import { SuggestedCorrection, Brand, UserProfile, UnmatchedFlyerItem } from '../types';
|
import { SuggestedCorrection, Brand, UserProfile, UnmatchedFlyerItem } from '../types';
|
||||||
import { NotFoundError } from '../services/db/errors.db';
|
import { NotFoundError } from '../services/db/errors.db';
|
||||||
import { mockLogger } from '../tests/utils/mockLogger';
|
|
||||||
import { createTestApp } from '../tests/utils/createTestApp';
|
import { createTestApp } from '../tests/utils/createTestApp';
|
||||||
|
|
||||||
|
const { mockLogger } = vi.hoisted(() => ({
|
||||||
|
mockLogger: {
|
||||||
|
info: vi.fn(),
|
||||||
|
debug: vi.fn(),
|
||||||
|
warn: vi.fn(),
|
||||||
|
error: vi.fn(),
|
||||||
|
child: vi.fn().mockReturnThis(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock('../lib/queue', () => ({
|
vi.mock('../lib/queue', () => ({
|
||||||
serverAdapter: {
|
serverAdapter: {
|
||||||
getRouter: () => (req: Request, res: Response, next: NextFunction) => next(), // Return a dummy express handler
|
getRouter: () => (req: Request, res: Response, next: NextFunction) => next(), // Return a dummy express handler
|
||||||
|
|||||||
@@ -6,9 +6,18 @@ import adminRouter from './admin.routes';
|
|||||||
import { createMockUserProfile } from '../tests/utils/mockFactories';
|
import { createMockUserProfile } from '../tests/utils/mockFactories';
|
||||||
import type { Job } from 'bullmq';
|
import type { Job } from 'bullmq';
|
||||||
import type { UserProfile } from '../types';
|
import type { UserProfile } from '../types';
|
||||||
import { mockLogger } from '../tests/utils/mockLogger';
|
|
||||||
import { createTestApp } from '../tests/utils/createTestApp';
|
import { createTestApp } from '../tests/utils/createTestApp';
|
||||||
|
|
||||||
|
const { mockLogger } = vi.hoisted(() => ({
|
||||||
|
mockLogger: {
|
||||||
|
info: vi.fn(),
|
||||||
|
debug: vi.fn(),
|
||||||
|
warn: vi.fn(),
|
||||||
|
error: vi.fn(),
|
||||||
|
child: vi.fn().mockReturnThis(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
// --- Mocks ---
|
// --- Mocks ---
|
||||||
|
|
||||||
// Mock the background job service to control its methods.
|
// Mock the background job service to control its methods.
|
||||||
|
|||||||
@@ -3,11 +3,22 @@ import { describe, it, expect, vi, beforeEach, type Mocked } from 'vitest';
|
|||||||
import supertest from 'supertest';
|
import supertest from 'supertest';
|
||||||
import { Request, Response, NextFunction } from 'express';
|
import { Request, Response, NextFunction } from 'express';
|
||||||
import adminRouter from './admin.routes';
|
import adminRouter from './admin.routes';
|
||||||
import { createMockUserProfile, createMockActivityLogItem } from '../tests/utils/mockFactories';
|
import {
|
||||||
|
createMockUserProfile,
|
||||||
|
createMockActivityLogItem,
|
||||||
|
} from '../tests/utils/mockFactories';
|
||||||
import { UserProfile } from '../types';
|
import { UserProfile } from '../types';
|
||||||
import { mockLogger } from '../tests/utils/mockLogger';
|
|
||||||
import { createTestApp } from '../tests/utils/createTestApp';
|
import { createTestApp } from '../tests/utils/createTestApp';
|
||||||
|
|
||||||
|
const { mockLogger } = vi.hoisted(() => ({
|
||||||
|
mockLogger: {
|
||||||
|
info: vi.fn(),
|
||||||
|
debug: vi.fn(),
|
||||||
|
warn: vi.fn(),
|
||||||
|
error: vi.fn(),
|
||||||
|
child: vi.fn().mockReturnThis(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
vi.mock('../lib/queue', () => ({
|
vi.mock('../lib/queue', () => ({
|
||||||
serverAdapter: {
|
serverAdapter: {
|
||||||
getRouter: () => (req: Request, res: Response, next: NextFunction) => next(), // Return a dummy express handler
|
getRouter: () => (req: Request, res: Response, next: NextFunction) => next(), // Return a dummy express handler
|
||||||
|
|||||||
@@ -5,9 +5,18 @@ import { Request, Response, NextFunction } from 'express';
|
|||||||
import adminRouter from './admin.routes';
|
import adminRouter from './admin.routes';
|
||||||
import { createMockUserProfile } from '../tests/utils/mockFactories';
|
import { createMockUserProfile } from '../tests/utils/mockFactories';
|
||||||
import { UserProfile } from '../types';
|
import { UserProfile } from '../types';
|
||||||
import { mockLogger } from '../tests/utils/mockLogger';
|
|
||||||
import { createTestApp } from '../tests/utils/createTestApp';
|
import { createTestApp } from '../tests/utils/createTestApp';
|
||||||
|
|
||||||
|
const { mockLogger } = vi.hoisted(() => ({
|
||||||
|
mockLogger: {
|
||||||
|
info: vi.fn(),
|
||||||
|
debug: vi.fn(),
|
||||||
|
warn: vi.fn(),
|
||||||
|
error: vi.fn(),
|
||||||
|
child: vi.fn().mockReturnThis(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock('../services/db/index.db', () => ({
|
vi.mock('../services/db/index.db', () => ({
|
||||||
adminRepo: {
|
adminRepo: {
|
||||||
getApplicationStats: vi.fn(),
|
getApplicationStats: vi.fn(),
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ vi.mock('../services/db/index.db', () => ({
|
|||||||
flyerRepo: {},
|
flyerRepo: {},
|
||||||
recipeRepo: {},
|
recipeRepo: {},
|
||||||
userRepo: {},
|
userRepo: {},
|
||||||
|
personalizationRepo: {},
|
||||||
}));
|
}));
|
||||||
vi.mock('../services/db/flyer.db');
|
vi.mock('../services/db/flyer.db');
|
||||||
vi.mock('../services/db/recipe.db');
|
vi.mock('../services/db/recipe.db');
|
||||||
|
|||||||
@@ -7,9 +7,18 @@ import type { Job } from 'bullmq';
|
|||||||
import aiRouter from './ai.routes';
|
import aiRouter from './ai.routes';
|
||||||
import { createMockUserProfile, createMockFlyer } from '../tests/utils/mockFactories';
|
import { createMockUserProfile, createMockFlyer } from '../tests/utils/mockFactories';
|
||||||
import * as aiService from '../services/aiService.server';
|
import * as aiService from '../services/aiService.server';
|
||||||
import { mockLogger } from '../tests/utils/mockLogger';
|
|
||||||
import { createTestApp } from '../tests/utils/createTestApp';
|
import { createTestApp } from '../tests/utils/createTestApp';
|
||||||
|
|
||||||
|
const { mockLogger } = vi.hoisted(() => ({
|
||||||
|
mockLogger: {
|
||||||
|
info: vi.fn(),
|
||||||
|
debug: vi.fn(),
|
||||||
|
warn: vi.fn(),
|
||||||
|
error: vi.fn(),
|
||||||
|
child: vi.fn().mockReturnThis(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
// Mock the AI service methods to avoid making real AI calls
|
// Mock the AI service methods to avoid making real AI calls
|
||||||
vi.mock('../services/aiService.server', () => ({
|
vi.mock('../services/aiService.server', () => ({
|
||||||
aiService: {
|
aiService: {
|
||||||
|
|||||||
@@ -472,7 +472,7 @@ describe('Flyer DB Service', () => {
|
|||||||
|
|
||||||
it('should rollback transaction on generic error', async () => {
|
it('should rollback transaction on generic error', async () => {
|
||||||
const dbError = new Error('DB Error');
|
const dbError = new Error('DB Error');
|
||||||
vi.mocked(withTransaction).mockImplementation(async (callback) => {
|
vi.mocked(withTransaction).mockImplementation(async (_callback) => {
|
||||||
throw dbError; // Simulate error during transaction
|
throw dbError; // Simulate error during transaction
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user