complete project using prettier!
This commit is contained in:
@@ -41,11 +41,13 @@ describe('Google Geocoding Service', () => {
|
||||
process.env.GOOGLE_MAPS_API_KEY = 'test-api-key';
|
||||
const mockApiResponse = {
|
||||
status: 'OK',
|
||||
results: [{
|
||||
geometry: {
|
||||
location: { lat: 34.0522, lng: -118.2437 },
|
||||
results: [
|
||||
{
|
||||
geometry: {
|
||||
location: { lat: 34.0522, lng: -118.2437 },
|
||||
},
|
||||
},
|
||||
}],
|
||||
],
|
||||
};
|
||||
vi.mocked(fetch).mockResolvedValue({
|
||||
ok: true,
|
||||
@@ -57,10 +59,12 @@ describe('Google Geocoding Service', () => {
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual({ lat: 34.0522, lng: -118.2437 });
|
||||
expect(fetch).toHaveBeenCalledWith(expect.stringContaining('https://maps.googleapis.com/maps/api/geocode/json'));
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
expect.stringContaining('https://maps.googleapis.com/maps/api/geocode/json'),
|
||||
);
|
||||
expect(mockLogger.info).toHaveBeenCalledWith(
|
||||
{ address: 'Los Angeles, CA', result: { lat: 34.0522, lng: -118.2437 } },
|
||||
'[GoogleGeocodingService] Successfully geocoded address'
|
||||
'[GoogleGeocodingService] Successfully geocoded address',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -69,8 +73,9 @@ describe('Google Geocoding Service', () => {
|
||||
delete process.env.GOOGLE_MAPS_API_KEY;
|
||||
|
||||
// Act & Assert
|
||||
await expect(googleGeocodingService.geocode('Any Address', mockLogger))
|
||||
.rejects.toThrow('GOOGLE_MAPS_API_KEY is not set.');
|
||||
await expect(googleGeocodingService.geocode('Any Address', mockLogger)).rejects.toThrow(
|
||||
'GOOGLE_MAPS_API_KEY is not set.',
|
||||
);
|
||||
expect(mockLogger.error).toHaveBeenCalledWith('[GoogleGeocodingService] API key is missing.');
|
||||
});
|
||||
|
||||
@@ -90,7 +95,7 @@ describe('Google Geocoding Service', () => {
|
||||
expect(result).toBeNull();
|
||||
expect(mockLogger.warn).toHaveBeenCalledWith(
|
||||
{ address: 'Invalid Address', status: 'ZERO_RESULTS' },
|
||||
'[GoogleGeocodingService] Geocoding failed or returned no results.'
|
||||
'[GoogleGeocodingService] Geocoding failed or returned no results.',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -103,11 +108,12 @@ describe('Google Geocoding Service', () => {
|
||||
} as Response);
|
||||
|
||||
// Act & Assert
|
||||
await expect(googleGeocodingService.geocode('Any Address', mockLogger))
|
||||
.rejects.toThrow('Google Maps API returned status 403');
|
||||
await expect(googleGeocodingService.geocode('Any Address', mockLogger)).rejects.toThrow(
|
||||
'Google Maps API returned status 403',
|
||||
);
|
||||
expect(mockLogger.error).toHaveBeenCalledWith(
|
||||
{ err: expect.any(Error), address: 'Any Address' },
|
||||
'[GoogleGeocodingService] An error occurred while calling the Google Maps API.'
|
||||
'[GoogleGeocodingService] An error occurred while calling the Google Maps API.',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -118,11 +124,12 @@ describe('Google Geocoding Service', () => {
|
||||
vi.mocked(fetch).mockRejectedValue(networkError);
|
||||
|
||||
// Act & Assert
|
||||
await expect(googleGeocodingService.geocode('Any Address', mockLogger))
|
||||
.rejects.toThrow(networkError);
|
||||
await expect(googleGeocodingService.geocode('Any Address', mockLogger)).rejects.toThrow(
|
||||
networkError,
|
||||
);
|
||||
expect(mockLogger.error).toHaveBeenCalledWith(
|
||||
{ err: networkError, address: 'Any Address' },
|
||||
'[GoogleGeocodingService] An error occurred while calling the Google Maps API.'
|
||||
'[GoogleGeocodingService] An error occurred while calling the Google Maps API.',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user