fixed map tests
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
const request = require('supertest');
|
||||
const express = require('express');
|
||||
|
||||
// Mock logger
|
||||
const mockLogger = {
|
||||
info: jest.fn(),
|
||||
error: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
http: jest.fn(),
|
||||
withRequestId: jest.fn()
|
||||
};
|
||||
|
||||
// Set up withRequestId to return the same mock logger
|
||||
mockLogger.withRequestId.mockReturnValue(mockLogger);
|
||||
|
||||
jest.mock('../../../utils/logger', () => mockLogger);
|
||||
|
||||
// Mock dependencies
|
||||
jest.mock('../../../services/googleMapsService', () => ({
|
||||
getPlacesAutocomplete: jest.fn(),
|
||||
@@ -136,9 +151,11 @@ describe('Maps Routes', () => {
|
||||
error: 'Maps service temporarily unavailable',
|
||||
details: 'Configuration issue'
|
||||
});
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
'Maps service error:',
|
||||
'API key not configured'
|
||||
expect(mockLogger.error).toHaveBeenCalledWith(
|
||||
'Maps service error',
|
||||
expect.objectContaining({
|
||||
error: 'API key not configured'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -216,8 +233,13 @@ describe('Maps Routes', () => {
|
||||
}
|
||||
);
|
||||
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
'Places Autocomplete: user=1, query_length=8, results=2'
|
||||
expect(mockLogger.info).toHaveBeenCalledWith(
|
||||
'Places Autocomplete request',
|
||||
expect.objectContaining({
|
||||
userId: 1,
|
||||
queryLength: 8,
|
||||
resultsCount: 2
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -281,8 +303,11 @@ describe('Maps Routes', () => {
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
// Should log with user ID
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('user=1')
|
||||
expect(mockLogger.info).toHaveBeenCalledWith(
|
||||
'Places Autocomplete request',
|
||||
expect.objectContaining({
|
||||
userId: 1
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -297,8 +322,13 @@ describe('Maps Routes', () => {
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.body).toEqual({ predictions: [] });
|
||||
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
'Places Autocomplete: user=1, query_length=17, results=0'
|
||||
expect(mockLogger.info).toHaveBeenCalledWith(
|
||||
'Places Autocomplete request',
|
||||
expect.objectContaining({
|
||||
userId: 1,
|
||||
queryLength: 17,
|
||||
resultsCount: 0
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -313,8 +343,13 @@ describe('Maps Routes', () => {
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.body).toEqual({});
|
||||
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
'Places Autocomplete: user=1, query_length=4, results=0'
|
||||
expect(mockLogger.info).toHaveBeenCalledWith(
|
||||
'Places Autocomplete request',
|
||||
expect.objectContaining({
|
||||
userId: 1,
|
||||
queryLength: 4,
|
||||
resultsCount: 0
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -351,8 +386,12 @@ describe('Maps Routes', () => {
|
||||
{ sessionToken: 'session123' }
|
||||
);
|
||||
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
'Place Details: user=1, placeId=ChIJ123abc...'
|
||||
expect(mockLogger.info).toHaveBeenCalledWith(
|
||||
'Place Details request',
|
||||
expect.objectContaining({
|
||||
userId: 1,
|
||||
placeIdPrefix: 'ChIJ123abc...'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -410,8 +449,12 @@ describe('Maps Routes', () => {
|
||||
.send({ placeId: longPlaceId });
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
`Place Details: user=1, placeId=${longPlaceId.substring(0, 10)}...`
|
||||
expect(mockLogger.info).toHaveBeenCalledWith(
|
||||
'Place Details request',
|
||||
expect.objectContaining({
|
||||
userId: 1,
|
||||
placeIdPrefix: longPlaceId.substring(0, 10) + '...'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -465,8 +508,12 @@ describe('Maps Routes', () => {
|
||||
{ componentRestrictions: { country: 'US' } }
|
||||
);
|
||||
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
'Geocoding: user=1, address_length=25'
|
||||
expect(mockLogger.info).toHaveBeenCalledWith(
|
||||
'Geocoding request',
|
||||
expect.objectContaining({
|
||||
userId: 1,
|
||||
addressLength: 25
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user