moar unit test !
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 6m36s
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 6m36s
This commit is contained in:
@@ -17,6 +17,7 @@ Price trend analysis - weekly - biweekly, monthly, seasonal, yearly, real food i
|
||||
8) Do not make obsequious statements - we're here to do a job, not get patted on the shoulder for insignificant acheivements.
|
||||
9) Provide me with the npm command to execute rather than wanting to edit the package.json file. That is not the correct way to handle a package update.
|
||||
|
||||
10) Provide code changes in DIFF format
|
||||
|
||||
try to minimize repeating yourself as it just wastes time
|
||||
|
||||
|
||||
@@ -42,7 +42,12 @@ vi.mock('../services/geocodingService.server');
|
||||
vi.mock('../services/queueService.server');
|
||||
vi.mock('@bull-board/api');
|
||||
vi.mock('@bull-board/api/bullMQAdapter');
|
||||
vi.mock('@bull-board/express');
|
||||
vi.mock('@bull-board/express', () => ({
|
||||
ExpressAdapter: vi.fn().mockImplementation(() => ({
|
||||
setBasePath: vi.fn(),
|
||||
getRouter: () => (req: Request, res: Response, next: NextFunction) => next(),
|
||||
})),
|
||||
}));
|
||||
|
||||
// Import the mocked modules to control them
|
||||
import * as adminDb from '../services/db/admin.db';
|
||||
|
||||
@@ -27,7 +27,11 @@ vi.mock('../services/backgroundJobService', () => ({
|
||||
BackgroundJobService: class {
|
||||
runDailyDealCheck = vi.fn();
|
||||
},
|
||||
backgroundJobService: {
|
||||
runDailyDealCheck: vi.fn(),
|
||||
}
|
||||
}));
|
||||
|
||||
vi.mock('../services/geocodingService.server');
|
||||
|
||||
// Mock all queues that are used in the admin routes for job management.
|
||||
@@ -45,10 +49,17 @@ vi.mock('../services/queueService.server', () => ({
|
||||
|
||||
vi.mock('@bull-board/api');
|
||||
vi.mock('@bull-board/api/bullMQAdapter');
|
||||
vi.mock('@bull-board/express');
|
||||
|
||||
// Fix: Explicitly mock @bull-board/express with a constructible class mock
|
||||
vi.mock('@bull-board/express', () => ({
|
||||
ExpressAdapter: vi.fn().mockImplementation(() => ({
|
||||
setBasePath: vi.fn(),
|
||||
getRouter: vi.fn().mockReturnValue((req: Request, res: Response, next: NextFunction) => next()),
|
||||
})),
|
||||
}));
|
||||
|
||||
// Import the mocked modules to control them
|
||||
import { BackgroundJobService } from '../services/backgroundJobService';
|
||||
import { BackgroundJobService, backgroundJobService } from '../services/backgroundJobService';
|
||||
import { flyerQueue, analyticsQueue, cleanupQueue } from '../services/queueService.server';
|
||||
|
||||
// Mock the logger
|
||||
@@ -98,12 +109,11 @@ describe('Admin Job Trigger Routes (/api/admin/trigger)', () => {
|
||||
|
||||
describe('POST /trigger/daily-deal-check', () => {
|
||||
it('should trigger the daily deal check job and return 202 Accepted', async () => {
|
||||
const runDailyDealCheckSpy = vi.spyOn(BackgroundJobService.prototype, 'runDailyDealCheck').mockImplementation(async () => {});
|
||||
// Use the instance method mock
|
||||
const response = await supertest(app).post('/api/admin/trigger/daily-deal-check');
|
||||
expect(response.status).toBe(202);
|
||||
expect(response.body.message).toContain('Daily deal check job has been triggered');
|
||||
expect(runDailyDealCheckSpy).toHaveBeenCalledTimes(1);
|
||||
runDailyDealCheckSpy.mockRestore();
|
||||
expect(backgroundJobService.runDailyDealCheck).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -41,7 +41,14 @@ vi.mock('../services/backgroundJobService');
|
||||
vi.mock('../services/geocodingService.server');
|
||||
vi.mock('@bull-board/api');
|
||||
vi.mock('@bull-board/api/bullMQAdapter');
|
||||
vi.mock('@bull-board/express');
|
||||
|
||||
// Fix: Explicitly mock @bull-board/express with a constructible class mock
|
||||
vi.mock('@bull-board/express', () => ({
|
||||
ExpressAdapter: vi.fn().mockImplementation(() => ({
|
||||
setBasePath: vi.fn(),
|
||||
getRouter: vi.fn().mockReturnValue((req: Request, res: Response, next: NextFunction) => next()),
|
||||
})),
|
||||
}));
|
||||
|
||||
// Import the mocked modules to control them
|
||||
import * as adminDb from '../services/db/admin.db';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// src/routes/admin.db.ts
|
||||
// src/routes/admin.routes.ts
|
||||
import { Router, NextFunction } from 'express';
|
||||
import passport from './passport.routes';
|
||||
import { isAdmin } from './passport.routes'; // Correctly imported
|
||||
|
||||
Reference in New Issue
Block a user