moar unit test !
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 6m34s
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 6m34s
This commit is contained in:
@@ -93,6 +93,11 @@ describe('FlyerUploader', { timeout: 20000 }, () => {
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Processing complete! Redirecting to flyer 42...')).toBeInTheDocument();
|
||||
expect(navigateSpy).toHaveBeenCalledWith('/flyers/42');
|
||||
});
|
||||
});
|
||||
|
||||
it('should poll for status, complete successfully, and redirect', async () => {
|
||||
|
||||
@@ -50,8 +50,19 @@ describe('API Client', () => {
|
||||
global.fetch = vi.fn((url, options) => {
|
||||
capturedUrl = new URL(url as string, 'http://localhost');
|
||||
capturedHeaders = options?.headers as Headers;
|
||||
capturedBody = options?.body; // Capture body for later inspection
|
||||
return Promise.resolve(new Response(JSON.stringify({ data: 'mock-success' }), { status: 200 }));
|
||||
|
||||
// FIX: Parse body if it is a string
|
||||
if (typeof options?.body === 'string') {
|
||||
try {
|
||||
capturedBody = JSON.parse(options.body);
|
||||
} catch {
|
||||
capturedBody = options.body;
|
||||
}
|
||||
} else {
|
||||
capturedBody = options?.body || null;
|
||||
}
|
||||
|
||||
return Promise.resolve(new Response(JSON.stringify({ data: 'mock-success' }), { status: 200, headers: new Headers() }));
|
||||
}) as any;
|
||||
});
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ describe('FlyerProcessingService', () => {
|
||||
const job = createMockJob({});
|
||||
const result = await service.prepareImageInputs('/tmp/flyer.jpg', job);
|
||||
|
||||
expect(result.imagePaths).toEqual([{ path: '/tmp/flyer.jpg', mimetype: 'image/jpeg' }]);
|
||||
expect(result.imagePaths).toEqual([{ path: '/tmp/flyer.jpg', mimetype: 'image/jpg' }]);
|
||||
expect(result.createdImagePaths).toEqual([]);
|
||||
expect(mocks.execAsync).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -198,6 +198,40 @@ vi.mock('../../services/aiApiClient', () => ({
|
||||
startVoiceSession: vi.fn(),
|
||||
}));
|
||||
|
||||
/**
|
||||
* Mocks the Express adapter for Bull Board.
|
||||
* This is critical for any test that imports `admin.routes.ts`. It replaces the
|
||||
* actual Bull Board UI adapter with a lightweight fake. This prevents the test
|
||||
* suite from crashing when trying to initialize the real UI, which has complex
|
||||
* dependencies not suitable for a test environment.
|
||||
*/
|
||||
vi.mock('@bull-board/express', () => ({
|
||||
ExpressAdapter: class {
|
||||
setBasePath() {}
|
||||
getRouter() {
|
||||
// Return a simple Express middleware function
|
||||
return (req: any, res: any, next: (err?: any) => void) => next();
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
/**
|
||||
* Mocks the Express adapter for Bull Board.
|
||||
* This is critical for any test that imports `admin.routes.ts`. It replaces the
|
||||
* actual Bull Board UI adapter with a lightweight fake. This prevents the test
|
||||
* suite from crashing when trying to initialize the real UI, which has complex
|
||||
* dependencies not suitable for a test environment.
|
||||
*/
|
||||
vi.mock('@bull-board/express', () => ({
|
||||
ExpressAdapter: class {
|
||||
setBasePath() {}
|
||||
getRouter() {
|
||||
// Return a simple Express middleware function
|
||||
return (req: any, res: any, next: (err?: any) => void) => next();
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
/**
|
||||
* Mocks the logger.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user