feat: Update AI service to use new Google Generative AI SDK
Some checks are pending
Deploy to Test Environment / deploy-to-test (push) Has started running
Some checks are pending
Deploy to Test Environment / deploy-to-test (push) Has started running
- Refactored AIService to integrate with the latest GoogleGenAI SDK, updating the generateContent method signature and response handling. - Adjusted error handling and logging for improved clarity and consistency. - Enhanced mock implementations in tests to align with the new SDK structure. refactor: Modify Admin DB service to use Profile type - Updated AdminRepository to replace User type with Profile in relevant methods. - Enhanced test cases to utilize mock factories for creating Profile and AdminUserView objects. fix: Improve error handling in BudgetRepository - Implemented type-safe checks for PostgreSQL error codes to enhance error handling in createBudget method. test: Refactor Deals DB tests for type safety - Updated DealsRepository tests to use Pool type for mock instances, ensuring type safety. chore: Add new mock factories for testing - Introduced mock factories for UserWithPasswordHash, Profile, WatchedItemDeal, LeaderboardUser, and UnmatchedFlyerItem to streamline test data creation. style: Clean up queue service tests - Refactored queue service tests to improve readability and maintainability, including better handling of mock worker instances. docs: Update types to include UserWithPasswordHash - Added UserWithPasswordHash interface to types for better clarity on user authentication data structure. chore: Remove deprecated Google AI SDK references - Updated code and documentation to reflect the migration to the new Google Generative AI SDK, removing references to the deprecated SDK.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// src/tests/utils/mockFactories.ts
|
||||
import { UserProfile, User, Flyer, Store, SuggestedCorrection, Brand, FlyerItem, MasterGroceryItem, ShoppingList, ShoppingListItem, Achievement, UserAchievement, Budget, SpendingByCategory, Recipe, RecipeComment, ActivityLogItem, DietaryRestriction, Appliance } from '../../types';
|
||||
import { UserProfile, User, Flyer, Store, SuggestedCorrection, Brand, FlyerItem, MasterGroceryItem, ShoppingList, ShoppingListItem, Achievement, UserAchievement, Budget, SpendingByCategory, Recipe, RecipeComment, ActivityLogItem, DietaryRestriction, Appliance, Notification, UnmatchedFlyerItem, AdminUserView, WatchedItemDeal, LeaderboardUser, UserWithPasswordHash, Profile } from '../../types';
|
||||
|
||||
/**
|
||||
* Creates a mock UserProfile object for use in tests, ensuring type safety.
|
||||
@@ -374,6 +374,142 @@ export const createMockDietaryRestriction = (overrides: Partial<DietaryRestricti
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock UserWithPasswordHash object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe UserWithPasswordHash object.
|
||||
*/
|
||||
export const createMockUserWithPasswordHash = (overrides: Partial<UserWithPasswordHash> = {}): UserWithPasswordHash => {
|
||||
const userId = overrides.user_id ?? `user-${Math.random().toString(36).substring(2, 9)}`;
|
||||
|
||||
const defaultUser: UserWithPasswordHash = {
|
||||
user_id: userId,
|
||||
email: `${userId}@example.com`,
|
||||
password_hash: 'hashed_password',
|
||||
failed_login_attempts: 0,
|
||||
last_failed_login: null,
|
||||
};
|
||||
|
||||
return { ...defaultUser, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock Profile object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe Profile object.
|
||||
*/
|
||||
export const createMockProfile = (overrides: Partial<Profile> = {}): Profile => {
|
||||
const userId = overrides.user_id ?? `user-${Math.random().toString(36).substring(2, 9)}`;
|
||||
|
||||
const defaultProfile: Profile = {
|
||||
user_id: userId,
|
||||
updated_at: new Date().toISOString(),
|
||||
full_name: 'Mock Profile User',
|
||||
avatar_url: null,
|
||||
address_id: null,
|
||||
points: 0,
|
||||
role: 'user',
|
||||
preferences: {},
|
||||
};
|
||||
|
||||
return { ...defaultProfile, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock WatchedItemDeal object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe WatchedItemDeal object.
|
||||
*/
|
||||
export const createMockWatchedItemDeal = (overrides: Partial<WatchedItemDeal> = {}): WatchedItemDeal => {
|
||||
const defaultDeal: WatchedItemDeal = {
|
||||
master_item_id: Math.floor(Math.random() * 1000),
|
||||
item_name: 'Mock Deal Item',
|
||||
best_price_in_cents: Math.floor(Math.random() * 1000) + 100,
|
||||
store_name: 'Mock Store',
|
||||
flyer_id: Math.floor(Math.random() * 100),
|
||||
valid_to: new Date(Date.now() + 5 * 24 * 60 * 60 * 1000).toISOString(), // 5 days from now
|
||||
};
|
||||
|
||||
return { ...defaultDeal, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock LeaderboardUser object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe LeaderboardUser object.
|
||||
*/
|
||||
export const createMockLeaderboardUser = (overrides: Partial<LeaderboardUser> = {}): LeaderboardUser => {
|
||||
const userId = overrides.user_id ?? `user-${Math.random().toString(36).substring(2, 9)}`;
|
||||
|
||||
const defaultUser: LeaderboardUser = {
|
||||
user_id: userId,
|
||||
full_name: 'Leaderboard User',
|
||||
avatar_url: null,
|
||||
points: Math.floor(Math.random() * 1000),
|
||||
rank: String(Math.floor(Math.random() * 100) + 1),
|
||||
};
|
||||
|
||||
return { ...defaultUser, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock UnmatchedFlyerItem object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe UnmatchedFlyerItem object.
|
||||
*/
|
||||
export const createMockUnmatchedFlyerItem = (overrides: Partial<UnmatchedFlyerItem> = {}): UnmatchedFlyerItem => {
|
||||
const defaultItem: UnmatchedFlyerItem = {
|
||||
unmatched_flyer_item_id: Math.floor(Math.random() * 1000),
|
||||
status: 'pending',
|
||||
created_at: new Date().toISOString(),
|
||||
flyer_item_id: Math.floor(Math.random() * 10000),
|
||||
flyer_item_name: 'Mystery Product',
|
||||
price_display: '$?.??',
|
||||
flyer_id: Math.floor(Math.random() * 100),
|
||||
store_name: 'Random Store',
|
||||
};
|
||||
|
||||
return { ...defaultItem, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock AdminUserView object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe AdminUserView object.
|
||||
*/
|
||||
export const createMockAdminUserView = (overrides: Partial<AdminUserView> = {}): AdminUserView => {
|
||||
const userId = overrides.user_id ?? `user-${Math.random().toString(36).substring(2, 9)}`;
|
||||
|
||||
const defaultUserView: AdminUserView = {
|
||||
user_id: userId,
|
||||
email: `${userId}@example.com`,
|
||||
created_at: new Date().toISOString(),
|
||||
role: 'user',
|
||||
full_name: 'Mock User',
|
||||
avatar_url: null,
|
||||
};
|
||||
|
||||
return { ...defaultUserView, ...overrides };
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mock Notification object for use in tests.
|
||||
* @param overrides - An object containing properties to override the default mock values.
|
||||
* @returns A complete and type-safe Notification object.
|
||||
*/
|
||||
export const createMockNotification = (overrides: Partial<Notification> = {}): Notification => {
|
||||
const defaultNotification: Notification = {
|
||||
notification_id: Math.floor(Math.random() * 1000),
|
||||
user_id: `user-${Math.random().toString(36).substring(2, 9)}`,
|
||||
content: 'This is a mock notification.',
|
||||
link_url: null,
|
||||
is_read: false,
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
|
||||
return { ...defaultNotification, ...overrides };
|
||||
};
|
||||
|
||||
export const createMockAppliance = (overrides: Partial<Appliance> = {}): Appliance => {
|
||||
return {
|
||||
appliance_id: 1,
|
||||
|
||||
Reference in New Issue
Block a user