brand new unit tests finally
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 2m24s

This commit is contained in:
2025-11-28 09:41:27 -08:00
parent 422123afa7
commit de00394908
5 changed files with 13 additions and 25 deletions

View File

@@ -17,7 +17,7 @@ import {
setUserAppliances,
getRecipesForUserDiets,
} from './personalization';
import type { MasterGroceryItem, PantryRecipe, RecommendedRecipe, WatchedItemDeal, PantryItemConversion, DietaryRestriction, Appliance, UserAppliance } from '../../types';
import type { MasterGroceryItem } from '../../types';
import { getPool } from './connection';
import { mockQuery, mockConnect } from '../../tests/setup/mock-db';

View File

@@ -15,7 +15,6 @@ import {
completeShoppingList,
getShoppingTripHistory,
createReceipt,
processReceiptItems,
findDealsForReceipt,
findReceiptOwner,
} from './shopping';

View File

@@ -3,7 +3,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
// Mock the nodemailer library BEFORE importing the email service.
const mockSendMail = vi.fn().mockImplementation((mailOptions) => {
// eslint-disable-next-line no-console
console.log('[TEST DEBUG] mockSendMail called with:', mailOptions?.to);
return Promise.resolve({
messageId: 'default-id',

View File

@@ -5,8 +5,6 @@
* does not reference any Node.js-specific globals like `process`.
*/
type LogLevel = 'INFO' | 'WARN' | 'ERROR' | 'DEBUG';
// Export the logger object for use throughout the client-side application.
export const logger = {
info: <T extends unknown[]>(message: string, ...args: T) => {

View File

@@ -1,34 +1,26 @@
// src/services/notificationService.test.ts
import { describe, it, expect, vi, beforeEach } from 'vitest';
import toast from 'react-hot-toast'; // Import the mocked module
import { notifySuccess, notifyError } from './notificationService';
// Define mocks with 'mock' prefix so they can be used inside vi.mock factory
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const mockSuccess = vi.fn((msg) => console.log('[TEST DEBUG] toast.success called with:', msg));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const mockError = vi.fn((msg) => console.log('[TEST DEBUG] toast.error called with:', msg));
// Mock react-hot-toast
vi.mock('react-hot-toast', () => {
const toastMock = vi.fn();
// Attach specific spies
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(toastMock as any).success = (...args: any[]) => mockSuccess(...args);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(toastMock as any).error = (...args: any[]) => mockError(...args);
const toastMock = vi.fn() as any;
toastMock.success = vi.fn();
toastMock.error = vi.fn();
return {
__esModule: true, // This is important for ES modules interop
default: toastMock,
toast: toastMock,
__esModule: true, // This is important for ES modules interop
};
});
describe('notificationService', () => {
beforeEach(() => {
// Clear mock history before each test to ensure isolation.
vi.clearAllMocks();
// vi.clearAllMocks(); // This is often too broad. Resetting specific mocks is safer.
vi.mocked(toast.success).mockClear();
vi.mocked(toast.error).mockClear();
});
describe('notifySuccess', () => {
@@ -36,8 +28,8 @@ describe('notificationService', () => {
const message = 'Operation completed successfully!';
notifySuccess(message);
expect(mockSuccess).toHaveBeenCalledTimes(1);
expect(mockSuccess).toHaveBeenCalledWith(
expect(toast.success).toHaveBeenCalledTimes(1);
expect(toast.success).toHaveBeenCalledWith(
message,
expect.objectContaining({
style: expect.any(Object), // Check that common styles are passed
@@ -55,8 +47,8 @@ describe('notificationService', () => {
const message = 'An unexpected error occurred.';
notifyError(message);
expect(mockError).toHaveBeenCalledTimes(1);
expect(mockError).toHaveBeenCalledWith(
expect(toast.error).toHaveBeenCalledTimes(1);
expect(toast.error).toHaveBeenCalledWith(
message,
expect.objectContaining({
style: expect.any(Object), // Check that common styles are passed