Google Maps Bug

This commit is contained in:
Eric Gullickson
2025-11-08 12:17:29 -06:00
parent efbe9ba3c0
commit bb4a356b9e
39 changed files with 1175 additions and 449 deletions

View File

@@ -52,9 +52,12 @@ export const mockSavedStations: SavedStation[] = [
id: '550e8400-e29b-41d4-a716-446655440000',
userId: 'user123',
stationId: mockStations[0].placeId,
placeId: mockStations[0].placeId,
nickname: 'Work Gas Station',
notes: 'Usually has good prices, rewards program available',
isFavorite: true,
has93Octane: true,
has93OctaneEthanolFree: true,
createdAt: new Date('2024-01-01'),
updatedAt: new Date('2024-01-15')
},
@@ -62,9 +65,12 @@ export const mockSavedStations: SavedStation[] = [
id: '550e8400-e29b-41d4-a716-446655440001',
userId: 'user123',
stationId: mockStations[1].placeId,
placeId: mockStations[1].placeId,
nickname: 'Home Station',
notes: 'Closest to apartment',
isFavorite: true,
has93Octane: true,
has93OctaneEthanolFree: false,
createdAt: new Date('2024-01-05'),
updatedAt: new Date('2024-01-10')
}

View File

@@ -26,7 +26,8 @@ describe('StationsService', () => {
cacheStation: jest.fn().mockResolvedValue(undefined),
getCachedStation: jest.fn(),
saveStation: jest.fn(),
getUserSavedStations: jest.fn(),
getUserSavedStations: jest.fn().mockResolvedValue([]),
updateSavedStation: jest.fn(),
deleteSavedStation: jest.fn()
} as unknown as jest.Mocked<StationsRepository>;
@@ -51,6 +52,7 @@ describe('StationsService', () => {
expect(result.stations).toHaveLength(3);
expect(result.stations[0]?.name).toBe('Shell Gas Station - Downtown');
expect(mockRepository.cacheStation).toHaveBeenCalledTimes(3);
expect(mockRepository.getUserSavedStations).toHaveBeenCalledWith(mockUserId);
});
it('should sort stations by distance', async () => {
@@ -108,6 +110,32 @@ describe('StationsService', () => {
expect(mockRepository.cacheStation).toHaveBeenCalled();
});
it('should prioritize saved stations and include saved metadata', async () => {
const savedStation = mockSavedStations[0];
if (!savedStation) throw new Error('Mock saved station not found');
mockRepository.getUserSavedStations.mockResolvedValue([savedStation]);
const stationsWithDistance = [
{ ...mockStations[0], distance: 900 },
{ ...mockStations[1], distance: 100 }
];
(googleMapsClient.searchNearbyStations as jest.Mock).mockResolvedValue(
stationsWithDistance
);
const result = await service.searchNearbyStations(
{
latitude: searchCoordinates.sanFrancisco.latitude,
longitude: searchCoordinates.sanFrancisco.longitude
},
mockUserId
);
expect(result.stations[0]?.placeId).toBe(savedStation.stationId);
expect(result.stations[0]?.savedMetadata?.has93Octane).toBe(true);
});
});
describe('saveStation', () => {
@@ -153,13 +181,17 @@ describe('StationsService', () => {
await service.saveStation(station.placeId, mockUserId, {
nickname: 'Favorite Station',
notes: 'Best prices in area',
isFavorite: true
isFavorite: true,
has93Octane: true,
has93OctaneEthanolFree: false
});
expect(mockRepository.saveStation).toHaveBeenCalledWith(mockUserId, station.placeId, {
nickname: 'Favorite Station',
notes: 'Best prices in area',
isFavorite: true
isFavorite: true,
has93Octane: true,
has93OctaneEthanolFree: false
});
});
});
@@ -188,6 +220,40 @@ describe('StationsService', () => {
});
});
describe('updateSavedStation', () => {
it('should update saved station metadata', async () => {
const savedStation = mockSavedStations[0];
const station = mockStations[0];
if (!savedStation || !station) throw new Error('Mock data not found');
mockRepository.updateSavedStation.mockResolvedValue(savedStation);
mockRepository.getCachedStation.mockResolvedValue(station);
const result = await service.updateSavedStation(savedStation.stationId, mockUserId, {
has93Octane: true,
has93OctaneEthanolFree: true
});
expect(mockRepository.updateSavedStation).toHaveBeenCalledWith(
mockUserId,
savedStation.stationId,
{
has93Octane: true,
has93OctaneEthanolFree: true
}
);
expect(result.station).toEqual(station);
});
it('should throw if saved station not found', async () => {
mockRepository.updateSavedStation.mockResolvedValue(null);
await expect(
service.updateSavedStation('unknown', mockUserId, { nickname: 'Update' })
).rejects.toThrow('Saved station not found');
});
});
describe('removeSavedStation', () => {
it('should delete a saved station', async () => {
const savedStation = mockSavedStations[0];