more db
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Failing after 45s

This commit is contained in:
2025-12-31 20:43:53 -08:00
parent 91254d18f3
commit 342f72b713
14 changed files with 867 additions and 408 deletions

View File

@@ -93,6 +93,8 @@ export const createMockUser = (overrides: Partial<User> = {}): User => {
const defaultUser: User = {
user_id: userId,
email: `${userId}@example.com`,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultUser, ...overrides };
@@ -119,10 +121,10 @@ export const createMockUserProfile = (
avatar_url: null,
preferences: {},
address_id: null,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
created_by: null,
address: null,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
user,
};
@@ -143,11 +145,11 @@ export const createMockStore = (overrides: Partial<Store> = {}): Store => {
const defaultStore: Store = {
store_id: storeId,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
name: 'Mock Store',
logo_url: null,
created_by: null,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultStore, ...overrides };
@@ -167,12 +169,11 @@ export const createMockFlyer = (
const flyerId = overrides.flyer_id ?? getNextId();
// Ensure the store_id is consistent between the flyer and the nested store object
const storeOverrides = overrides.store || {};
if (overrides.store_id && !storeOverrides.store_id) {
storeOverrides.store_id = overrides.store_id;
}
const store = createMockStore(storeOverrides);
const store = createMockStore({
...overrides.store,
// Prioritize the top-level store_id if provided
store_id: overrides.store_id ?? overrides.store?.store_id,
});
// Determine the final file_name to generate dependent properties from.
const fileName = overrides.file_name ?? `flyer-${flyerId}.jpg`;
@@ -190,8 +191,6 @@ export const createMockFlyer = (
const defaultFlyer: Flyer = {
flyer_id: flyerId,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
file_name: fileName,
image_url: `/flyer-images/${fileName}`,
icon_url: `/flyer-images/icons/icon-${fileName.replace(/\.[^/.]+$/, '.webp')}`,
@@ -203,6 +202,8 @@ export const createMockFlyer = (
status: 'processed',
item_count: 50,
uploaded_by: null,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
store,
};
@@ -244,12 +245,12 @@ export const createMockBrand = (overrides: Partial<Brand> = {}): Brand => {
const defaultBrand: Brand = {
brand_id: brandId,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
name: `Brand ${brandId}`,
logo_url: null,
store_id: null,
store_name: null,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultBrand, ...overrides };
@@ -266,6 +267,8 @@ export const createMockCategory = (overrides: Partial<Category> = {}): Category
const defaultCategory: Category = {
category_id: categoryId,
name: `Category ${categoryId}`,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultCategory, ...overrides };
@@ -319,7 +322,6 @@ export const createMockFlyerItem = (
const defaultItem: FlyerItem = {
flyer_item_id: flyerItemId,
flyer_id: flyerId,
created_at: new Date().toISOString(),
item: 'Mock Item',
price_display: '$1.99',
price_in_cents: 199,
@@ -327,6 +329,7 @@ export const createMockFlyerItem = (
quantity: 'each',
view_count: 0,
click_count: 0,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
@@ -358,11 +361,11 @@ export const createMockRecipe = (
rating_count: 50,
fork_count: 10,
status: 'public',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
prep_time_minutes: 15,
cook_time_minutes: 30,
servings: 4,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
const {
@@ -412,6 +415,8 @@ export const createMockRecipeIngredient = (
master_item_id: masterItemId,
quantity: 1,
unit: 'cup',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
const { master_item: _, ...itemOverrides } = overrides;
@@ -432,6 +437,7 @@ export const createMockRecipeComment = (overrides: Partial<RecipeComment> = {}):
content: 'This is a mock comment.',
status: 'visible',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
user_full_name: 'Mock User', // This was correct
user_avatar_url: undefined,
};
@@ -452,6 +458,8 @@ export const createMockPlannedMeal = (overrides: Partial<PlannedMeal> = {}): Pla
plan_date: new Date().toISOString().split('T')[0],
meal_type: 'dinner',
servings_to_cook: 4,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultMeal, ...overrides };
@@ -476,6 +484,7 @@ export const createMockMenuPlan = (
start_date: new Date().toISOString().split('T')[0],
end_date: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString().split('T')[0],
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
const { planned_meals: mealsOverrides, ...planOverrides } = overrides;
@@ -661,23 +670,22 @@ export const createMockMasterGroceryItem = (
overrides: Partial<MasterGroceryItem> & { category?: Partial<Category> } = {},
): MasterGroceryItem => {
// Ensure category_id is consistent between the item and the nested category object
const categoryOverrides = overrides.category || {};
if (overrides.category_id && !categoryOverrides.category_id) {
categoryOverrides.category_id = overrides.category_id;
}
const category = createMockCategory(categoryOverrides);
const category = createMockCategory({
...overrides.category,
// Prioritize the top-level category_id if provided
category_id: overrides.category_id ?? overrides.category?.category_id,
});
const defaultItem: MasterGroceryItem = {
master_grocery_item_id: getNextId(),
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
name: 'Mock Master Item',
category_id: category.category_id,
category_name: category.name,
is_allergen: false,
allergy_info: null,
created_by: null,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
const { category: _, ...itemOverrides } = overrides;
@@ -729,9 +737,9 @@ export const createMockShoppingList = (
shopping_list_id: shoppingListId,
user_id: `user-${getNextId()}`,
name: 'My Mock List',
items: [],
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
items: [],
};
if (overrides.items) {
@@ -767,15 +775,12 @@ export const createMockShoppingListItem = (
shopping_list_id: shoppingListId,
custom_item_name: 'Mock Shopping List Item',
quantity: 1,
is_purchased: false,
is_purchased: false, // This was correct
added_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
master_item_id: masterItemId,
};
if (masterItemId) {
defaultItem.master_item_id = masterItemId;
}
const { master_item: masterItemOverride, ...itemOverrides } = overrides;
const result = { ...defaultItem, ...itemOverrides };
@@ -805,6 +810,8 @@ export const createMockShoppingTripItem = (
master_item_name: masterItemId ? (overrides.master_item?.name ?? 'Mock Master Item') : null,
quantity: 1,
price_paid_cents: 199,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
const { master_item: _, ...itemOverrides } = overrides;
@@ -829,6 +836,7 @@ export const createMockShoppingTrip = (
completed_at: new Date().toISOString(),
total_spent_cents: 0,
items: [],
updated_at: new Date().toISOString(),
};
const { items: itemsOverrides, ...tripOverrides } = overrides;
@@ -864,6 +872,8 @@ export const createMockReceiptItem = (overrides: Partial<ReceiptItem> = {}): Rec
master_item_id: null,
product_id: null,
status: 'unmatched',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultItem, ...overrides };
@@ -888,8 +898,9 @@ export const createMockReceipt = (
total_amount_cents: null,
status: 'pending',
raw_text: null,
created_at: new Date().toISOString(),
processed_at: null,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
const { items: itemsOverrides, ...receiptOverrides } = overrides;
@@ -916,6 +927,8 @@ export const createMockDietaryRestriction = (
dietary_restriction_id: 1,
name: 'Vegetarian',
type: 'diet',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
...overrides,
};
};
@@ -955,6 +968,8 @@ export const createMockItemPriceHistory = (
max_price_in_cents: 399,
avg_price_in_cents: 299,
data_points_count: 10,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultHistory, ...overrides };
};
@@ -1008,6 +1023,7 @@ export const createMockRecipeCollection = (
name: 'My Favorite Recipes',
description: 'A collection of mock recipes.',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultCollection, ...overrides };
};
@@ -1027,6 +1043,7 @@ export const createMockSharedShoppingList = (
shared_with_user_id: `user-${getNextId()}`,
permission_level: 'view',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultSharedList, ...overrides };
};
@@ -1118,6 +1135,7 @@ export const createMockUserAlert = (overrides: Partial<UserAlert> = {}): UserAle
threshold_value: 499,
is_active: true,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultAlert, ...overrides };
};
@@ -1140,6 +1158,7 @@ export const createMockUserSubmittedPrice = (
upvotes: 0,
downvotes: 0,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultPrice, ...overrides };
};
@@ -1157,6 +1176,7 @@ export const createMockRecipeRating = (overrides: Partial<RecipeRating> = {}): R
rating: 5,
comment: 'Great recipe!',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultRating, ...overrides };
};
@@ -1171,6 +1191,8 @@ export const createMockTag = (overrides: Partial<Tag> = {}): Tag => {
const defaultTag: Tag = {
tag_id: tagId,
name: `Tag ${tagId}`,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultTag, ...overrides };
};
@@ -1188,6 +1210,8 @@ export const createMockPantryLocation = (
pantry_location_id: locationId,
user_id: `user-${getNextId()}`,
name: `Location ${locationId}`,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultLocation, ...overrides };
};
@@ -1228,6 +1252,7 @@ export const createMockUserDietaryRestriction = (
const defaultUserRestriction: UserDietaryRestriction = {
user_id: userId,
restriction_id: restrictionId,
created_at: new Date().toISOString(),
};
return { ...defaultUserRestriction, ...overrides };
@@ -1245,12 +1270,14 @@ export const createMockUserAppliance = (
const userId = overrides.user_id ?? overrides.user?.user_id ?? `user-${getNextId()}`;
const applianceId = overrides.appliance_id ?? overrides.appliance?.appliance_id ?? getNextId();
const defaultUserAppliance: UserAppliance = {
const defaultUserAppliance = {
user_id: userId,
appliance_id: applianceId,
created_at: new Date().toISOString(),
};
return { ...defaultUserAppliance, ...overrides };
// The 'as UserAppliance' cast is necessary because TypeScript can't guarantee that the spread of a Partial<T> results in a complete T.
return { ...defaultUserAppliance, ...overrides } as UserAppliance;
};
/**
@@ -1266,13 +1293,13 @@ export const createMockAddress = (overrides: Partial<Address> = {}): Address =>
province_state: 'BC',
postal_code: 'V8T 1A1',
country: 'CA',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
// Optional fields
address_line_2: null,
latitude: null,
longitude: null,
location: null,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultAddress, ...overrides };
@@ -1309,8 +1336,6 @@ export const createMockUserWithPasswordHash = (
*/
export const createMockProfile = (overrides: Partial<Profile> = {}): Profile => {
const defaultProfile: Profile = {
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
full_name: 'Mock Profile User',
avatar_url: null,
address_id: null,
@@ -1319,6 +1344,8 @@ export const createMockProfile = (overrides: Partial<Profile> = {}): Profile =>
preferences: {},
created_by: null,
updated_by: null,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultProfile, ...overrides };
@@ -1376,14 +1403,14 @@ export const createMockUnmatchedFlyerItem = (
const defaultItem: UnmatchedFlyerItem = {
unmatched_flyer_item_id: getNextId(),
status: 'pending',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
reviewed_at: null,
flyer_item_id: getNextId(),
flyer_item_name: 'Mystery Product',
price_display: '$?.??',
flyer_id: getNextId(),
store_name: 'Random Store',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
return { ...defaultItem, ...overrides };
@@ -1400,10 +1427,10 @@ export const createMockAdminUserView = (overrides: Partial<AdminUserView> = {}):
const defaultUserView: AdminUserView = {
user_id: userId,
email: `${userId}@example.com`,
created_at: new Date().toISOString(),
role: 'user',
full_name: 'Mock User',
avatar_url: null,
created_at: new Date().toISOString(),
};
return { ...defaultUserView, ...overrides };
@@ -1450,6 +1477,8 @@ export const createMockAppliance = (overrides: Partial<Appliance> = {}): Applian
return {
appliance_id: 1,
name: 'Oven',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
...overrides,
};
};
@@ -1482,7 +1511,7 @@ export const createMockAddressPayload = (overrides: Partial<Address> = {}): Part
...overrides,
});
export const createMockSearchQueryPayload = (overrides: Partial<Omit<SearchQuery, 'search_query_id' | 'id' | 'created_at' | 'user_id'>> = {}): Omit<SearchQuery, 'search_query_id' | 'id' | 'created_at' | 'user_id'> => ({
export const createMockSearchQueryPayload = (overrides: Partial<Omit<SearchQuery, 'search_query_id' | 'created_at' | 'updated_at' | 'user_id'>> = {}): Omit<SearchQuery, 'search_query_id' | 'created_at' | 'updated_at' | 'user_id'> => ({
query_text: 'mock search',
result_count: 5,
was_successful: true,