ensure mocks are used wherever possible, more test fixes
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 1h7m5s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 1h7m5s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// src/tests/utils/mockFactories.ts
|
||||
import { UserProfile, User, Flyer, Store, SuggestedCorrection, Brand, Category, FlyerItem, MasterGroceryItem, ShoppingList, ShoppingListItem, Achievement, UserAchievement, Budget, SpendingByCategory, Recipe, RecipeIngredient, RecipeComment, ActivityLogItem, DietaryRestriction, UserDietaryRestriction, Appliance, UserAppliance, Notification, UnmatchedFlyerItem, AdminUserView, WatchedItemDeal, LeaderboardUser, UserWithPasswordHash, Profile, Address, MenuPlan, PlannedMeal, PantryItem, Product, ShoppingTrip, ShoppingTripItem, Receipt, ReceiptItem } from '../../types';
|
||||
import { UserProfile, User, Flyer, Store, SuggestedCorrection, Brand, Category, FlyerItem, MasterGroceryItem, ShoppingList, ShoppingListItem, Achievement, UserAchievement, Budget, SpendingByCategory, Recipe, RecipeIngredient, RecipeComment, ActivityLogItem, DietaryRestriction, UserDietaryRestriction, Appliance, UserAppliance, Notification, UnmatchedFlyerItem, AdminUserView, WatchedItemDeal, LeaderboardUser, UserWithPasswordHash, Profile, Address, MenuPlan, PlannedMeal, PantryItem, Product, ShoppingTrip, ShoppingTripItem, Receipt, ReceiptItem, ProcessingStage, UserAlert, UserSubmittedPrice, RecipeRating, Tag, PantryLocation, DealItem, ItemPriceHistory, HistoricalPriceDataPoint, ReceiptDeal, RecipeCollection, SharedShoppingList, MostFrequentSaleItem, PantryRecipe, RecommendedRecipe, UnitPrice, Source } from '../../types';
|
||||
import type { AppStats } from '../../services/apiClient';
|
||||
|
||||
// --- ID Generator for Deterministic Mocking ---
|
||||
let idCounter = 0;
|
||||
@@ -254,6 +255,7 @@ export const createMockFlyerItem = (overrides: Partial<FlyerItem> & { flyer?: Pa
|
||||
item: 'Mock Item',
|
||||
price_display: '$1.99',
|
||||
price_in_cents: 199,
|
||||
unit_price: null,
|
||||
quantity: 'each',
|
||||
view_count: 0,
|
||||
click_count: 0,
|
||||
@@ -458,6 +460,15 @@ export const createMockActivityLogItem = (overrides: Partial<ActivityLogItem> =
|
||||
details: { list_name: 'Mock List', shopping_list_id: 1, shared_with_name: 'Another User' },
|
||||
};
|
||||
break;
|
||||
case 'recipe_favorited':
|
||||
specificLog = {
|
||||
...baseLog,
|
||||
action: 'recipe_favorited',
|
||||
display_text: 'User favorited a recipe.',
|
||||
icon: 'heart',
|
||||
details: { recipe_name: 'Mock Recipe', user_full_name: 'Mock User' },
|
||||
};
|
||||
break;
|
||||
case 'flyer_processed':
|
||||
default:
|
||||
specificLog = {
|
||||
@@ -788,6 +799,278 @@ export const createMockDietaryRestriction = (overrides: Partial<DietaryRestricti
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock DealItem object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe DealItem object.
|
||||
*/
|
||||
export const createMockDealItem = (overrides: Partial<DealItem> = {}): DealItem => {
|
||||
const defaultDealItem: DealItem = {
|
||||
item: 'Mock Deal Item',
|
||||
price_display: '$1.99',
|
||||
price_in_cents: 199,
|
||||
quantity: 'each',
|
||||
storeName: 'Mock Store',
|
||||
master_item_name: 'Mock Master Item',
|
||||
unit_price: null,
|
||||
};
|
||||
|
||||
return { ...defaultDealItem, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock ItemPriceHistory object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe ItemPriceHistory object.
|
||||
*/
|
||||
export const createMockItemPriceHistory = (overrides: Partial<ItemPriceHistory> = {}): ItemPriceHistory => {
|
||||
const defaultHistory: ItemPriceHistory = {
|
||||
item_price_history_id: getNextId(),
|
||||
master_item_id: getNextId(),
|
||||
summary_date: new Date().toISOString().split('T')[0],
|
||||
min_price_in_cents: 199,
|
||||
max_price_in_cents: 399,
|
||||
avg_price_in_cents: 299,
|
||||
data_points_count: 10,
|
||||
};
|
||||
return { ...defaultHistory, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock HistoricalPriceDataPoint object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe HistoricalPriceDataPoint object.
|
||||
*/
|
||||
export const createMockHistoricalPriceDataPoint = (overrides: Partial<HistoricalPriceDataPoint> = {}): HistoricalPriceDataPoint => {
|
||||
const defaultPoint: HistoricalPriceDataPoint = {
|
||||
master_item_id: getNextId(),
|
||||
avg_price_in_cents: 250,
|
||||
summary_date: new Date().toISOString().split('T')[0],
|
||||
};
|
||||
return { ...defaultPoint, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock ReceiptDeal object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe ReceiptDeal object.
|
||||
*/
|
||||
export const createMockReceiptDeal = (overrides: Partial<ReceiptDeal> = {}): ReceiptDeal => {
|
||||
const defaultDeal: ReceiptDeal = {
|
||||
receipt_item_id: getNextId(),
|
||||
master_item_id: getNextId(),
|
||||
item_name: 'Mock Deal Item',
|
||||
price_paid_cents: 199,
|
||||
current_best_price_in_cents: 150,
|
||||
potential_savings_cents: 49,
|
||||
deal_store_name: 'Competitor Store',
|
||||
flyer_id: getNextId(),
|
||||
};
|
||||
return { ...defaultDeal, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock RecipeCollection object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe RecipeCollection object.
|
||||
*/
|
||||
export const createMockRecipeCollection = (overrides: Partial<RecipeCollection> = {}): RecipeCollection => {
|
||||
const defaultCollection: RecipeCollection = {
|
||||
recipe_collection_id: getNextId(),
|
||||
user_id: `user-${getNextId()}`,
|
||||
name: 'My Favorite Recipes',
|
||||
description: 'A collection of mock recipes.',
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
return { ...defaultCollection, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock SharedShoppingList object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe SharedShoppingList object.
|
||||
*/
|
||||
export const createMockSharedShoppingList = (overrides: Partial<SharedShoppingList> = {}): SharedShoppingList => {
|
||||
const defaultSharedList: SharedShoppingList = {
|
||||
shared_shopping_list_id: getNextId(),
|
||||
shopping_list_id: getNextId(),
|
||||
shared_by_user_id: `user-${getNextId()}`,
|
||||
shared_with_user_id: `user-${getNextId()}`,
|
||||
permission_level: 'view',
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
return { ...defaultSharedList, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock MostFrequentSaleItem object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe MostFrequentSaleItem object.
|
||||
*/
|
||||
export const createMockMostFrequentSaleItem = (overrides: Partial<MostFrequentSaleItem> = {}): MostFrequentSaleItem => {
|
||||
const defaultItem: MostFrequentSaleItem = {
|
||||
master_item_id: getNextId(),
|
||||
item_name: 'Chicken Breast',
|
||||
sale_count: 25,
|
||||
};
|
||||
return { ...defaultItem, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock PantryRecipe object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe PantryRecipe object.
|
||||
*/
|
||||
export const createMockPantryRecipe = (overrides: Partial<PantryRecipe> = {}): PantryRecipe => {
|
||||
const defaultRecipe = createMockRecipe({ name: 'Pantry Special', ...overrides });
|
||||
const pantryRecipe: PantryRecipe = {
|
||||
...defaultRecipe,
|
||||
missing_ingredients_count: 2,
|
||||
pantry_ingredients_count: 5,
|
||||
};
|
||||
return { ...pantryRecipe, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock RecommendedRecipe object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe RecommendedRecipe object.
|
||||
*/
|
||||
export const createMockRecommendedRecipe = (overrides: Partial<RecommendedRecipe> = {}): RecommendedRecipe => {
|
||||
const defaultRecipe = createMockRecipe({ name: 'Highly Recommended', ...overrides });
|
||||
const recommendedRecipe: RecommendedRecipe = {
|
||||
...defaultRecipe,
|
||||
recommendation_score: 0.85,
|
||||
reason: 'Based on your recent activity and pantry items.',
|
||||
};
|
||||
return { ...recommendedRecipe, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock UnitPrice object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe UnitPrice object.
|
||||
*/
|
||||
export const createMockUnitPrice = (overrides: Partial<UnitPrice> = {}): UnitPrice => {
|
||||
const defaultUnitPrice: UnitPrice = {
|
||||
value: 100,
|
||||
unit: 'g',
|
||||
};
|
||||
return { ...defaultUnitPrice, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock Source object for use in tests, typically for AI analysis results.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe Source object.
|
||||
*/
|
||||
export const createMockSource = (overrides: Partial<Source> = {}): Source => {
|
||||
const defaultSource: Source = {
|
||||
uri: 'https://example.com/mock-source',
|
||||
title: 'Mock Source Title',
|
||||
};
|
||||
return { ...defaultSource, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock UserAlert object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe UserAlert object.
|
||||
*/
|
||||
export const createMockUserAlert = (overrides: Partial<UserAlert> = {}): UserAlert => {
|
||||
const defaultAlert: UserAlert = {
|
||||
user_alert_id: getNextId(),
|
||||
user_watched_item_id: getNextId(),
|
||||
alert_type: 'PRICE_BELOW',
|
||||
threshold_value: 499,
|
||||
is_active: true,
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
return { ...defaultAlert, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock UserSubmittedPrice object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe UserSubmittedPrice object.
|
||||
*/
|
||||
export const createMockUserSubmittedPrice = (overrides: Partial<UserSubmittedPrice> = {}): UserSubmittedPrice => {
|
||||
const defaultPrice: UserSubmittedPrice = {
|
||||
user_submitted_price_id: getNextId(),
|
||||
user_id: `user-${getNextId()}`,
|
||||
master_item_id: getNextId(),
|
||||
store_id: getNextId(),
|
||||
price_in_cents: 299,
|
||||
photo_url: null,
|
||||
upvotes: 0,
|
||||
downvotes: 0,
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
return { ...defaultPrice, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock RecipeRating object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe RecipeRating object.
|
||||
*/
|
||||
export const createMockRecipeRating = (overrides: Partial<RecipeRating> = {}): RecipeRating => {
|
||||
const defaultRating: RecipeRating = {
|
||||
recipe_rating_id: getNextId(),
|
||||
recipe_id: getNextId(),
|
||||
user_id: `user-${getNextId()}`,
|
||||
rating: 5,
|
||||
comment: 'Great recipe!',
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
return { ...defaultRating, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock Tag object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe Tag object.
|
||||
*/
|
||||
export const createMockTag = (overrides: Partial<Tag> = {}): Tag => {
|
||||
const tagId = overrides.tag_id ?? getNextId();
|
||||
const defaultTag: Tag = {
|
||||
tag_id: tagId,
|
||||
name: `Tag ${tagId}`,
|
||||
};
|
||||
return { ...defaultTag, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock PantryLocation object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe PantryLocation object.
|
||||
*/
|
||||
export const createMockPantryLocation = (overrides: Partial<PantryLocation> = {}): PantryLocation => {
|
||||
const locationId = overrides.pantry_location_id ?? getNextId();
|
||||
const defaultLocation: PantryLocation = {
|
||||
pantry_location_id: locationId,
|
||||
user_id: `user-${getNextId()}`,
|
||||
name: `Location ${locationId}`,
|
||||
};
|
||||
return { ...defaultLocation, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock AppStats object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe AppStats object.
|
||||
*/
|
||||
export const createMockAppStats = (overrides: Partial<AppStats> = {}): AppStats => {
|
||||
const defaultStats: AppStats = {
|
||||
userCount: 100,
|
||||
flyerCount: 50,
|
||||
flyerItemCount: 2000,
|
||||
storeCount: 5,
|
||||
pendingCorrectionCount: 0,
|
||||
};
|
||||
return { ...defaultStats, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock UserDietaryRestriction object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
@@ -998,6 +1281,22 @@ export const createMockNotification = (overrides: Partial<Notification> = {}): N
|
||||
return { ...defaultNotification, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock ProcessingStage object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe ProcessingStage object.
|
||||
*/
|
||||
export const createMockProcessingStage = (overrides: Partial<ProcessingStage> = {}): ProcessingStage => {
|
||||
const defaultStage: ProcessingStage = {
|
||||
name: 'Mock Stage',
|
||||
status: 'pending',
|
||||
detail: '',
|
||||
critical: true,
|
||||
};
|
||||
|
||||
return { ...defaultStage, ...overrides };
|
||||
};
|
||||
|
||||
export const createMockAppliance = (overrides: Partial<Appliance> = {}): Appliance => {
|
||||
return {
|
||||
appliance_id: 1,
|
||||
|
||||
Reference in New Issue
Block a user