integration tests fixes
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 4m43s

This commit is contained in:
2025-12-06 19:34:47 -08:00
parent da18719aa5
commit c86dc5f95e

View File

@@ -77,13 +77,6 @@ export class AIService {
imagePath: string,
imageMimeType: string
): Promise<{ raw_item_description: string; price_paid_cents: number }[]> {
if (process.env.NODE_ENV === 'test') {
return [
{ raw_item_description: "Test Item 1", price_paid_cents: 100 },
{ raw_item_description: "Test Item 2", price_paid_cents: 200 }
];
}
const prompt = `
Analyze the provided receipt image. Extract all purchased line items.
For each item, identify its description and total price.
@@ -138,28 +131,6 @@ export class AIService {
store_address: string | null;
items: ExtractedFlyerItem[];
}> {
// --- TEST MODE STUB ---
if (process.env.NODE_ENV === 'test') {
logger.info('[AIService] Test mode detected. Returning stubbed flyer data.');
return {
store_name: 'Test Store',
valid_from: '2023-01-01',
valid_to: '2023-01-07',
store_address: '123 Test St',
items: [
{
item: 'Test Apple',
price_display: '$1.00',
price_in_cents: 100,
quantity: '1 lb',
category_name: 'Produce',
master_item_id: undefined,
}
]
};
}
// ---------------------
let locationHint = '';
if (userProfileAddress) {
locationHint = `The user who uploaded this flyer has a profile address of "${userProfileAddress}". Use this as a strong hint for the store's location.`;
@@ -258,14 +229,6 @@ export class AIService {
cropArea: { x: number; y: number; width: number; height: number },
extractionType: 'store_name' | 'dates' | 'item_details'
): Promise<{ text: string }> {
if (process.env.NODE_ENV === 'test') {
// Return values that satisfy specific integration test assertions
if (extractionType === 'store_name') return { text: 'Test Store' };
// The integration test for address extraction might rely on this or a different path.
// If it's a generic text extraction, we return something safe.
return { text: 'Stubbed Text' };
}
// 1. Define prompts based on the extraction type
const prompts = {
store_name: 'What is the store name in this image? Respond with only the name.',
@@ -320,13 +283,6 @@ export class AIService {
* @returns A text response with trip planning advice and a list of map sources.
*/
async planTripWithMaps(items: FlyerItem[], store: { name: string } | undefined, userLocation: GeolocationCoordinates): Promise<{text: string; sources: { uri: string; title: string; }[]}> {
if (process.env.NODE_ENV === 'test') {
return {
text: 'Stubbed trip plan: Go to Test Store.',
sources: [{ uri: 'http://maps.google.com/test', title: 'Test Map' }]
};
}
const topItems = items.slice(0, 5).map(i => i.item).join(', ');
const storeName = store?.name || 'the grocery store';