fixed map tests

This commit is contained in:
jackiettran
2025-11-06 16:56:17 -05:00
parent 2956b79f34
commit 2ee4b5c389
3 changed files with 75 additions and 27 deletions

1
.gitignore vendored
View File

@@ -18,6 +18,7 @@ node_modules/
.env.test.local .env.test.local
.env.production.local .env.production.local
.mcp.json .mcp.json
.claude
# Logs # Logs
npm-debug.log* npm-debug.log*

View File

@@ -1,6 +1,21 @@
const request = require('supertest'); const request = require('supertest');
const express = require('express'); 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 // Mock dependencies
jest.mock('../../../services/googleMapsService', () => ({ jest.mock('../../../services/googleMapsService', () => ({
getPlacesAutocomplete: jest.fn(), getPlacesAutocomplete: jest.fn(),
@@ -136,9 +151,11 @@ describe('Maps Routes', () => {
error: 'Maps service temporarily unavailable', error: 'Maps service temporarily unavailable',
details: 'Configuration issue' details: 'Configuration issue'
}); });
expect(consoleErrorSpy).toHaveBeenCalledWith( expect(mockLogger.error).toHaveBeenCalledWith(
'Maps service error:', 'Maps service error',
'API key not configured' expect.objectContaining({
error: 'API key not configured'
})
); );
}); });
@@ -216,8 +233,13 @@ describe('Maps Routes', () => {
} }
); );
expect(consoleLogSpy).toHaveBeenCalledWith( expect(mockLogger.info).toHaveBeenCalledWith(
'Places Autocomplete: user=1, query_length=8, results=2' 'Places Autocomplete request',
expect.objectContaining({
userId: 1,
queryLength: 8,
resultsCount: 2
})
); );
}); });
@@ -281,8 +303,11 @@ describe('Maps Routes', () => {
expect(response.status).toBe(200); expect(response.status).toBe(200);
// Should log with user ID // Should log with user ID
expect(consoleLogSpy).toHaveBeenCalledWith( expect(mockLogger.info).toHaveBeenCalledWith(
expect.stringContaining('user=1') 'Places Autocomplete request',
expect.objectContaining({
userId: 1
})
); );
}); });
@@ -297,8 +322,13 @@ describe('Maps Routes', () => {
expect(response.status).toBe(200); expect(response.status).toBe(200);
expect(response.body).toEqual({ predictions: [] }); expect(response.body).toEqual({ predictions: [] });
expect(consoleLogSpy).toHaveBeenCalledWith( expect(mockLogger.info).toHaveBeenCalledWith(
'Places Autocomplete: user=1, query_length=17, results=0' '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.status).toBe(200);
expect(response.body).toEqual({}); expect(response.body).toEqual({});
expect(consoleLogSpy).toHaveBeenCalledWith( expect(mockLogger.info).toHaveBeenCalledWith(
'Places Autocomplete: user=1, query_length=4, results=0' 'Places Autocomplete request',
expect.objectContaining({
userId: 1,
queryLength: 4,
resultsCount: 0
})
); );
}); });
}); });
@@ -351,8 +386,12 @@ describe('Maps Routes', () => {
{ sessionToken: 'session123' } { sessionToken: 'session123' }
); );
expect(consoleLogSpy).toHaveBeenCalledWith( expect(mockLogger.info).toHaveBeenCalledWith(
'Place Details: user=1, placeId=ChIJ123abc...' 'Place Details request',
expect.objectContaining({
userId: 1,
placeIdPrefix: 'ChIJ123abc...'
})
); );
}); });
@@ -410,8 +449,12 @@ describe('Maps Routes', () => {
.send({ placeId: longPlaceId }); .send({ placeId: longPlaceId });
expect(response.status).toBe(200); expect(response.status).toBe(200);
expect(consoleLogSpy).toHaveBeenCalledWith( expect(mockLogger.info).toHaveBeenCalledWith(
`Place Details: user=1, placeId=${longPlaceId.substring(0, 10)}...` 'Place Details request',
expect.objectContaining({
userId: 1,
placeIdPrefix: longPlaceId.substring(0, 10) + '...'
})
); );
}); });
@@ -465,8 +508,12 @@ describe('Maps Routes', () => {
{ componentRestrictions: { country: 'US' } } { componentRestrictions: { country: 'US' } }
); );
expect(consoleLogSpy).toHaveBeenCalledWith( expect(mockLogger.info).toHaveBeenCalledWith(
'Geocoding: user=1, address_length=25' 'Geocoding request',
expect.objectContaining({
userId: 1,
addressLength: 25
})
); );
}); });

View File

@@ -287,12 +287,7 @@ const Owning: React.FC = () => {
return ( return (
<div className="container mt-4"> <div className="container mt-4">
<div className="d-flex justify-content-between align-items-center mb-4"> <h1 className="mb-4">Owning</h1>
<h1>Owning</h1>
<Link to="/create-item" className="btn btn-primary">
Add New Item
</Link>
</div>
{error && ( {error && (
<div className="alert alert-danger" role="alert"> <div className="alert alert-danger" role="alert">
@@ -487,10 +482,15 @@ const Owning: React.FC = () => {
</div> </div>
)} )}
<h4 className="mb-3"> <div className="d-flex justify-content-between align-items-center mb-3">
<h4 className="mb-0">
<i className="bi bi-list-ul me-2"></i> <i className="bi bi-list-ul me-2"></i>
Listings Listings
</h4> </h4>
<Link to="/create-item" className="btn btn-primary">
Add New Item
</Link>
</div>
{listings.length === 0 ? ( {listings.length === 0 ? (
<div className="text-center py-5"> <div className="text-center py-5">