feat: Expand OCR with fuel receipt scanning and maintenance extraction (#129) #147

Merged
egullickson merged 26 commits from issue-129-expand-ocr-fuel-receipt-maintenance into main 2026-02-13 02:25:55 +00:00
2 changed files with 25 additions and 2 deletions
Showing only changes of commit 4e5da4782f - Show all commits

View File

@@ -128,6 +128,7 @@ export class GoogleMapsClient {
type: 'gas_station',
key: this.apiKey,
},
timeout: 5000,
}
);
@@ -145,8 +146,12 @@ export class GoogleMapsClient {
await cacheService.set(cacheKey, station, this.cacheTTL);
return station;
} catch (error) {
logger.error('Station name search failed', { error, merchantName });
} catch (error: any) {
if (error.code === 'ECONNABORTED' || error.message?.includes('timeout')) {
logger.warn('Station name search timed out', { merchantName, timeoutMs: 5000 });
} else {
logger.error('Station name search failed', { error, merchantName });
}
return null;
}
}

View File

@@ -32,6 +32,7 @@ import { GoogleMapsClient } from '../../external/google-maps/google-maps.client'
import { StationsService } from '../../domain/stations.service';
import { StationsRepository } from '../../data/stations.repository';
import { googleMapsClient } from '../../external/google-maps/google-maps.client';
import { logger } from '../../../../core/logging/logger';
import { mockStations } from '../fixtures/mock-stations';
describe('Station Matching from Receipt', () => {
@@ -162,6 +163,23 @@ describe('Station Matching from Receipt', () => {
expect(result).toBeNull();
});
it('should return null with logged warning on Places API timeout', async () => {
const timeoutError = new Error('timeout of 5000ms exceeded') as any;
timeoutError.code = 'ECONNABORTED';
mockAxios.get.mockRejectedValue(timeoutError);
const mockLogger = logger as jest.Mocked<typeof logger>;
const result = await client.searchStationByName('Shell');
expect(result).toBeNull();
expect(mockLogger.warn).toHaveBeenCalledWith(
'Station name search timed out',
expect.objectContaining({ merchantName: 'Shell', timeoutMs: 5000 })
);
expect(mockLogger.error).not.toHaveBeenCalled();
});
it('should include rating and photo reference when available', async () => {
mockAxios.get.mockResolvedValue({
data: {