more db unit tests - best o luck !
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 4m27s

This commit is contained in:
2025-12-06 23:27:37 -08:00
parent cea3586984
commit 0d04d74228
5 changed files with 27 additions and 12 deletions

View File

@@ -130,18 +130,22 @@ describe('AI Routes (/api/ai)', () => {
});
it('should pass user ID to the job when authenticated', async () => {
// Arrange: Create a mock authenticated user and inject it into the request
// Arrange: Create a new app instance specifically for this test
// with the authenticated user middleware already applied.
const mockUser = createMockUserProfile({ user_id: 'auth-user-1' });
app.use((req, res, next) => {
const authenticatedApp = express();
authenticatedApp.use(express.json({ strict: false }));
authenticatedApp.use((req, res, next) => {
req.user = mockUser;
next();
});
authenticatedApp.use('/api/ai', aiRouter);
vi.mocked(flyerDb.findFlyerByChecksum).mockResolvedValue(undefined);
vi.mocked(flyerQueue.add).mockResolvedValue({ id: 'job-456' } as any);
// Act
await supertest(app)
await supertest(authenticatedApp)
.post('/api/ai/upload-and-process')
.field('checksum', 'auth-checksum')
.attach('flyerFile', imagePath);

View File

@@ -40,9 +40,8 @@ router.post(
},
});
const upload = multer({
const uploadMiddleware = multer({
storage: storage,
limits: { fileSize: 5 * 1024 * 1024 }, // 5MB limit
fileFilter: (req, file, cb) => {
if (file.mimetype.startsWith('image/')) {
cb(null, true);
@@ -50,10 +49,12 @@ router.post(
cb(new Error('Only image files are allowed!'));
}
},
}).single('avatar');
});
const upload = uploadMiddleware.single('avatar');
// Manually invoke the multer middleware.
upload(req, res, async (err) => {
upload(req, res, async (err: unknown) => {
if (err) return next(err);
if (!req.file) return res.status(400).json({ message: 'No avatar file uploaded.' });
@@ -304,6 +305,9 @@ router.delete('/shopping-lists/:listId', async (req, res, next) => {
logger.debug(`[ROUTE] DELETE /api/users/shopping-lists/:listId - ENTER`);
const user = req.user as UserProfile;
const listId = parseInt(req.params.listId, 10);
if (isNaN(listId)) {
return res.status(400).json({ message: 'Invalid list ID.' });
}
try {
await db.deleteShoppingList(listId, user.user_id);
res.status(204).send();
@@ -349,6 +353,9 @@ router.put('/shopping-lists/items/:itemId', async (req, res, next) => {
router.delete('/shopping-lists/items/:itemId', async (req, res, next) => {
logger.debug(`[ROUTE] DELETE /api/users/shopping-lists/items/:itemId - ENTER`);
const itemId = parseInt(req.params.itemId, 10);
if (isNaN(itemId)) {
return res.status(400).json({ message: 'Invalid item ID.' });
}
try {
await db.removeShoppingListItem(itemId);
res.status(204).send();

View File

@@ -89,6 +89,10 @@ describe('Flyer DB Service', () => {
.mockResolvedValueOnce({ rows: [] }) // Link flyer_location
.mockResolvedValueOnce({ rows: [] }); // COMMIT
// Mock geocodeAddress to handle the null address case gracefully
const { geocodeAddress } = await import('../geocodingService.server');
vi.mocked(geocodeAddress).mockResolvedValue(null);
await createFlyerAndItems(mockFlyerData, []);
// Also test the case where store_address is null

View File

@@ -228,15 +228,15 @@ export async function updateShoppingListItem(itemId: number, updates: Partial<Sh
const values = [];
let valueIndex = 1;
if (updates.quantity !== undefined) {
if ('quantity' in updates) {
setClauses.push(`quantity = $${valueIndex++}`);
values.push(updates.quantity);
}
if (updates.is_purchased !== undefined) {
if ('is_purchased' in updates) {
setClauses.push(`is_purchased = $${valueIndex++}`);
values.push(updates.is_purchased);
}
if (updates.notes !== undefined) {
if ('notes' in updates) {
setClauses.push(`notes = $${valueIndex++}`);
values.push(updates.notes);
}